From d63b351137d65b67292aab668bbe79222fe20a3d Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 17 Jan 2007 14:40:03 +0000 Subject: [PATCH] =?UTF-8?q?From=20Andr=C3=A9=20Garneau,=20threading=20bug?= =?UTF-8?q?=20fixes=20-=20moving=20scoped=20statics=20out=20of=20scope=20t?= =?UTF-8?q?o=20be=20global=20statics?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/osg/FrameBufferObject.cpp | 2 +- src/osg/GLExtensions.cpp | 40 +++++++++++++++++------------------ src/osg/Texture.cpp | 40 ++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 40 deletions(-) diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 984408e5e..70f86df9a 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -26,10 +26,10 @@ using namespace osg; +static buffered_object< ref_ptr > s_extensions; FBOExtensions* FBOExtensions::instance(unsigned contextID, bool createIfNotInitalized) { - static buffered_object< ref_ptr > s_extensions; if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new FBOExtensions(contextID); return s_extensions[contextID].get(); } diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index 30331e8aa..0cd8531c2 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -28,6 +28,18 @@ #include #endif +typedef std::set ExtensionSet; +static osg::buffered_object s_glExtensionSetList; +static osg::buffered_object s_glRendererList; +static osg::buffered_value s_glInitializedList; + +static osg::buffered_object s_gluExtensionSetList; +static osg::buffered_object s_gluRendererList; +static osg::buffered_value s_gluInitializedList; + +static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE"); +static std::string s_GLExtensionDisableString(envVar?envVar:"Nothing defined"); + float osg::getGLVersionNumber() { // needs to be extended to do proper things with subversions like 1.5.1, etc. @@ -38,18 +50,13 @@ float osg::getGLVersionNumber() bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension) { - typedef std::set ExtensionSet; - static osg::buffered_object s_extensionSetList; - static osg::buffered_object s_rendererList; - static osg::buffered_value s_initializedList; - - ExtensionSet& extensionSet = s_extensionSetList[contextID]; - std::string& rendererString = s_rendererList[contextID]; + ExtensionSet& extensionSet = s_glExtensionSetList[contextID]; + std::string& rendererString = s_glRendererList[contextID]; // if not already set up, initialize all the per graphic context values. - if (!s_initializedList[contextID]) + if (!s_glInitializedList[contextID]) { - s_initializedList[contextID] = 1; + s_glInitializedList[contextID] = 1; // set up the renderer const GLubyte* renderer = glGetString(GL_RENDERER); @@ -194,26 +201,19 @@ void osg::setGLExtensionDisableString(const std::string& disableString) std::string& osg::getGLExtensionDisableString() { - static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE"); - static std::string s_GLExtensionDisableString(envVar?envVar:"Nothing defined"); return s_GLExtensionDisableString; } bool osg::isGLUExtensionSupported(unsigned int contextID, const char *extension) { - typedef std::set ExtensionSet; - static osg::buffered_object s_extensionSetList; - static osg::buffered_object s_rendererList; - static osg::buffered_value s_initializedList; - - ExtensionSet& extensionSet = s_extensionSetList[contextID]; - std::string& rendererString = s_rendererList[contextID]; + ExtensionSet& extensionSet = s_gluExtensionSetList[contextID]; + std::string& rendererString = s_gluRendererList[contextID]; // if not already set up, initialize all the per graphic context values. - if (!s_initializedList[contextID]) + if (!s_gluInitializedList[contextID]) { - s_initializedList[contextID] = 1; + s_gluInitializedList[contextID] = 1; // set up the renderer const GLubyte* renderer = glGetString(GL_RENDERER); diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 52faa0270..3f51626e9 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -45,21 +45,6 @@ using namespace osg; ApplicationUsageProxy Texture_e0(ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_MAX_TEXTURE_SIZE","Set the maximum size of textures."); -unsigned int Texture::s_numberTextureReusedLastInLastFrame = 0; -unsigned int Texture::s_numberNewTextureInLastFrame = 0; -unsigned int Texture::s_numberDeletedTextureInLastFrame = 0; - -unsigned int s_minimumNumberOfTextureObjectsToRetainInCache = 0; -void Texture::setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum) -{ - s_minimumNumberOfTextureObjectsToRetainInCache = minimum; -} - -unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() -{ - return s_minimumNumberOfTextureObjectsToRetainInCache; -} - class TextureObjectManager : public osg::Referenced { public: @@ -130,6 +115,27 @@ public: OpenThreads::Mutex _mutex; }; +unsigned int Texture::s_numberTextureReusedLastInLastFrame = 0; +unsigned int Texture::s_numberNewTextureInLastFrame = 0; +unsigned int Texture::s_numberDeletedTextureInLastFrame = 0; + +unsigned int s_minimumNumberOfTextureObjectsToRetainInCache = 0; + +typedef buffered_value< ref_ptr > BufferedExtensions; +static BufferedExtensions s_extensions; + +static ref_ptr s_textureObjectManager = new TextureObjectManager; + +void Texture::setMinimumNumberOfTextureObjectsToRetainInCache(unsigned int minimum) +{ + s_minimumNumberOfTextureObjectsToRetainInCache = minimum; +} + +unsigned int Texture::getMinimumNumberOfTextureObjectsToRetainInCache() +{ + return s_minimumNumberOfTextureObjectsToRetainInCache; +} + Texture::TextureObject* TextureObjectManager::generateTextureObject(unsigned int /*contextID*/,GLenum target) { GLuint id; @@ -290,7 +296,6 @@ void TextureObjectManager::flushTextureObjects(unsigned int contextID,double cur static TextureObjectManager* getTextureObjectManager() { - static ref_ptr s_textureObjectManager = new TextureObjectManager; return s_textureObjectManager.get(); } @@ -1322,9 +1327,6 @@ void Texture::releaseGLObjects(State* state) const } } -typedef buffered_value< ref_ptr > BufferedExtensions; -static BufferedExtensions s_extensions; - Texture::Extensions* Texture::getExtensions(unsigned int contextID,bool createIfNotInitalized) { if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Extensions(contextID);