Implement deleteAllTextureObject/BufferObjects functionality.

Cleaned up warnings.
This commit is contained in:
Robert Osfield
2009-11-27 11:43:18 +00:00
parent ab8d93a181
commit 6ebeff658a
3 changed files with 101 additions and 98 deletions

View File

@@ -208,7 +208,7 @@ class OSG_EXPORT GLBufferObject : public Referenced
inline GLuint getGLObjectID() const { return _glObjectID; }
inline GLsizeiptrARB getOffset(unsigned int i) const { return _bufferEntries[i].offset; }
void bindBuffer();
inline void bindBuffer();
inline void unbindBuffer()
{
@@ -231,13 +231,6 @@ class OSG_EXPORT GLBufferObject : public Referenced
static GLBufferObject* createGLBufferObject(unsigned int contextID, const BufferObject* bufferObject);
/** Use deleteVertexBufferObject instead of glDeleteBuffers to allow
* OpenGL buffer objects to be cached until they can be deleted
* by the OpenGL context in which they were created, specified
* by contextID.*/
static void deleteBufferObject(unsigned int contextID,GLuint globj);
static void deleteAllBufferObjects(unsigned int contextID);
static void discardAllBufferObjects(unsigned int contextID);
static void flushAllDeletedBufferObjects(unsigned int contextID);
@@ -734,6 +727,11 @@ class OSG_EXPORT PixelDataBufferObject : public BufferObject
};
inline void GLBufferObject::bindBuffer()
{
_extensions->glBindBuffer(_profile._target,_glObjectID);
if (_set) _set->moveToBack(this);
}
}

View File

