Removed old texture object manage code.
This commit is contained in:
@@ -70,8 +70,6 @@ unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache()
|
||||
}
|
||||
|
||||
|
||||
#define USE_NEW_TEXTURE_POOL 1
|
||||
|
||||
Texture::TextureObject::~TextureObject()
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "<<this<<std::endl;
|
||||
@@ -884,8 +882,6 @@ osg::ref_ptr<Texture::TextureObjectManager>& 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<Texture::TextureObjectList> 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<OriginalTextureObjectManager> 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 "<<s_number<<std::endl;
|
||||
|
||||
// no useable texture object found so return 0
|
||||
GLuint id;
|
||||
glGenTextures( 1L, &id );
|
||||
|
||||
return new Texture::TextureObject(texture, id,target,numMipmapLevels,internalFormat,width,height,depth,border);
|
||||
}
|
||||
|
||||
Texture::TextureObject* OriginalTextureObjectManager::reuseTextureObject(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()++;
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> 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 "<<std::endl;
|
||||
|
||||
++Texture::s_numberTextureReusedLastInLastFrame;
|
||||
|
||||
textureObject->setTexture(texture);
|
||||
|
||||
return textureObject;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void OriginalTextureObjectManager::flushAllTextureObjects(unsigned int contextID)
|
||||
{
|
||||
Texture::TextureObjectManager* tom = Texture::getTextureObjectManager(contextID);
|
||||
ElapsedTime elapsedTime(&(tom->getDeleteTime()));
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
|
||||
Texture::TextureObjectList& tol = _textureObjectListMap[contextID];
|
||||
|
||||
// osg::notify(osg::INFO)<<"Flushing texture objects num="<<tol.size()<<" contextID="<<contextID<<std::endl;
|
||||
|
||||
for(Texture::TextureObjectList::iterator itr=tol.begin();
|
||||
itr!=tol.end();
|
||||
++itr)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<" deleting texture object "<<(*itr)->_id<<std::endl;
|
||||
GLuint id = (*itr)->id();
|
||||
glDeleteTextures( 1L, &id);
|
||||
|
||||
tom->getNumberDeleted()++;
|
||||
}
|
||||
tol.clear();
|
||||
}
|
||||
|
||||
void OriginalTextureObjectManager::discardAllTextureObjects(unsigned int contextID)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> 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<OpenThreads::Mutex> 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()<availableTime && tol.size()>s_minimumNumberOfTextureObjectsToRetainInCache && numObjectsDeleted<maxNumObjectsToDelete;
|
||||
)
|
||||
{
|
||||
if ((*itr)->getTimeStamp()<=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<osg::Texture*>(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<osg::Texture*>(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<OpenThreads::Mutex> lock(getOriginalTextureObjectManager()->_mutex);
|
||||
getOriginalTextureObjectManager()->_textureObjectListMap[contextID].push_back(to);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Texture::Texture():
|
||||
_wrap_s(CLAMP),
|
||||
_wrap_t(CLAMP),
|
||||
|
||||
Reference in New Issue
Block a user