From ab7111421984991a9d4c7a9aaa4bc6c806915acb Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 3 Jan 2006 10:44:14 +0000 Subject: [PATCH] Moved the body of the FBOExtensions::instance() to the .cpp and added bool to control whether that an FBOExtensions structure can be created if missing. --- include/osg/FrameBufferObject | 14 ++------------ src/osg/FrameBufferObject.cpp | 13 ++++++++++--- src/osgUtil/RenderStage.cpp | 4 ++-- 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/include/osg/FrameBufferObject b/include/osg/FrameBufferObject index 63e4410d8..04e1139d5 100644 --- a/include/osg/FrameBufferObject +++ b/include/osg/FrameBufferObject @@ -91,7 +91,7 @@ namespace osg * FBOExtensions **************************************************************************/ - class OSG_EXPORT FBOExtensions + class OSG_EXPORT FBOExtensions : public osg::Referenced { public: typedef void APIENTRY TglBindRenderbufferEXT(GLenum, GLuint); @@ -122,17 +122,7 @@ namespace osg TglFramebufferRenderbufferEXT* glFramebufferRenderbufferEXT; TglGenerateMipmapEXT* glGenerateMipmapEXT; - static FBOExtensions* instance(unsigned contextID) - { - static buffered_object _instances; - FBOExtensions *ext = _instances[contextID]; - if (!ext) - { - ext = new FBOExtensions(contextID); - _instances[contextID] = ext; - } - return ext; - } + static FBOExtensions* instance(unsigned contextID, bool createIfNotInitalized); bool isSupported() const { return _supported; } diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 67158c178..3ae88c5c2 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -27,6 +27,13 @@ using namespace osg; +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(); +} + /************************************************************************** * FBOExtensions **************************************************************************/ @@ -99,7 +106,7 @@ void RenderBuffer::flushDeletedRenderBuffers(unsigned int contextID,double /*cur // if no time available don't try to flush objects. if (availableTime<=0.0) return; - const FBOExtensions* extensions = FBOExtensions::instance(contextID); + const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); if(!extensions || !extensions->isSupported() ) return; const osg::Timer& timer = *osg::Timer::instance(); @@ -479,7 +486,7 @@ void FrameBufferObject::flushDeletedFrameBufferObjects(unsigned int contextID,do // if no time available don't try to flush objects. if (availableTime<=0.0) return; - const FBOExtensions* extensions = FBOExtensions::instance(contextID); + const FBOExtensions* extensions = FBOExtensions::instance(contextID,true); if(!extensions || !extensions->isSupported() ) return; const osg::Timer& timer = *osg::Timer::instance(); @@ -536,7 +543,7 @@ void FrameBufferObject::apply(State &state) const return; - FBOExtensions* ext = FBOExtensions::instance(contextID); + FBOExtensions* ext = FBOExtensions::instance(contextID,true); if (!ext->isSupported()) { _unsupported[contextID] = 1; diff --git a/src/osgUtil/RenderStage.cpp b/src/osgUtil/RenderStage.cpp index a5333a5c1..efb766e28 100644 --- a/src/osgUtil/RenderStage.cpp +++ b/src/osgUtil/RenderStage.cpp @@ -275,7 +275,7 @@ void RenderStage::runCameraSetUp(osg::State& state) if (renderTargetImplemntation==osg::CameraNode::FRAME_BUFFER_OBJECT) { - osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(state.getContextID()); + osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(state.getContextID(),true); bool fbo_supported = fbo_ext && fbo_ext->isSupported(); if (fbo_supported && !_fbo) @@ -617,7 +617,7 @@ void RenderStage::drawInner(osg::State& state,RenderLeaf*& previous, bool& doCop glReadBuffer(_readBuffer); } - osg::FBOExtensions* fbo_ext = _fbo.valid() ? osg::FBOExtensions::instance(state.getContextID()) : 0; + osg::FBOExtensions* fbo_ext = _fbo.valid() ? osg::FBOExtensions::instance(state.getContextID(),true) : 0; bool fbo_supported = fbo_ext && fbo_ext->isSupported(); if (fbo_supported)