From 6ebeff658ad77fc6fd327595b6ad4a14d053478a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 27 Nov 2009 11:43:18 +0000 Subject: [PATCH] Implement deleteAllTextureObject/BufferObjects functionality. Cleaned up warnings. --- include/osg/BufferObject | 14 ++--- src/osg/BufferObject.cpp | 120 ++++++++++++++++----------------------- src/osg/Texture.cpp | 65 ++++++++++++++------- 3 files changed, 101 insertions(+), 98 deletions(-) diff --git a/include/osg/BufferObject b/include/osg/BufferObject index 4a8980592..9cf15be18 100644 --- a/include/osg/BufferObject +++ b/include/osg/BufferObject @@ -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); +} } diff --git a/src/osg/BufferObject.cpp b/src/osg/BufferObject.cpp index e127295c3..c73c725f0 100644 --- a/src/osg/BufferObject.cpp +++ b/src/osg/BufferObject.cpp @@ -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 "<glBindBuffer(_profile._target,_glObjectID); - if (_set) _set->moveToBack(this); + //osg::notify(osg::NOTICE)<<"Destucting BufferObject "<glDeleteBuffers(1, &_glObjectID); @@ -235,55 +230,6 @@ void GLBufferObject::deleteGLObject() } } -void GLBufferObject::deleteBufferObject(unsigned int contextID,GLuint globj) -{ - osg::notify(osg::NOTICE)<<"GLBufferObject::deleteBufferObject("< 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() && elapsedTimeglDeleteBuffers(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 = "< 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."< glbo = to; + + to = to->_next; + + _orphanedGLBufferObjects.push_back(glbo.get()); + remove(glbo.get()); + + ref_ptr 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()"<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()<getContextID(); @@ -1209,7 +1187,7 @@ void BufferObject::releaseGLObjects(State* state) const { if (_glBufferObjects[i].valid()) { - osg::notify(osg::NOTICE)<<" GLBufferObject::releaseGLBufferObject("< glto = to; + + to = to->_next; + + _orphanedTextureObjects.push_back(glto.get()); + remove(glto.get()); + + ref_ptr 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()"<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="<