From 64341cfb72198873e963a33fd1ad46a2e3eaafd8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 6 Mar 2018 09:49:02 +0000 Subject: [PATCH] Added State::glDrawBuffer/glReadBuffer() method to implement lazy state updating for glDrawBuffer and glReadBuffer --- include/osg/State | 11 +++++++++++ src/osg/State.cpp | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/osg/State b/include/osg/State index 2af764bbc..c2132bdad 100644 --- a/include/osg/State +++ b/include/osg/State @@ -303,6 +303,14 @@ class OSG_EXPORT State : public Referenced /** Apply any shader composed state.*/ void applyShaderComposition(); + + void glDrawBuffer(GLenum buffer); + GLenum getDrawBuffer() const { return _drawBuffer; } + + void glReadBuffer(GLenum buffer); + GLenum getReadBuffer() const { return _readBuffer; } + + /** Set whether a particular OpenGL mode is valid in the current graphics context. * Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/ inline void setModeValidity(StateAttribute::GLMode mode,bool valid) @@ -1079,6 +1087,9 @@ class OSG_EXPORT State : public Referenced ref_ptr _frameStamp; + GLenum _drawBuffer; + GLenum _readBuffer; + ref_ptr _identity; ref_ptr _initialViewMatrix; ref_ptr _projection; diff --git a/src/osg/State.cpp b/src/osg/State.cpp index b4f74b2da..ac20854e0 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -51,6 +51,9 @@ State::State(): _shaderComposer = new ShaderComposer; _currentShaderCompositionProgram = 0L; + _drawBuffer = GL_NONE; + _readBuffer = GL_NONE; + _identity = new osg::RefMatrix(); // default RefMatrix constructs to identity. _initialViewMatrix = _identity; _projection = _identity; @@ -434,6 +437,28 @@ void State::reset() } +void State::glDrawBuffer(GLenum buffer) +{ + if (_drawBuffer!=buffer) + { + #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE) + glDrawBuffer(buffer); + #endif + _drawBuffer=buffer; + } +} + +void State::glReadBuffer(GLenum buffer) +{ + if (_readBuffer!=buffer) + { + #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) && !defined(OSG_GLES3_AVAILABLE) + glReadBuffer(buffer); + #endif + _readBuffer=buffer; + } +} + void State::setInitialViewMatrix(const osg::RefMatrix* matrix) { if (matrix) _initialViewMatrix = matrix;