From 1fce3c0ad14108678ac8f5088596b82c9a0f4113 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 27 Sep 2009 15:14:57 +0000 Subject: [PATCH] Added handling of resetting of the texture object format --- include/osg/Texture | 13 ++--- src/osg/Texture.cpp | 86 ++++++++++++++++++++++++--------- src/osgWrappers/osg/Texture.cpp | 18 +++++++ 3 files changed, 87 insertions(+), 30 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 82ee5fb09..49580f967 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -975,16 +975,12 @@ class OSG_EXPORT Texture : public osg::StateAttribute inline void setAllocated(bool allocated=true) { _allocated = allocated; } - inline void setAllocated(GLint numMipmapLevels, + void setAllocated(GLint numMipmapLevels, GLenum internalFormat, GLsizei width, GLsizei height, GLsizei depth, - GLint border) - { - _allocated=true; - _profile.set(numMipmapLevels,internalFormat,width,height,depth,border); - } + GLint border); inline bool isAllocated() const { return _allocated; } @@ -1019,12 +1015,16 @@ class OSG_EXPORT Texture : public osg::StateAttribute void moveToBack(TextureObject* to); void addToBack(TextureObject* to); void orphan(TextureObject* to); + void remove(TextureObject* to); + unsigned int size() const { return _profile._size * _numOfTextureObjects; } bool makeSpace(unsigned int& size); bool checkConsistency() const; + TextureObjectManager* getParent() { return _parent; } + protected: virtual ~TextureObjectSet(); @@ -1085,6 +1085,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute void flushDeletedTextureObjects(double currentTime, double& availableTime); void releaseTextureObject(TextureObject* to); + TextureObjectSet* getTextureObjectSet(const TextureProfile& profile); void newFrame(osg::FrameStamp* fs); void resetStats(); diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 13f6ba5e5..3f7c298fe 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -76,6 +76,32 @@ void Texture::TextureObject::bind() if (_set) _set->moveToBack(this); } +void Texture::TextureObject::setAllocated(GLint numMipmapLevels, + GLenum internalFormat, + GLsizei width, + GLsizei height, + GLsizei depth, + GLint border) +{ + _allocated=true; + if (!match(_profile._target,numMipmapLevels,internalFormat,width,height,depth,border)) + { + _profile.set(numMipmapLevels,internalFormat,width,height,depth,border); + + if (_set) + { + // remove self from original set + _set->remove(this); + + // get the new set for the new profile + _set = _set->getParent()->getTextureObjectSet(_profile); + + // register self with new set. + _set->addToBack(this); + } + } +} + void Texture::TextureProfile::computeSize() { unsigned int numBitsPerTexel = 32; @@ -209,29 +235,7 @@ void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects() _orphanedTextureObjects.push_back(to); - if (to->_previous!=0) - { - (to->_previous)->_next = to->_next; - } - else - { - // 'to' was head so assign _head to the next in list - _head = to->_next; - } - - if (to->_next!=0) - { - (to->_next)->_previous = to->_previous; - } - else - { - // 'to' was tail so assing tail to the previous in list - _tail = to->_previous; - } - - // reset the 'to' list pointers as it's no longer in the active list. - to->_next = 0; - to->_previous = 0; + remove(to); #if 0 osg::notify(osg::NOTICE)<<" HPOTO after _head = "<<_head<_previous!=0) + { + (to->_previous)->_next = to->_next; + } + else + { + // 'to' was head so assign _head to the next in list + _head = to->_next; + } + + if (to->_next!=0) + { + (to->_next)->_previous = to->_previous; + } + else + { + // 'to' was tail so assing tail to the previous in list + _tail = to->_previous; + } + + // reset the 'to' list pointers as it's no longer in the active list. + to->_next = 0; + to->_previous = 0; +} + + Texture::TextureObjectManager::TextureObjectManager(unsigned int contextID): _contextID(contextID), _numActiveTextureObjects(0), @@ -631,9 +663,15 @@ Texture::TextureObject* Texture::TextureObjectManager::generateTextureObject(con ++getNumberGenerated(); Texture::TextureProfile profile(target,numMipmapLevels,internalFormat,width,height,depth,border); + TextureObjectSet* tos = getTextureObjectSet(profile); + return tos->takeOrGenerate(const_cast(texture)); +} + +Texture::TextureObjectSet* Texture::TextureObjectManager::getTextureObjectSet(const TextureProfile& profile) +{ osg::ref_ptr& tos = _textureSetMap[profile]; if (!tos) tos = new Texture::TextureObjectSet(this, profile); - return tos->takeOrGenerate(const_cast(texture)); + return tos.get(); } void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects() diff --git a/src/osgWrappers/osg/Texture.cpp b/src/osgWrappers/osg/Texture.cpp index 1a3119e37..4d7fc5998 100644 --- a/src/osgWrappers/osg/Texture.cpp +++ b/src/osgWrappers/osg/Texture.cpp @@ -885,6 +885,11 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectManager) __void__releaseTextureObject__TextureObject_P1, "", ""); + I_Method1(osg::Texture::TextureObjectSet *, getTextureObjectSet, IN, const osg::Texture::TextureProfile &, profile, + Properties::NON_VIRTUAL, + __TextureObjectSet_P1__getTextureObjectSet__C5_TextureProfile_R1, + "", + ""); I_Method1(void, newFrame, IN, osg::FrameStamp *, fs, Properties::NON_VIRTUAL, __void__newFrame__osg_FrameStamp_P1, @@ -1033,6 +1038,11 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectSet) __void__orphan__TextureObject_P1, "", ""); + I_Method1(void, remove, IN, osg::Texture::TextureObject *, to, + Properties::NON_VIRTUAL, + __void__remove__TextureObject_P1, + "", + ""); I_Method0(unsigned int, size, Properties::NON_VIRTUAL, __unsigned_int__size, @@ -1048,6 +1058,14 @@ BEGIN_OBJECT_REFLECTOR(osg::Texture::TextureObjectSet) __bool__checkConsistency, "", ""); + I_Method0(osg::Texture::TextureObjectManager *, getParent, + Properties::NON_VIRTUAL, + __TextureObjectManager_P1__getParent, + "", + ""); + I_SimpleProperty(osg::Texture::TextureObjectManager *, Parent, + __TextureObjectManager_P1__getParent, + 0); END_REFLECTOR BEGIN_VALUE_REFLECTOR(osg::Texture::TextureProfile)