@@ -61,18 +61,12 @@ GLBufferObject::GLBufferObject(unsigned int contextID, BufferObject* bufferObjec
_extensions = GLBufferObject::getExtensions(contextID, true);
_extensions->glGenBuffers(1, &_glObjectID);
osg::notify(osg::NOTICE)<<"Constucting BufferObject "<<this<<std::endl;
// osg::notify(osg::NOTICE)<<"Constucting BufferObject "<<this<<std::endl;
}
GLBufferObject::~GLBufferObject()
{
osg::notify(osg::NOTICE)<<"Destucting BufferObject "<<this<<std::endl;
}
void GLBufferObject::bindBuffer()
{
_extensions->glBindBuffer(_profile._target,_glObjectID);
if (_set) _set->moveToBack(this);
//osg::notify(osg::NOTICE)<<"Destucting BufferObject "<<this<<std::endl;
}
void GLBufferObject::setBufferObject(BufferObject* bufferObject)
@@ -225,6 +219,7 @@ void GLBufferObject::compileBuffer()
void GLBufferObject::deleteGLObject()
{
// osg::notify(osg::NOTICE)<<"GLBufferObject::deleteGLObject() "<<_glObjectID<<std::endl;
if (_glObjectID!=0)
{
_extensions->glDeleteBuffers(1, &_glObjectID);
@@ -235,55 +230,6 @@ void GLBufferObject::deleteGLObject()
}
}
void GLBufferObject::deleteBufferObject(unsigned int contextID,GLuint globj)
{
osg::notify(osg::NOTICE)<<"GLBufferObject::deleteBufferObject("<<std::endl;
}
#if 0
void GLBufferObject::flushDeletedBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime)
{
// if no time available don't try to flush objects.
if (availableTime<=0.0) return;
const osg::Timer& timer = *osg::Timer::instance();
osg::Timer_t start_tick = timer.tick();
double elapsedTime = 0.0;
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedBufferObjectCache);
const Extensions* extensions = getExtensions(contextID,true);
unsigned int noDeleted = 0;
BufferObjectMap& dll = s_deletedBufferObjectCache[contextID];
BufferObjectMap::iterator ditr=dll.begin();
for(;
ditr!=dll.end() && elapsedTime<availableTime;
++ditr)
{
extensions->glDeleteBuffers(1,&(ditr->second));
elapsedTime = timer.delta_s(start_tick,timer.tick());
++noDeleted;
}
if (ditr!=dll.begin()) dll.erase(dll.begin(),ditr);
// if (noDeleted!=0) notify(osg::NOTICE)<<"Number VBOs deleted = "<<noDeleted<<" BO's left"<<dll.size()<<std::endl;
}
availableTime -= elapsedTime;
}
void GLBufferObject::discardDeletedBufferObjects(unsigned int contextID)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedBufferObjectCache);
BufferObjectMap& dll = s_deletedBufferObjectCache[contextID];
dll.clear();
}
#endif
//////////////////////////////////////////////////////////////////////////////
//
// Extension support
@@ -546,12 +492,44 @@ void GLBufferObjectSet::handlePendingOrphandedGLBufferObjects()
void GLBufferObjectSet::deleteAllGLBufferObjects()
{
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::deleteAllGLBufferObjects() not implemented yet."<<std::endl;
// osg::notify(osg::NOTICE)<<"GLBufferObjectSet::deleteAllGLBufferObjects()"<<std::endl;
// clean up the pending orphans.
handlePendingOrphandedGLBufferObjects();
GLBufferObject* to = _head;
while(to!=0)
{
ref_ptr<GLBufferObject> glbo = to;
to = to->_next;
_orphanedGLBufferObjects.push_back(glbo.get());
remove(glbo.get());
ref_ptr<BufferObject> original_BufferObject = glbo->getBufferObject();
if (original_BufferObject.valid())
{
// detect the GLBufferObject from the BufferObject
original_BufferObject->setGLBufferObject(_contextID,0);
}
}
_head = 0;
_tail = 0;
// clean up the pending orphans.
handlePendingOrphandedGLBufferObjects();
// do the actual delete.
flushAllDeletedGLBufferObjects();
// osg::notify(osg::NOTICE)<<"done GLBufferObjectSet::deleteAllGLBufferObjects()"<<std::endl;
}
void GLBufferObjectSet::discardAllGLBufferObjects()
{
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllGLBufferObjects()"<<std::endl;
// osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllGLBufferObjects()"<<std::endl;
GLBufferObject* to = _head;
while(to!=0)
@@ -570,9 +548,18 @@ void GLBufferObjectSet::discardAllGLBufferObjects()
// the linked list should now be empty
_head = 0;
_tail = 0;
_pendingOrphanedGLBufferObjects.clear();
_orphanedGLBufferObjects.clear();
unsigned int numDeleted = _numOfGLBufferObjects;
_numOfGLBufferObjects = 0;
// update the GLBufferObjectManager's running total of current pool size
_parent->getCurrGLBufferObjectPoolSize() -= numDeleted*_profile._size;
_parent->getNumberOrphanedGLBufferObjects() -= numDeleted;
_parent->getNumberDeleted() += numDeleted;
}
void GLBufferObjectSet::flushAllDeletedGLBufferObjects()
@@ -581,10 +568,7 @@ void GLBufferObjectSet::flushAllDeletedGLBufferObjects()
itr != _orphanedGLBufferObjects.end();
++itr)
{
(*itr)->deleteGLObject();
osg::notify(osg::NOTICE)<<"Deleting textureobject id="<<(*itr)->getGLObjectID()<<std::endl;
}
unsigned int numDeleted = _orphanedGLBufferObjects.size();
@@ -600,15 +584,11 @@ void GLBufferObjectSet::flushAllDeletedGLBufferObjects()
void GLBufferObjectSet::discardAllDeletedGLBufferObjects()
{
osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllDeletedGLBufferObjects()"<<std::endl;
// osg::notify(osg::NOTICE)<<"GLBufferObjectSet::discardAllDeletedGLBufferObjects()"<<std::endl;
// clean up the pending orphans.
handlePendingOrphandedGLBufferObjects();
osg::notify(osg::NOTICE)<<" _orphanedGLBufferObjects.size() = "<<_orphanedGLBufferObjects.size()<<std::endl;
osg::notify(osg::NOTICE)<<" _pendingOrphanedGLBufferObjects.size() = "<<_pendingOrphanedGLBufferObjects.size()<<std::endl;
unsigned int numDiscarded = _orphanedGLBufferObjects.size();
_numOfGLBufferObjects -= numDiscarded;
@@ -649,8 +629,6 @@ void GLBufferObjectSet::flushDeletedGLBufferObjects(double currentTime, double&
++itr)
{
osg::notify(osg::NOTICE)<<"Deleting textureobject id="<<itr->get()<<std::endl;
(*itr)->deleteGLObject();
++numDeleted;
@@ -1193,7 +1171,7 @@ void BufferObject::resizeGLObjectBuffers(unsigned int maxSize)
void BufferObject::releaseGLObjects(State* state) const
{
osg::notify(osg::NOTICE)<<"BufferObject::releaseGLObjects("<<state<<")"<<std::endl;
// osg::notify(osg::NOTICE)<<"BufferObject::releaseGLObjects("<<state<<")"<<std::endl;
if (state)
{
unsigned int contextID = state->getContextID();
@@ -1209,7 +1187,7 @@ void BufferObject::releaseGLObjects(State* state) const
{
if (_glBufferObjects[i].valid())
{
osg::notify(osg::NOTICE)<<" GLBufferObject::releaseGLBufferObject("<<i<<", _glBufferObjects["<<i<<"]="<<_glBufferObjects[i].get()<<")"<<std::endl;
// osg::notify(osg::NOTICE)<<" GLBufferObject::releaseGLBufferObject("<<i<<", _glBufferObjects["<<i<<"]="<<_glBufferObjects[i].get()<<")"<<std::endl;
GLBufferObject::releaseGLBufferObject(i, _glBufferObjects[i].get());
_glBufferObjects[i] = 0;
}

View File

@@ -74,7 +74,7 @@ unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache()
Texture::TextureObject::~TextureObject()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "<<this<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObject::~TextureObject() "<<this<<std::endl;
}
void Texture::TextureObject::bind()
@@ -223,7 +223,7 @@ bool Texture::TextureObjectSet::checkConsistency() const
void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
{
osg::notify(osg::NOTICE)<<"handlePendingOrphandedTextureObjects()"<<_pendingOrphanedTextureObjects.size()<<std::endl;
// osg::notify(osg::NOTICE)<<"handlePendingOrphandedTextureObjects()"<<_pendingOrphanedTextureObjects.size()<<std::endl;
if (_pendingOrphanedTextureObjects.empty()) return;
@@ -261,12 +261,38 @@ void Texture::TextureObjectSet::handlePendingOrphandedTextureObjects()
void Texture::TextureObjectSet::deleteAllTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::deleteAllTextureObjects() not implemented yet."<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::deleteAllTextureObjects()"<<std::endl;
// move the pending orhpans into the orhans list
handlePendingOrphandedTextureObjects();
// detect all the active texture objects from their Textures
TextureObject* to = _head;
while(to!=0)
{
ref_ptr<TextureObject> glto = to;
to = to->_next;
_orphanedTextureObjects.push_back(glto.get());
remove(glto.get());
ref_ptr<Texture> original_texture = glto->getTexture();
if (original_texture.valid())
{
original_texture->setTextureObject(_contextID,0);
}
}
// now do the actual delete.
flushAllDeletedTextureObjects();
// osg::notify(osg::NOTICE)<<"done GLBufferObjectSet::deleteAllGLBufferObjects()"<<std::endl;
}
void Texture::TextureObjectSet::discardAllTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllTextureObjects()."<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllTextureObjects()."<<std::endl;
TextureObject* to = _head;
while(to!=0)
@@ -288,6 +314,14 @@ void Texture::TextureObjectSet::discardAllTextureObjects()
_pendingOrphanedTextureObjects.clear();
_orphanedTextureObjects.clear();
unsigned int numDeleted = _numOfTextureObjects;
_numOfTextureObjects = 0;
// update the TextureObjectManager's running total of current pool size
_parent->getCurrTexturePoolSize() -= numDeleted*_profile._size;
_parent->getNumberOrphanedTextureObjects() -= numDeleted;
_parent->getNumberDeleted() += numDeleted;
}
void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
@@ -301,8 +335,7 @@ void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
GLuint id = (*itr)->id();
osg::notify(osg::NOTICE)<<"Deleting textureobject id="<<id<<std::endl;
// osg::notify(osg::NOTICE)<<" Deleting textureobject ptr="<<itr->get()<<" id="<<id<<std::endl;
glDeleteTextures( 1L, &id);
}
@@ -319,15 +352,11 @@ void Texture::TextureObjectSet::flushAllDeletedTextureObjects()
void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllDeletedTextureObjects()"<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectSet::discardAllDeletedTextureObjects()"<<std::endl;
// clean up the pending orphans.
handlePendingOrphandedTextureObjects();
osg::notify(osg::NOTICE)<<" _orphanedTextureObjects.size() = "<<_orphanedTextureObjects.size()<<std::endl;
osg::notify(osg::NOTICE)<<" _pendingOrphanedTextureObjects.size() = "<<_pendingOrphanedTextureObjects.size()<<std::endl;
unsigned int numDiscarded = _orphanedTextureObjects.size();
_numOfTextureObjects -= numDiscarded;
@@ -340,7 +369,6 @@ void Texture::TextureObjectSet::discardAllDeletedTextureObjects()
_parent->getNumberActiveTextureObjects() += 1;
_parent->getNumberDeleted() += 1;
// just clear the list as there is nothing else we can do with them when discarding them
_orphanedTextureObjects.clear();
}
@@ -372,8 +400,7 @@ void Texture::TextureObjectSet::flushDeletedTextureObjects(double currentTime, d
GLuint id = (*itr)->id();
osg::notify(osg::NOTICE)<<"Deleting textureobject id="<<id<<std::endl;
// osg::notify(osg::NOTICE)<<" Deleting textureobject ptr="<<itr->get()<<" id="<<id<<std::endl;
glDeleteTextures( 1L, &id);
++numDeleted;
@@ -428,7 +455,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeFromOrphans(Texture* text
// place at back of active list
addToBack(to.get());
osg::notify(osg::INFO)<<"Reusing orhpahned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
// osg::notify(osg::INFO)<<"Reusing orhpahned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
return to.release();
}
@@ -746,7 +773,7 @@ void Texture::TextureObjectManager::handlePendingOrphandedTextureObjects()
void Texture::TextureObjectManager::deleteAllTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::deleteAllTextureObjects() _contextID="<<_contextID<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::deleteAllTextureObjects() _contextID="<<_contextID<<std::endl;
ElapsedTime elapsedTime(&(getDeleteTime()));
@@ -760,7 +787,7 @@ void Texture::TextureObjectManager::deleteAllTextureObjects()
void Texture::TextureObjectManager::discardAllTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();
@@ -772,7 +799,7 @@ void Texture::TextureObjectManager::discardAllTextureObjects()
void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::flushAllDeletedTextureObjects() _contextID="<<_contextID<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::flushAllDeletedTextureObjects() _contextID="<<_contextID<<std::endl;
ElapsedTime elapsedTime(&(getDeleteTime()));
@@ -786,7 +813,7 @@ void Texture::TextureObjectManager::flushAllDeletedTextureObjects()
void Texture::TextureObjectManager::discardAllDeletedTextureObjects()
{
osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllDeletedTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
// osg::notify(osg::NOTICE)<<"Texture::TextureObjectManager::discardAllDeletedTextureObjects() _contextID="<<_contextID<<" _numActiveTextureObjects="<<_numActiveTextureObjects<<std::endl;
for(TextureSetMap::iterator itr = _textureSetMap.begin();
itr != _textureSetMap.end();