Refactored the GL object deletion management to use new osg::GraphicsObjectManager/GLObjectManager base classes, and osg::ContextData container.

This approach unifies much of the code handling the clean up of OpenGL graphics data, avoids lots of local mutexes and static variables that were previously required,
and enables the clean up scheme to be easily extended by users providing their own GraphicsObjectManager subclasses.


git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@15130 16af8721-9629-0410-8352-f15c8da7e697
This commit is contained in:
Robert Osfield
2015-09-23 09:47:34 +00:00
parent cb3396b0e5
commit 161246d864
37 changed files with 1339 additions and 1374 deletions

View File

@@ -21,6 +21,7 @@
#include <osg/FrameBufferObject>
#include <osg/TextureRectangle>
#include <osg/Texture1D>
#include <osg/ContextData>
#include <OpenThreads/ScopedLock>
#include <OpenThreads/Mutex>
@@ -247,6 +248,11 @@ void Texture::TextureObject::bind()
if (_set) _set->moveToBack(this);
}
void Texture::TextureObject::release()
{
if (_set) _set->orphan(this);
}
void Texture::TextureObject::setAllocated(GLint numMipmapLevels,
GLenum internalFormat,
GLsizei width,
@@ -347,7 +353,7 @@ void Texture::TextureProfile::computeSize()
//
// New texture object manager
//
Texture::TextureObjectSet::TextureObjectSet(TextureObjectManager* parent, const TextureProfile& profile):
TextureObjectSet::TextureObjectSet(TextureObjectManager* parent, const Texture::TextureProfile& profile):
_parent(parent),
_contextID(parent->getContextID()),
_profile(profile),
@@ -357,7 +363,7 @@ Texture::TextureObjectSet::TextureObjectSet(TextureObjectManager* parent, const
{
}
Texture::TextureObjectSet::~TextureObjectSet()
TextureObjectSet::~TextureObjectSet()
{
#if 0
OSG_NOTICE<<"TextureObjectSet::~TextureObjectSet(), _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
@@ -367,7 +373,7 @@ Texture::TextureObjectSet::~TextureObjectSet()
#endif
}
bool Texture::TextureObjectSet::checkConsistency() const
bool TextureObjectSet::checkConsistency() const
{
OSG_NOTICE<<"TextureObjectSet::checkConsistency()"<<std::endl;
// check consistency of linked list.
@@ -381,7 +387,7 @@ bool Texture::TextureObjectSet::checkConsistency() const
{
if ((to->_next)->_previous != to)
{
OSG_NOTICE<<"Texture::TextureObjectSet::checkConsistency() : Error (to->_next)->_previous != to "<<std::endl;
OSG_NOTICE<<"TextureObjectSet::checkConsistency() : Error (to->_next)->_previous != to "<<std::endl;
return false;
}
}
@@ -389,7 +395,7 @@ bool Texture::TextureObjectSet::checkConsistency() const
{
if (_tail != to)
{
OSG_NOTICE<<"Texture::TextureObjectSet::checkConsistency() : Error _tail != to"<<std::endl;
OSG_NOTICE<<"TextureObjectSet::checkConsistency() : Error _tail != to"<<std::endl;
return false;
}
}
@@ -413,7 +419,7 @@ bool Texture::TextureObjectSet::checkConsistency() const
return true;
}
void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
void TextureObjectSet::handlePendingOrphandedTextureObjects()
{
// OSG_NOTICE<<"handlePendingOrphandedTextureObjects()"<<_pendingOrphanedTextureObjects.size()<<std::endl;
@@ -421,11 +427,11 @@ void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
unsigned int numOrphaned = _pendingOrphanedTextureObjects.size();
for(TextureObjectList::iterator itr = _pendingOrphanedTextureObjects.begin();
for(Texture::TextureObjectList::iterator itr = _pendingOrphanedTextureObjects.begin();
itr != _pendingOrphanedTextureObjects.end();
++itr)
{
TextureObject* to = itr->get();
Texture::TextureObject* to = itr->get();
_orphanedTextureObjects.push_back(to);
@@ -443,15 +449,15 @@ void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
}
void Texture::TextureObjectSet::deleteAllTextureObjects()
void TextureObjectSet::deleteAllTextureObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectSet::deleteAllTextureObjects()"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::deleteAllTextureObjects()"<<std::endl;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedTextureObjects.empty())
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedTextureObjects();
}
}
@@ -460,10 +466,10 @@ void Texture::TextureObjectSet::deleteAllTextureObjects()
// detect all the active texture objects from their Textures
unsigned int numOrphaned = 0;
TextureObject* to = _head;
Texture::TextureObject* to = _head;
while(to!=0)
{
ref_ptr<TextureObject> glto = to;
ref_ptr<Texture::TextureObject> glto = to;
to = to->_next;
@@ -489,14 +495,14 @@ void Texture::TextureObjectSet::deleteAllTextureObjects()
// OSG_NOTICE<<"done GLBufferObjectSet::deleteAllGLBufferObjects()"<<std::endl;
}
void Texture::TextureObjectSet::discardAllTextureObjects()
void TextureObjectSet::discardAllTextureObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectSet::discardAllTextureObjects()."<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::discardAllTextureObjects()."<<std::endl;
TextureObject* to = _head;
Texture::TextureObject* to = _head;
while(to!=0)
{
ref_ptr<TextureObject> glto = to;
ref_ptr<Texture::TextureObject> glto = to;
to = to->_next;
@@ -524,19 +530,19 @@ void Texture::TextureObjectSet::discardAllTextureObjects()
_parent->getNumberDeleted() += numDeleted;
}
void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
void TextureObjectSet::flushAllDeletedTextureObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushAllDeletedTextureObjects()"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushAllDeletedTextureObjects()"<<std::endl;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedTextureObjects.empty())
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedTextureObjects();
}
}
for(TextureObjectList::iterator itr = _orphanedTextureObjects.begin();
for(Texture::TextureObjectList::iterator itr = _orphanedTextureObjects.begin();
itr != _orphanedTextureObjects.end();
++itr)
{
@@ -558,16 +564,16 @@ void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
_orphanedTextureObjects.clear();
}
void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
void TextureObjectSet::discardAllDeletedTextureObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectSet::discardAllDeletedTextureObjects()"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::discardAllDeletedTextureObjects()"<<std::endl;
// clean up the pending orphans.
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedTextureObjects.empty())
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedTextureObjects();
}
}
@@ -587,15 +593,15 @@ void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
_orphanedTextureObjects.clear();
}
void Texture::TextureObjectSet::flushDeletedTextureObjects(double /*currentTime*/, double& availableTime)
void TextureObjectSet::flushDeletedTextureObjects(double /*currentTime*/, double& availableTime)
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..)"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushDeletedTextureObjects(..)"<<std::endl;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedTextureObjects.empty())
{
// OSG_NOTICE<<"Texture::TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::flushDeletedTextureObjects(..) handling orphans"<<std::endl;
handlePendingOrphandedTextureObjects();
}
}
@@ -627,7 +633,7 @@ void Texture::TextureObjectSet::flushDeletedTextureObjects(double /*currentTime*
ElapsedTime timer;
TextureObjectList::iterator itr = _orphanedTextureObjects.begin();
Texture::TextureObjectList::iterator itr = _orphanedTextureObjects.begin();
for(;
itr != _orphanedTextureObjects.end() && timer.elapsedTime()<availableTime && numDeleted<maxNumObjectsToDelete;
++itr)
@@ -657,13 +663,13 @@ void Texture::TextureObjectSet::flushDeletedTextureObjects(double /*currentTime*
availableTime -= timer.elapsedTime();
}
bool Texture::TextureObjectSet::makeSpace(unsigned int& size)
bool TextureObjectSet::makeSpace(unsigned int& size)
{
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
if (!_pendingOrphanedTextureObjects.empty())
{
// OSG_NOTICE<<"Texture::TextureObjectSet::Texture::TextureObjectSet::makeSpace(..) handling orphans"<<std::endl;
// OSG_NOTICE<<"TextureObjectSet::TextureObjectSet::makeSpace(..) handling orphans"<<std::endl;
handlePendingOrphandedTextureObjects();
}
}
@@ -680,10 +686,10 @@ bool Texture::TextureObjectSet::makeSpace(unsigned int& size)
return size==0;
}
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeFromOrphans(Texture* texture)
osg::ref_ptr<Texture::TextureObject> TextureObjectSet::takeFromOrphans(Texture* texture)
{
// take front of orphaned list.
ref_ptr<TextureObject> to = _orphanedTextureObjects.front();
ref_ptr<Texture::TextureObject> to = _orphanedTextureObjects.front();
// remove from orphan list.
_orphanedTextureObjects.pop_front();
@@ -704,7 +710,7 @@ osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeFromOrphans(
}
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeOrGenerate(Texture* texture)
osg::ref_ptr<Texture::TextureObject> TextureObjectSet::takeOrGenerate(Texture* texture)
{
// see if we can recyle TextureObject from the orphan list
{
@@ -733,7 +739,7 @@ osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeOrGenerate(T
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
ref_ptr<TextureObject> to = _head;
ref_ptr<Texture::TextureObject> to = _head;
ref_ptr<Texture> original_texture = to->getTexture();
@@ -761,7 +767,7 @@ osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeOrGenerate(T
GLuint id;
glGenTextures( 1L, &id );
osg::ref_ptr<TextureObject> to = new Texture::TextureObject(const_cast<Texture*>(texture),id,_profile);
osg::ref_ptr<Texture::TextureObject> to = new Texture::TextureObject(const_cast<Texture*>(texture),id,_profile);
to->_set = this;
++_numOfTextureObjects;
@@ -776,7 +782,7 @@ osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectSet::takeOrGenerate(T
return to;
}
void Texture::TextureObjectSet::moveToBack(Texture::TextureObject* to)
void TextureObjectSet::moveToBack(Texture::TextureObject* to)
{
#if 0
OSG_NOTICE<<"TextureObjectSet::moveToBack("<<to<<")"<<std::endl;
@@ -838,7 +844,7 @@ void Texture::TextureObjectSet::moveToBack(Texture::TextureObject* to)
CHECK_CONSISTENCY
}
void Texture::TextureObjectSet::addToBack(Texture::TextureObject* to)
void TextureObjectSet::addToBack(Texture::TextureObject* to)
{
#if 0
OSG_NOTICE<<"TextureObjectSet::addToBack("<<to<<")"<<std::endl;
@@ -871,7 +877,7 @@ void Texture::TextureObjectSet::addToBack(Texture::TextureObject* to)
CHECK_CONSISTENCY
}
void Texture::TextureObjectSet::orphan(Texture::TextureObject* to)
void TextureObjectSet::orphan(Texture::TextureObject* to)
{
// OSG_NOTICE<<"TextureObjectSet::orphan("<<to<<")"<<std::endl;
@@ -893,7 +899,7 @@ void Texture::TextureObjectSet::orphan(Texture::TextureObject* to)
#endif
}
void Texture::TextureObjectSet::remove(Texture::TextureObject* to)
void TextureObjectSet::remove(Texture::TextureObject* to)
{
if (to->_previous!=0)
{
@@ -920,7 +926,7 @@ void Texture::TextureObjectSet::remove(Texture::TextureObject* to)
to->_previous = 0;
}
void Texture::TextureObjectSet::moveToSet(TextureObject* to, TextureObjectSet* set)
void TextureObjectSet::moveToSet(Texture::TextureObject* to, TextureObjectSet* set)
{
if (set==this) return;
if (!set) return;
@@ -935,10 +941,10 @@ void Texture::TextureObjectSet::moveToSet(TextureObject* to, TextureObjectSet* s
set->addToBack(to);
}
unsigned int Texture::TextureObjectSet::computeNumTextureObjectsInList() const
unsigned int TextureObjectSet::computeNumTextureObjectsInList() const
{
unsigned int num=0;
TextureObject* obj = _head;
Texture::TextureObject* obj = _head;
while(obj!=NULL)
{
++num;
@@ -948,8 +954,8 @@ unsigned int Texture::TextureObjectSet::computeNumTextureObjectsInList() const
}
Texture::TextureObjectManager::TextureObjectManager(unsigned int contextID):
_contextID(contextID),
TextureObjectManager::TextureObjectManager(unsigned int contextID):
GraphicsObjectManager("TextureObjectManager", contextID),
_numActiveTextureObjects(0),
_numOrphanedTextureObjects(0),
_currTexturePoolSize(0),
@@ -959,13 +965,16 @@ Texture::TextureObjectManager::TextureObjectManager(unsigned int contextID):
_numDeleted(0),
_deleteTime(0.0),
_numGenerated(0),
_generateTime(0.0),
_numApplied(0),
_applyTime(0.0)
_generateTime(0.0)
{
}
void Texture::TextureObjectManager::setMaxTexturePoolSize(unsigned int size)
TextureObjectManager::~TextureObjectManager()
{
}
void TextureObjectManager::setMaxTexturePoolSize(unsigned int size)
{
if (_maxTexturePoolSize == size) return;
@@ -977,7 +986,7 @@ void Texture::TextureObjectManager::setMaxTexturePoolSize(unsigned int size)
_maxTexturePoolSize = size;
}
bool Texture::TextureObjectManager::makeSpace(unsigned int size)
bool TextureObjectManager::makeSpace(unsigned int size)
{
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end() && size>0;
@@ -990,12 +999,12 @@ bool Texture::TextureObjectManager::makeSpace(unsigned int size)
}
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectManager::generateTextureObject(const Texture* texture, GLenum target)
osg::ref_ptr<Texture::TextureObject> TextureObjectManager::generateTextureObject(const Texture* texture, GLenum target)
{
return generateTextureObject(texture, target, 0, 0, 0, 0, 0, 0);
}
osg::ref_ptr<Texture::TextureObject> Texture::TextureObjectManager::generateTextureObject(const Texture* texture,
osg::ref_ptr<Texture::TextureObject> TextureObjectManager::generateTextureObject(const Texture* texture,
GLenum target,
GLint numMipmapLevels,
GLenum internalFormat,
@@ -1032,14 +1041,14 @@ Texture::TextureObject* Texture::generateAndAssignTextureObject(
return _textureObjectBuffer[contextID].get();
}
Texture::TextureObjectSet* Texture::TextureObjectManager::getTextureObjectSet(const TextureProfile& profile)
TextureObjectSet* TextureObjectManager::getTextureObjectSet(const Texture::TextureProfile& profile)
{
osg::ref_ptr<Texture::TextureObjectSet>& tos = _textureSetMap[profile];
if (!tos) tos = new Texture::TextureObjectSet(this, profile);
osg::ref_ptr<TextureObjectSet>& tos = _textureSetMap[profile];
if (!tos) tos = new TextureObjectSet(this, profile);
return tos.get();
}
void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects()
void TextureObjectManager::handlePendingOrphandedTextureObjects()
{
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
@@ -1049,12 +1058,8 @@ void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects()
}
}
void Texture::TextureObjectManager::deleteAllTextureObjects()
void TextureObjectManager::deleteAllGLObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectManager::deleteAllTextureObjects() _contextID="<<_contextID<<std::endl;
ElapsedTime elapsedTime(&(getDeleteTime()));
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
++itr)
@@ -1063,10 +1068,8 @@ void Texture::TextureObjectManager::deleteAllTextureObjects()
}
}
void Texture::TextureObjectManager::discardAllTextureObjects()
void TextureObjectManager::discardAllGLObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectManager::discardAllTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
++itr)
@@ -1075,12 +1078,8 @@ void Texture::TextureObjectManager::discardAllTextureObjects()
}
}
void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
void TextureObjectManager::flushAllDeletedGLObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectManager::flushAllDeletedTextureObjects() _contextID="<<_contextID<<std::endl;
ElapsedTime elapsedTime(&(getDeleteTime()));
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
++itr)
@@ -1089,10 +1088,8 @@ void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
}
}
void Texture::TextureObjectManager::discardAllDeletedTextureObjects()
void TextureObjectManager::discardAllDeletedGLObjects()
{
// OSG_NOTICE<<"Texture::TextureObjectManager::discardAllDeletedTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
++itr)
@@ -1101,10 +1098,8 @@ void Texture::TextureObjectManager::discardAllDeletedTextureObjects()
}
}
void Texture::TextureObjectManager::flushDeletedTextureObjects(double currentTime, double& availableTime)
void TextureObjectManager::flushDeletedGLObjects(double currentTime, double& availableTime)
{
ElapsedTime elapsedTime(&(getDeleteTime()));
for(TextureSetMap::iterator itr = _textureSetMap.begin();
(itr != _textureSetMap.end()) && (availableTime > 0.0);
++itr)
@@ -1113,14 +1108,7 @@ void Texture::TextureObjectManager::flushDeletedTextureObjects(double currentTim
}
}
void Texture::TextureObjectManager::releaseTextureObject(Texture::TextureObject* to)
{
if (to->_set) to->_set->orphan(to);
else OSG_NOTICE<<"TextureObjectManager::releaseTextureObject(Texture::TextureObject* to) Not implemented yet"<<std::endl;
}
void Texture::TextureObjectManager::newFrame(osg::FrameStamp* fs)
void TextureObjectManager::newFrame(osg::FrameStamp* fs)
{
if (fs) _frameNumber = fs->getFrameNumber();
else ++_frameNumber;
@@ -1128,19 +1116,18 @@ void Texture::TextureObjectManager::newFrame(osg::FrameStamp* fs)
++_numFrames;
}
void Texture::TextureObjectManager::reportStats(std::ostream& out)
void TextureObjectManager::reportStats(std::ostream& out)
{
double numFrames(_numFrames==0 ? 1.0 : _numFrames);
out<<"TextureObjectMananger::reportStats()"<<std::endl;
out<<" total _numOfTextureObjects="<<_numActiveTextureObjects<<", _numOrphanedTextureObjects="<<_numOrphanedTextureObjects<<" _currTexturePoolSize="<<_currTexturePoolSize<<std::endl;
out<<" total _numGenerated="<<_numGenerated<<", _generateTime="<<_generateTime<<", averagePerFrame="<<_generateTime/numFrames*1000.0<<"ms"<<std::endl;
out<<" total _numDeleted="<<_numDeleted<<", _deleteTime="<<_deleteTime<<", averagePerFrame="<<_deleteTime/numFrames*1000.0<<"ms"<<std::endl;
out<<" total _numApplied="<<_numApplied<<", _applyTime="<<_applyTime<<", averagePerFrame="<<_applyTime/numFrames*1000.0<<"ms"<<std::endl;
out<<" getMaxTexturePoolSize()="<<getMaxTexturePoolSize()<<" current/max size = "<<double(_currTexturePoolSize)/double(getMaxTexturePoolSize())<<std::endl;
recomputeStats(out);
}
void Texture::TextureObjectManager::resetStats()
void TextureObjectManager::resetStats()
{
_numFrames = 0;
_numDeleted = 0;
@@ -1148,15 +1135,12 @@ void Texture::TextureObjectManager::resetStats()
_numGenerated = 0;
_generateTime = 0;
_numApplied = 0;
_applyTime = 0;
}
void Texture::TextureObjectManager::recomputeStats(std::ostream& out) const
void TextureObjectManager::recomputeStats(std::ostream& out) const
{
out<<"Texture::TextureObjectManager::recomputeStats()"<<std::endl;
out<<"TextureObjectManager::recomputeStats()"<<std::endl;
unsigned int numObjectsInLists = 0;
unsigned int numActive = 0;
unsigned int numOrphans = 0;
@@ -1184,7 +1168,7 @@ void Texture::TextureObjectManager::recomputeStats(std::ostream& out) const
if (currentSize != _currTexturePoolSize) out<<" WARNING: _currTexturePoolSize("<<_currTexturePoolSize<<") != currentSize, delta = "<<int(_currTexturePoolSize)-int(currentSize)<<std::endl;
}
bool Texture::TextureObjectManager::checkConsistency() const
bool TextureObjectManager::checkConsistency() const
{
unsigned int numObjectsInLists = 0;
unsigned int numActive = 0;
@@ -1207,25 +1191,15 @@ bool Texture::TextureObjectManager::checkConsistency() const
{
recomputeStats(osg::notify(osg::NOTICE));
throw "Texture::TextureObjectManager::checkConsistency() sizes inconsistent";
throw "TextureObjectManager::checkConsistency() sizes inconsistent";
return false;
}
return true;
}
osg::ref_ptr<Texture::TextureObjectManager>& Texture::getTextureObjectManager(unsigned int contextID)
{
typedef osg::buffered_object< ref_ptr<Texture::TextureObjectManager> > TextureObjectManagerBuffer;
static TextureObjectManagerBuffer s_TextureObjectManager;
if (!s_TextureObjectManager[contextID]) s_TextureObjectManager[contextID] = new Texture::TextureObjectManager(contextID);
return s_TextureObjectManager[contextID];
}
osg::ref_ptr<Texture::TextureObject> Texture::generateTextureObject(const Texture* texture, unsigned int contextID, GLenum target)
{
return getTextureObjectManager(contextID)->generateTextureObject(texture, target);
return osg::get<TextureObjectManager>(contextID)->generateTextureObject(texture, target);
}
osg::ref_ptr<Texture::TextureObject> Texture::generateTextureObject(const Texture* texture, unsigned int contextID,
@@ -1237,37 +1211,7 @@ osg::ref_ptr<Texture::TextureObject> Texture::generateTextureObject(const Textur
GLsizei depth,
GLint border)
{
return getTextureObjectManager(contextID)->generateTextureObject(texture,target,numMipmapLevels,internalFormat,width,height,depth,border);
}
void Texture::deleteAllTextureObjects(unsigned int contextID)
{
getTextureObjectManager(contextID)->deleteAllTextureObjects();
}
void Texture::discardAllTextureObjects(unsigned int contextID)
{
getTextureObjectManager(contextID)->discardAllTextureObjects();
}
void Texture::flushAllDeletedTextureObjects(unsigned int contextID)
{
getTextureObjectManager(contextID)->flushAllDeletedTextureObjects();
}
void Texture::discardAllDeletedTextureObjects(unsigned int contextID)
{
getTextureObjectManager(contextID)->discardAllDeletedTextureObjects();
}
void Texture::flushDeletedTextureObjects(unsigned int contextID,double currentTime, double& availbleTime)
{
getTextureObjectManager(contextID)->flushDeletedTextureObjects(currentTime, availbleTime);
}
void Texture::releaseTextureObject(unsigned int contextID, Texture::TextureObject* to)
{
getTextureObjectManager(contextID)->releaseTextureObject(to);
return osg::get<TextureObjectManager>(contextID)->generateTextureObject(texture,target,numMipmapLevels,internalFormat,width,height,depth,border);
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1453,7 +1397,7 @@ void Texture::dirtyTextureObject()
{
if (_textureObjectBuffer[i].valid())
{
Texture::releaseTextureObject(i, _textureObjectBuffer[i].get());
_textureObjectBuffer[i]->release();
_textureObjectBuffer[i] = 0;
}
}
@@ -2829,7 +2773,7 @@ void Texture::releaseGLObjects(State* state) const
unsigned int contextID = state->getContextID();
if (_textureObjectBuffer[contextID].valid())
{
Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get());
_textureObjectBuffer[contextID]->release();
_textureObjectBuffer[contextID] = 0;
}