From 75fd039dba9cc049e8a37b2c8dfa84ea8a3b1002 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 24 Jul 2013 13:02:32 +0000 Subject: [PATCH] Added GL2Extensions::isDrawBuffersSupported() and usage of this in FrameBufferObject.cpp to prevent crash under GLES2 when users attempt to use MRT when it's not supported --- include/osg/GL2Extensions | 2 ++ src/osg/FrameBufferObject.cpp | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/include/osg/GL2Extensions b/include/osg/GL2Extensions index 39d2c3545..0c4a1a699 100644 --- a/include/osg/GL2Extensions +++ b/include/osg/GL2Extensions @@ -530,6 +530,8 @@ class OSG_EXPORT GL2Extensions : public osg::Referenced void setShaderAtomicCounterSupported(bool flag) { _isShaderAtomicCountersSupported = flag; } bool isShaderAtomicCounterSupported() const {return _isShaderAtomicCountersSupported; } + bool isDrawBuffersSupported() const { return _glDrawBuffers!=0; } + /** Function to call to get the extension of a specified context. * If the Exentsion object for that context has not yet been created then * and the 'createIfNotInitalized' flag been set to false then returns NULL. diff --git a/src/osg/FrameBufferObject.cpp b/src/osg/FrameBufferObject.cpp index 68c755a8c..ec570d14e 100644 --- a/src/osg/FrameBufferObject.cpp +++ b/src/osg/FrameBufferObject.cpp @@ -916,10 +916,14 @@ void FrameBufferObject::apply(State &state, BindTarget target) const if (_drawBuffers.size() > 0) { GL2Extensions *gl2e = GL2Extensions::Get(state.getContextID(), true ); - if (gl2e) + if (gl2e && gl2e->isDrawBuffersSupported()) { gl2e->glDrawBuffers(_drawBuffers.size(), &(_drawBuffers[0])); } + else + { + OSG_WARN <<"Warning: FrameBufferObject: could not set draw buffers, glDrawBuffers is not supported!" << std::endl; + } } if (dirtyAttachmentList) @@ -939,7 +943,7 @@ void FrameBufferObject::apply(State &state, BindTarget target) const { OSG_WARN << "Warning: FrameBufferObject: could not attach PACKED_DEPTH_STENCIL_BUFFER, " - "EXT_packed_depth_stencil is not supported !" << std::endl; + "EXT_packed_depth_stencil is not supported!" << std::endl; } break;