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.
This commit is contained in:
Robert Osfield 2006-01-03 10:44:14 +00:00
parent 4167bc3673
commit ab71114219
3 changed files with 14 additions and 17 deletions

View File

@ -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<FBOExtensions *> _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; }

View File

@ -27,6 +27,13 @@
using namespace osg;
FBOExtensions* FBOExtensions::instance(unsigned contextID, bool createIfNotInitalized)
{
static buffered_object< ref_ptr<FBOExtensions> > 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;

View File

@ -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)