Improved the computation of the TextureProfile _size value, fixed the computation up of the miplevels

This commit is contained in:
Robert Osfield
2009-09-26 16:28:42 +00:00
parent 4d75729650
commit 9a1cd7072f
5 changed files with 217 additions and 22 deletions

View File

@@ -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="<<numBitsPerTexel<<std::endl;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -289,9 +330,9 @@ void Texture::TextureObjectSet::flushDeletedTextureObjects(double currentTime, d
++numDeleted;
}
osg::notify(osg::NOTICE)<<"Size before = "<<_orphanedTextureObjects.size();
// osg::notify(osg::NOTICE)<<"Size before = "<<_orphanedTextureObjects.size();
_orphanedTextureObjects.erase(_orphanedTextureObjects.begin(), itr);
osg::notify(osg::NOTICE)<<", after = "<<_orphanedTextureObjects.size()<<" numDeleted = "<<numDeleted<<std::endl;
// osg::notify(osg::NOTICE)<<", after = "<<_orphanedTextureObjects.size()<<" numDeleted = "<<numDeleted<<std::endl;
// update the number of TO's in this TextureObjectSet
_numOfTextureObjects -= numDeleted;
@@ -1568,9 +1609,7 @@ void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& i
inwidth = width;
inheight = height;
bool useHardwareMipMapGeneration = !image.isMipmap() && isHardwareMipmapGenerationEnabled(state);
if( _min_filter == LINEAR || _min_filter == NEAREST || useHardwareMipMapGeneration )
if( _min_filter == LINEAR || _min_filter == NEAREST)
{
numMipmapLevels = 1;
}
@@ -1580,20 +1619,10 @@ void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& i
}
else
{
numMipmapLevels = 0;
for( ; (width || height) ;++numMipmapLevels)
{
if (width == 0)
width = 1;
if (height == 0)
height = 1;
width >>= 1;
height >>= 1;
}
numMipmapLevels = 1;
for(int s=1; s<width || s<height; s <<= 1, ++numMipmapLevels) {}
}
// osg::notify(osg::NOTICE)<<"Texture::computeRequiredTextureDimensions() image.s() "<<image.s()<<" image.t()="<<image.t()<<" width="<<width<<" height="<<height<<" numMipmapLevels="<<numMipmapLevels<<std::endl;
// osg::notify(osg::NOTICE)<<" _resizeNonPowerOfTwoHint="<<_resizeNonPowerOfTwoHint<<" extensions->isNonPowerOfTwoTextureSupported(_min_filter)="<<extensions->isNonPowerOfTwoTextureSupported(_min_filter) <<std::endl;
}

View File

@@ -348,10 +348,14 @@ void Texture2D::copyTexImage2D(State& state, int x, int y, int width, int height
_textureWidth = width;
_textureHeight = height;
_numMipmapLevels = 1;
textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
_numMipmapLevels = 1;
if (needHardwareMipMap)
{
for(int s=1; s<width || s<height; s <<= 1, ++_numMipmapLevels) {}
}
textureObject->setAllocated(_numMipmapLevels,_internalFormat,_textureWidth,_textureHeight,1,0);
// inform state that this texture is the current one bound.
state.haveAppliedTextureAttribute(state.getActiveTextureUnit(), this);

View File

@@ -1563,6 +1563,7 @@ void SceneView::draw()
}
}
// #define REPORT_TEXTURE_MANAGER_STATS
#ifdef REPORT_TEXTURE_MANAGER_STATS
tom->reportStats();
#endif

View File

@@ -11,6 +11,7 @@
#include <osgIntrospection/Attributes>
#include <osg/CopyOp>
#include <osg/FrameStamp>
#include <osg/GraphicsContext>
#include <osg/Image>
#include <osg/Object>
@@ -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,

View File

@@ -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,