diff --git a/include/osgGL2/ProgramObject b/include/osgGL2/ProgramObject index 0708bdf98..53e76bb93 100644 --- a/include/osgGL2/ProgramObject +++ b/include/osgGL2/ProgramObject @@ -34,15 +34,6 @@ namespace osgGL2 { -/** use deleteObject instead of glDeleteObject to allow - * GL2 Objects to cached until they can be deleted - * by the OpenGL context in which they were created, specified - * by contextID.*/ -extern OSGGL2_EXPORT void DeleteObject(unsigned int contextID, GLhandleARB handle); - -/** flush all the cached glProgramObjects which need to be deleted - * in the OpenGL context related to contextID.*/ -extern OSGGL2_EXPORT void FlushDeletedGL2Objects(unsigned int contextID); /////////////////////////////////////////////////////////////////////////// @@ -87,6 +78,16 @@ class OSGGL2_EXPORT ProgramObject : public osg::StateAttribute void dirtyProgramObject(); void addShader( ShaderObject* shader ); + + /** use deleteObject instead of glDeleteObject to allow + * GL2 Objects to cached until they can be deleted + * by the OpenGL context in which they were created, specified + * by contextID.*/ + static void deleteObject(unsigned int contextID, GLhandleARB handle); + + /** flush all the cached glProgramObjects which need to be deleted + * in the OpenGL context related to contextID.*/ + static void flushDeletedGL2Objects(unsigned int contextID,double currentTime, double& availableTime); protected: diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 73f5f857f..bea82343c 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -19,18 +19,19 @@ #include #include #include +#include #include #include -#include +#include using namespace osg; // static cache of deleted display lists which can only // by completely deleted once the appropriate OpenGL context // is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below. -typedef std::vector DisplayListVector; -typedef std::map DeletedDisplayListCache; +typedef std::list DisplayListList; +typedef std::map DeletedDisplayListCache; static DeletedDisplayListCache s_deletedDisplayListCache; static DeletedDisplayListCache s_deletedVertexBufferObjectCache; @@ -45,25 +46,36 @@ void Drawable::deleteDisplayList(unsigned int contextID,GLuint globj) /** flush all the cached display list which need to be deleted * in the OpenGL context related to contextID.*/ -void Drawable::flushDeletedDisplayLists(unsigned int contextID,double currentTime, double& availableTime) +void Drawable::flushDeletedDisplayLists(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; + + unsigned int noDeleted = 0; + DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID); if (citr!=s_deletedDisplayListCache.end()) { - DisplayListVector displayListSet; - displayListSet.reserve(1000); - - // this swap will transfer the content of and empty citr->second - // in one quick pointer change. - displayListSet.swap(citr->second); - - for(DisplayListVector::iterator gitr=displayListSet.begin(); - gitr!=displayListSet.end(); - ++gitr) + DisplayListList& dll = citr->second; + + for(DisplayListList::iterator ditr=dll.begin(); + ditr!=dll.end() && elapsedTime s_textureObjectManager; diff --git a/src/osg/VertexProgram.cpp b/src/osg/VertexProgram.cpp index 8edf734ce..f27d9b0ac 100644 --- a/src/osg/VertexProgram.cpp +++ b/src/osg/VertexProgram.cpp @@ -14,14 +14,17 @@ #include #include #include +#include + +#include using namespace osg; // static cache of deleted vertex programs which can only // by completely deleted once the appropriate OpenGL context // is set. -typedef std::vector VertexProgramObjectVector; -typedef std::map DeletedVertexProgramObjectCache; +typedef std::list VertexProgramObjectList; +typedef std::map DeletedVertexProgramObjectCache; static DeletedVertexProgramObjectCache s_deletedVertexProgramObjectCache; void VertexProgram::deleteVertexProgramObject(unsigned int contextID,GLuint handle) @@ -34,30 +37,34 @@ void VertexProgram::deleteVertexProgramObject(unsigned int contextID,GLuint hand } -void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,double currentTime, double& availableTime) +void VertexProgram::flushDeletedVertexProgramObjects(unsigned int contextID,double /*currentTime*/, double& availableTime) { - const Extensions* extensions = getExtensions(contextID,true); + // if no time available don't try to flush objects. + if (availableTime<=0.0) return; - if (!extensions->isVertexProgramSupported()) - return; + const osg::Timer& timer = *osg::Timer::instance(); + osg::Timer_t start_tick = timer.tick(); + double elapsedTime = 0.0; DeletedVertexProgramObjectCache::iterator citr = s_deletedVertexProgramObjectCache.find(contextID); if (citr!=s_deletedVertexProgramObjectCache.end()) { - VertexProgramObjectVector vpObjectSet; - vpObjectSet.reserve(1000); + + const Extensions* extensions = getExtensions(contextID,true); - // this swap will transfer the content of and empty citr->second - // in one quick pointer change. - vpObjectSet.swap(citr->second); - - for(VertexProgramObjectVector::iterator titr=vpObjectSet.begin(); - titr!=vpObjectSet.end(); - ++titr) + VertexProgramObjectList& vpol = citr->second; + + for(VertexProgramObjectList::iterator titr=vpol.begin(); + titr!=vpol.end() && elapsedTimeglDeletePrograms( 1L, &(*titr ) ); + titr = vpol.erase(titr); + elapsedTime = timer.delta_s(start_tick,timer.tick()); } } + + availableTime -= elapsedTime; } diff --git a/src/osgGL2/ProgramObject.cpp b/src/osgGL2/ProgramObject.cpp index ec8edce68..6baaa5db1 100644 --- a/src/osgGL2/ProgramObject.cpp +++ b/src/osgGL2/ProgramObject.cpp @@ -23,21 +23,24 @@ #include #include #include +#include #include #include +#include + using namespace osgGL2; /////////////////////////////////////////////////////////////////////////// // static cache of deleted GL2 objects which may only // by actually deleted in the correct GL context. -typedef std::vector GL2ObjectVector; -typedef std::map DeletedGL2ObjectCache; +typedef std::list GL2ObjectList; +typedef std::map DeletedGL2ObjectCache; static DeletedGL2ObjectCache s_deletedGL2ObjectCache; -void osgGL2::DeleteObject(unsigned int contextID, GLhandleARB handle) +void ProgramObject::deleteObject(unsigned int contextID, GLhandleARB handle) { if (handle!=0) { @@ -46,28 +49,36 @@ void osgGL2::DeleteObject(unsigned int contextID, GLhandleARB handle) } } -void osgGL2::FlushDeletedGL2Objects(unsigned int contextID) +void ProgramObject::flushDeletedGL2Objects(unsigned int contextID,double /*currentTime*/, double& availableTime) { - const Extensions* extensions = Extensions::Get(contextID,true); + // if no time available don't try to flush objects. + if (availableTime<=0.0) return; - if (!extensions->isShaderObjectsSupported()) - return; + const osg::Timer& timer = *osg::Timer::instance(); + osg::Timer_t start_tick = timer.tick(); + double elapsedTime = 0.0; DeletedGL2ObjectCache::iterator citr = s_deletedGL2ObjectCache.find(contextID); if( citr != s_deletedGL2ObjectCache.end() ) { - GL2ObjectVector vpObjectSet; + const Extensions* extensions = Extensions::Get(contextID,true); - // this swap will transfer the content of and empty citr->second - // in one quick pointer change. - vpObjectSet.swap(citr->second); - for( GL2ObjectVector::iterator titr=vpObjectSet.begin(); - titr!=vpObjectSet.end(); - ++titr ) + if (!extensions->isShaderObjectsSupported()) + return; + + GL2ObjectList& vpObjectList = citr->second; + + for(GL2ObjectList::iterator titr=vpObjectList.begin(); + titr!=vpObjectList.end() && elapsedTimeglDeleteObject( *titr ); + titr = vpObjectList.erase( titr ); + elapsedTime = timer.delta_s(start_tick,timer.tick()); } } + + availableTime -= elapsedTime; } /////////////////////////////////////////////////////////////////////////// @@ -94,7 +105,7 @@ ProgramObject::~ProgramObject() PerContextProgObj* pcpo = _pcpoList[cxt].get(); - DeleteObject( cxt, pcpo->getHandle() ); + deleteObject( cxt, pcpo->getHandle() ); // TODO add shader objects to delete list. _pcpoList[cxt] = 0; }