From 7362b8b49f10ea72c06980aa852160922e44fea5 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 16 Dec 2009 12:17:45 +0000 Subject: [PATCH] Removed old texture object manage code. --- src/osg/Texture.cpp | 314 +------------------------------------------- 1 file changed, 2 insertions(+), 312 deletions(-) diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 30259a530..6ce81ea2f 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -70,8 +70,6 @@ unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() } -#define USE_NEW_TEXTURE_POOL 1 - Texture::TextureObject::~TextureObject() { // osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "<& Texture::getTextureObjectManager(un } -#if USE_NEW_TEXTURE_POOL - Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target) { return getTextureObjectManager(contextID)->generateTextureObject(texture, target); @@ -933,316 +929,10 @@ void Texture::releaseTextureObject(unsigned int contextID, Texture::TextureObjec getTextureObjectManager(contextID)->releaseTextureObject(to); } -#else - -/////////////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////////////// // -// Original texture object manager +// Texture class implementation // -class OriginalTextureObjectManager : public osg::Referenced -{ -public: - - OriginalTextureObjectManager(): - _expiryDelay(0.0) - { - // printf("Constructing OriginalTextureObjectManager\n"); - } - - ~OriginalTextureObjectManager() - { - // printf("Destructing OriginalTextureObjectManager\n"); - } - - virtual Texture::TextureObject* generateTextureObject(Texture* texture, unsigned int contextID,GLenum target); - - virtual Texture::TextureObject* generateTextureObject(Texture* texture, unsigned int contextID, - GLenum target, - GLint numMipmapLevels, - GLenum internalFormat, - GLsizei width, - GLsizei height, - GLsizei depth, - GLint border); - - virtual Texture::TextureObject* reuseTextureObject(Texture* texture, unsigned int contextID, - GLenum target, - GLint numMipmapLevels, - GLenum internalFormat, - GLsizei width, - GLsizei height, - GLsizei depth, - GLint border); - - inline Texture::TextureObject* reuseOrGenerateTextureObject(Texture* texture, unsigned int contextID, - GLenum target, - GLint numMipmapLevels, - GLenum internalFormat, - GLsizei width, - GLsizei height, - GLsizei depth, - GLint border) - { - Texture::TextureObject* to = reuseTextureObject(texture, contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); - if (to) return to; - else return generateTextureObject(texture, contextID,target,numMipmapLevels,internalFormat,width,height,depth,border); - } - - void flushAllTextureObjects(unsigned int contextID); - - void discardAllTextureObjects(unsigned int contextID); - - void flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime); - - void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; } - - double getExpiryDelay() const { return _expiryDelay; } - - /** How long to keep unused texture objects before deletion. */ - double _expiryDelay; - - typedef osg::buffered_object TextureObjectListMap; - TextureObjectListMap _textureObjectListMap; - - // mutex to keep access serialized. - OpenThreads::Mutex _mutex; -}; - -unsigned int Texture::s_numberTextureReusedLastInLastFrame = 0; -unsigned int Texture::s_numberNewTextureInLastFrame = 0; -unsigned int Texture::s_numberDeletedTextureInLastFrame = 0; - - -static ref_ptr s_textureObjectManager = new OriginalTextureObjectManager; - - -Texture::TextureObject* OriginalTextureObjectManager::generateTextureObject(Texture* texture, unsigned int contextID,GLenum target) -{ - Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID); - ElapsedTime elapsedTime(&(tom->getGenerateTime())); - tom->getNumberGenerated()++; - - GLuint id; - glGenTextures( 1L, &id ); - - return new Texture::TextureObject(texture, id,target); -} - -static int s_number = 0; - -Texture::TextureObject* OriginalTextureObjectManager::generateTextureObject(Texture* texture, unsigned int contextID, - GLenum target, - GLint numMipmapLevels, - GLenum internalFormat, - GLsizei width, - GLsizei height, - GLsizei depth, - GLint border) -{ - Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID); - ElapsedTime elapsedTime(&(tom->getGenerateTime())); - tom->getNumberGenerated()++; - - ++s_number; - ++Texture::s_numberNewTextureInLastFrame; - // notify(NOTICE)<<"creating new texture object "<getGenerateTime())); - tom->getNumberGenerated()++; - - OpenThreads::ScopedLock lock(_mutex); - - Texture::TextureObjectList& tol = _textureObjectListMap[contextID]; - for(Texture::TextureObjectList::iterator itr = tol.begin(); - itr != tol.end(); - ++itr) - { - if ((*itr)->match(target,numMipmapLevels,internalFormat,width,height,depth,border)) - { - // found usable texture object. - Texture::TextureObject* textureObject = (*itr).release(); - tol.erase(itr); - - // notify(NOTICE)<<"reusing texture object "<setTexture(texture); - - return textureObject; - } - } - - return 0; -} - -void OriginalTextureObjectManager::flushAllTextureObjects(unsigned int contextID) -{ - Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID); - ElapsedTime elapsedTime(&(tom->getDeleteTime())); - - OpenThreads::ScopedLock lock(_mutex); - - Texture::TextureObjectList& tol = _textureObjectListMap[contextID]; - - // osg::notify(osg::INFO)<<"Flushing texture objects num="<_id<id(); - glDeleteTextures( 1L, &id); - - tom->getNumberDeleted()++; - } - tol.clear(); -} - -void OriginalTextureObjectManager::discardAllTextureObjects(unsigned int contextID) -{ - OpenThreads::ScopedLock lock(_mutex); - - Texture::TextureObjectList& tol = _textureObjectListMap[contextID]; - tol.clear(); -} - -void OriginalTextureObjectManager::flushTextureObjects(unsigned int contextID,double currentTime, double& availableTime) -{ - - // if no time available don't try to flush objects. - if (availableTime<=0.0) return; - - Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID); - ElapsedTime timer(&(tom->getDeleteTime())); - - unsigned int numObjectsDeleted = 0; - unsigned int maxNumObjectsToDelete = 4; - - { - OpenThreads::ScopedLock lock(_mutex); - - Texture::TextureObjectList& tol = _textureObjectListMap[contextID]; - - // reset the time of any uninitialized objects. - Texture::TextureObjectList::iterator itr; - for(itr=tol.begin(); - itr!=tol.end(); - ++itr) - { - if ((*itr)->getTimeStamp()==0.0) (*itr)->setTimeStamp(currentTime); - } - - double expiryTime = currentTime-_expiryDelay; - - for(itr=tol.begin(); - itr!=tol.end() && timer.elapsedTime()s_minimumNumberOfTextureObjectsToRetainInCache && numObjectsDeletedgetTimeStamp()<=expiryTime) - { - --s_number; - ++Texture::s_numberDeletedTextureInLastFrame; - - GLuint id = (*itr)->id(); - glDeleteTextures( 1L, &id); - itr = tol.erase(itr); - ++numObjectsDeleted; - } - else - { - ++itr; - } - } - } - - tom->getNumberDeleted()+=numObjectsDeleted; - - availableTime -= timer.elapsedTime(); -} - - -static OriginalTextureObjectManager* getOriginalTextureObjectManager() -{ - return s_textureObjectManager.get(); -} - - -Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID,GLenum target) -{ - if (getOriginalTextureObjectManager()) return getOriginalTextureObjectManager()->generateTextureObject(const_cast(texture),contextID,target); - else return 0; -} - -Texture::TextureObject* Texture::generateTextureObject(const Texture* texture, unsigned int contextID, - GLenum target, - GLint numMipmapLevels, - GLenum internalFormat, - GLsizei width, - GLsizei height, - GLsizei depth, - GLint border) -{ - if (getOriginalTextureObjectManager()) - return getOriginalTextureObjectManager()->reuseOrGenerateTextureObject(const_cast(texture), - contextID, - target, - numMipmapLevels, - internalFormat, - width, - height, - depth, - border); - else - return 0; -} - -void Texture::flushAllDeletedTextureObjects(unsigned int contextID) -{ - if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->flushAllTextureObjects(contextID); -} - -void Texture::discardAllDeletedTextureObjects(unsigned int contextID) -{ - if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->discardAllTextureObjects(contextID); -} - -void Texture::flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availbleTime) -{ - if (getOriginalTextureObjectManager()) getOriginalTextureObjectManager()->flushTextureObjects(contextID, currentTime, availbleTime); -} - -void Texture::releaseTextureObject(unsigned int contextID, Texture::TextureObject* to) -{ - if (getOriginalTextureObjectManager()) - { - OpenThreads::ScopedLock lock(getOriginalTextureObjectManager()->_mutex); - getOriginalTextureObjectManager()->_textureObjectListMap[contextID].push_back(to); - } -} - -#endif - - - Texture::Texture(): _wrap_s(CLAMP), _wrap_t(CLAMP),