From 9a1cd7072fb65858dcd1ec10ec83b7a99493b7c6 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 26 Sep 2009 16:28:42 +0000 Subject: [PATCH] Improved the computation of the TextureProfile _size value, fixed the computation up of the miplevels --- src/osg/Texture.cpp | 67 ++++++++++++----- src/osg/Texture2D.cpp | 10 ++- src/osgUtil/SceneView.cpp | 1 + src/osgWrappers/osg/Texture.cpp | 127 ++++++++++++++++++++++++++++++++ src/osgWrappers/osg/Timer.cpp | 34 +++++++++ 5 files changed, 217 insertions(+), 22 deletions(-) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index b517c0f1c..13f6ba5e5 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -79,7 +79,48 @@ void Texture::TextureObject::bind() void Texture::TextureProfile::computeSize() { unsigned int numBitsPerTexel = 32; - _size = (_width * _height * _depth * numBitsPerTexel)/8; + + switch(_internalFormat) + { + case(1): numBitsPerTexel = 8; break; + case(GL_ALPHA): numBitsPerTexel = 8; break; + case(GL_LUMINANCE): numBitsPerTexel = 8; break; + case(GL_INTENSITY): numBitsPerTexel = 8; break; + + case(GL_LUMINANCE_ALPHA): numBitsPerTexel = 16; break; + case(2): numBitsPerTexel = 16; break; + + case(GL_RGB): numBitsPerTexel = 24; break; + case(GL_BGR): numBitsPerTexel = 24; break; + case(3): numBitsPerTexel = 24; break; + + case(GL_RGBA): numBitsPerTexel = 32; break; + case(4): numBitsPerTexel = 32; break; + + case(GL_COMPRESSED_ALPHA_ARB): numBitsPerTexel = 4; break; + case(GL_COMPRESSED_INTENSITY_ARB): numBitsPerTexel = 4; break; + case(GL_COMPRESSED_LUMINANCE_ALPHA_ARB): numBitsPerTexel = 4; break; + case(GL_COMPRESSED_RGB_S3TC_DXT1_EXT): numBitsPerTexel = 4; break; + case(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT): numBitsPerTexel = 4; break; + + case(GL_COMPRESSED_RGB_ARB): numBitsPerTexel = 8; break; + case(GL_COMPRESSED_RGBA_S3TC_DXT3_EXT): numBitsPerTexel = 8; break; + case(GL_COMPRESSED_RGBA_S3TC_DXT5_EXT): numBitsPerTexel = 8; break; + } + + _size = (unsigned int)(ceil(double(_width * _height * _depth * numBitsPerTexel)/8.0)); + + if (_numMipmapLevels>1) + { + unsigned int mipmapSize = _size / 4; + for(GLint i=0; i<_numMipmapLevels && mipmapSize!=0; ++i) + { + _size += mipmapSize; + mipmapSize /= 4; + } + } + + // osg::notify(osg::NOTICE)<<"TO ("<<_width<<", "<<_height<<", "<<_depth<<") size="<<_size<<" numBitsPerTexel="<isNonPowerOfTwoTextureSupported(_min_filter)="<isNonPowerOfTwoTextureSupported(_min_filter) <setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); + _numMipmapLevels = 1; + if (needHardwareMipMap) + { + for(int s=1; ssetAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0); // inform state that this texture is the current one bound. state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this); diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index c8f5f3d23..687018b86 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -1563,6 +1563,7 @@ void SceneView::draw() } } +// #define REPORT_TEXTURE_MANAGER_STATS #ifdef REPORT_TEXTURE_MANAGER_STATS tom->reportStats(); #endif diff --git a/src/osgWrappers/osg/Texture.cpp b/src/osgWrappers/osg/Texture.cpp index 948eaa9a3..1a3119e37 100644 --- a/src/osgWrappers/osg/Texture.cpp +++ b/src/osgWrappers/osg/Texture.cpp @@ -11,6 +11,7 @@ #include #include +#include #include #include #include @@ -767,6 +768,7 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObject) I_PublicMemberProperty(osg::Texture::TextureObject *, _next); I_PublicMemberProperty(osg::Texture *, _texture); I_PublicMemberProperty(bool, _allocated); + I_PublicMemberProperty(unsigned int, _frameLastUsed); I_PublicMemberProperty(double, _timeStamp); END_REFLECTOR @@ -783,11 +785,46 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectManager) __unsigned_int__getContextID, "", ""); + I_Method1(void, setNumberActiveTextureObjects, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setNumberActiveTextureObjects__unsigned_int, + "", + ""); + I_Method0(unsigned int &, getNumberActiveTextureObjects, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberActiveTextureObjects, + "", + ""); + I_Method0(unsigned int, getNumberActiveTextureObjects, + Properties::NON_VIRTUAL, + __unsigned_int__getNumberActiveTextureObjects, + "", + ""); + I_Method1(void, setNumberOrphanedTextureObjects, IN, unsigned int, size, + Properties::NON_VIRTUAL, + __void__setNumberOrphanedTextureObjects__unsigned_int, + "", + ""); + I_Method0(unsigned int &, getNumberOrphanedTextureObjects, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberOrphanedTextureObjects, + "", + ""); + I_Method0(unsigned int, getNumberOrphanedTextureObjects, + Properties::NON_VIRTUAL, + __unsigned_int__getNumberOrphanedTextureObjects, + "", + ""); I_Method1(void, setCurrTexturePoolSize, IN, unsigned int, size, Properties::NON_VIRTUAL, __void__setCurrTexturePoolSize__unsigned_int, "", ""); + I_Method0(unsigned int &, getCurrTexturePoolSize, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getCurrTexturePoolSize, + "", + ""); I_Method0(unsigned int, getCurrTexturePoolSize, Properties::NON_VIRTUAL, __unsigned_int__getCurrTexturePoolSize, @@ -848,15 +885,100 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectManager) __void__releaseTextureObject__TextureObject_P1, "", ""); + I_Method1(void, newFrame, IN, osg::FrameStamp *, fs, + Properties::NON_VIRTUAL, + __void__newFrame__osg_FrameStamp_P1, + "", + ""); + I_Method0(void, resetStats, + Properties::NON_VIRTUAL, + __void__resetStats, + "", + ""); + I_Method0(void, reportStats, + Properties::NON_VIRTUAL, + __void__reportStats, + "", + ""); + I_Method0(unsigned int &, getFrameNumber, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getFrameNumber, + "", + ""); + I_Method0(unsigned int &, getNumberFrames, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberFrames, + "", + ""); + I_Method0(unsigned int &, getNumberDeleted, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberDeleted, + "", + ""); + I_Method0(double &, getDeleteTime, + Properties::NON_VIRTUAL, + __double_R1__getDeleteTime, + "", + ""); + I_Method0(unsigned int &, getNumberGenerated, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberGenerated, + "", + ""); + I_Method0(double &, getGenerateTime, + Properties::NON_VIRTUAL, + __double_R1__getGenerateTime, + "", + ""); + I_Method0(unsigned int &, getNumberApplied, + Properties::NON_VIRTUAL, + __unsigned_int_R1__getNumberApplied, + "", + ""); + I_Method0(double &, getApplyTime, + Properties::NON_VIRTUAL, + __double_R1__getApplyTime, + "", + ""); + I_SimpleProperty(double &, ApplyTime, + __double_R1__getApplyTime, + 0); I_SimpleProperty(unsigned int, ContextID, __unsigned_int__getContextID, 0); I_SimpleProperty(unsigned int, CurrTexturePoolSize, __unsigned_int__getCurrTexturePoolSize, __void__setCurrTexturePoolSize__unsigned_int); + I_SimpleProperty(double &, DeleteTime, + __double_R1__getDeleteTime, + 0); + I_SimpleProperty(unsigned int &, FrameNumber, + __unsigned_int_R1__getFrameNumber, + 0); + I_SimpleProperty(double &, GenerateTime, + __double_R1__getGenerateTime, + 0); I_SimpleProperty(unsigned int, MaxTexturePoolSize, __unsigned_int__getMaxTexturePoolSize, __void__setMaxTexturePoolSize__unsigned_int); + I_SimpleProperty(unsigned int, NumberActiveTextureObjects, + __unsigned_int__getNumberActiveTextureObjects, + __void__setNumberActiveTextureObjects__unsigned_int); + I_SimpleProperty(unsigned int &, NumberApplied, + __unsigned_int_R1__getNumberApplied, + 0); + I_SimpleProperty(unsigned int &, NumberDeleted, + __unsigned_int_R1__getNumberDeleted, + 0); + I_SimpleProperty(unsigned int &, NumberFrames, + __unsigned_int_R1__getNumberFrames, + 0); + I_SimpleProperty(unsigned int &, NumberGenerated, + __unsigned_int_R1__getNumberGenerated, + 0); + I_SimpleProperty(unsigned int, NumberOrphanedTextureObjects, + __unsigned_int__getNumberOrphanedTextureObjects, + __void__setNumberOrphanedTextureObjects__unsigned_int); END_REFLECTOR BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectSet) @@ -886,6 +1008,11 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectSet) __void__flushDeletedTextureObjects__double__double_R1, "", ""); + I_Method1(osg::Texture::TextureObject *, takeFromOrphans, IN, osg::Texture *, texture, + Properties::NON_VIRTUAL, + __TextureObject_P1__takeFromOrphans__Texture_P1, + "", + ""); I_Method1(osg::Texture::TextureObject *, takeOrGenerate, IN, osg::Texture *, texture, Properties::NON_VIRTUAL, __TextureObject_P1__takeOrGenerate__Texture_P1, diff --git a/src/osgWrappers/osg/Timer.cpp b/src/osgWrappers/osg/Timer.cpp index 4ab58751c..9d7b53d1c 100644 --- a/src/osgWrappers/osg/Timer.cpp +++ b/src/osgWrappers/osg/Timer.cpp @@ -20,6 +20,40 @@ #undef OUT #endif +BEGIN_VALUE_REFLECTOR(osg::ElapsedTime) + I_DeclaringFile("osg/Timer"); + I_ConstructorWithDefaults2(IN, double *, elapsedTime, , IN, osg::Timer *, timer, 0, + ____ElapsedTime__double_P1__osg_Timer_P1, + "", + ""); + I_ConstructorWithDefaults1(IN, osg::Timer *, timer, 0, + Properties::NON_EXPLICIT, + ____ElapsedTime__osg_Timer_P1, + "", + ""); + I_Method0(void, reset, + Properties::NON_VIRTUAL, + __void__reset, + "", + ""); + I_Method0(double, elapsedTime, + Properties::NON_VIRTUAL, + __double__elapsedTime, + "", + ""); + I_Method0(void, finish, + Properties::NON_VIRTUAL, + __void__finish, + "", + ""); + I_ProtectedMethod1(void, init, IN, osg::Timer *, timer, + Properties::NON_VIRTUAL, + Properties::NON_CONST, + __void__init__osg_Timer_P1, + "", + ""); +END_REFLECTOR + BEGIN_VALUE_REFLECTOR(osg::Timer) I_DeclaringFile("osg/Timer"); I_Constructor0(____Timer,