diff --git a/include/osg/Texture b/include/osg/Texture index 8166b6303..50399629d 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -647,6 +647,9 @@ class SG_EXPORT Texture : public osg::StateAttribute TextureObjectListMap _textureObjectListMap; + // mutex to keep access serialized. + OpenThreads::Mutex _mutex; + }; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index b8e082b2c..c7a35fec4 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -33,13 +33,17 @@ using namespace osg; // is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below. typedef std::list DisplayListList; typedef std::map DeletedDisplayListCache; + +static OpenThreads::Mutex s_mutex_deletedDisplayListCache; static DeletedDisplayListCache s_deletedDisplayListCache; -static DeletedDisplayListCache s_deletedVertexBufferObjectCache; void Drawable::deleteDisplayList(unsigned int contextID,GLuint globj) { if (globj!=0) { +#ifdef THREAD_SAFE_DELETE_LISTS + OpenThreads::ScopedLock lock(s_mutex_deletedDisplayListCache); +#endif // insert the globj into the cache for the appropriate context. s_deletedDisplayListCache[contextID].push_back(globj); } @@ -58,31 +62,45 @@ void Drawable::flushDeletedDisplayLists(unsigned int contextID,double /*currentT unsigned int noDeleted = 0; - DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID); - if (citr!=s_deletedDisplayListCache.end()) { - DisplayListList& dll = citr->second; - - for(DisplayListList::iterator ditr=dll.begin(); - ditr!=dll.end() && elapsedTime lock(s_mutex_deletedDisplayListCache); +#endif + DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID); + if (citr!=s_deletedDisplayListCache.end()) + { + DisplayListList& dll = citr->second; + + for(DisplayListList::iterator ditr=dll.begin(); + ditr!=dll.end() && elapsedTimesecond; - - for(GL2ObjectList::iterator titr=vpObjectList.begin(); - titr!=vpObjectList.end() && elapsedTimeglDeleteObject( *titr ); - titr = vpObjectList.erase( titr ); - elapsedTime = timer.delta_s(start_tick,timer.tick()); + const Extensions* extensions = Extensions::Get(contextID,true); + + if (!extensions->isGlslSupported()) + { + // can we really get here? + osg::notify(osg::WARN) << "flushDeletedGL2Objects not supported by OpenGL driver" << std::endl; + 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; }