From 8febae1546330ef4682e46e5b453e3eb1dc31780 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 1 Sep 2016 14:38:16 +0100 Subject: [PATCH] Fixed VertexArrayState::bind*BufferObject(..) methods so they correctly handle dirtied buffer objects --- include/osg/VertexArrayState | 33 ++++++++++++++++++++++++--------- src/osg/VertexArrayState.cpp | 17 +++++++++-------- 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/osg/VertexArrayState b/include/osg/VertexArrayState index ce1924e1d..fd068ca0d 100644 --- a/include/osg/VertexArrayState +++ b/include/osg/VertexArrayState @@ -60,10 +60,16 @@ public: inline void bindVertexBufferObject(osg::GLBufferObject* vbo) { - if (vbo == _currentVBO) return; - if (vbo->isDirty()) vbo->compileBuffer(); - else vbo->bindBuffer(); - _currentVBO = vbo; + if (vbo->isDirty()) + { + vbo->compileBuffer(); + _currentVBO = vbo; + } + else if (vbo != _currentVBO) + { + vbo->bindBuffer(); + _currentVBO = vbo; + } } inline void unbindVertexBufferObject() @@ -79,10 +85,16 @@ public: inline void bindElementBufferObject(osg::GLBufferObject* ebo) { - if (ebo == _currentEBO) return; - if (ebo->isDirty()) ebo->compileBuffer(); - else ebo->bindBuffer(); - _currentEBO = ebo; + if (ebo->isDirty()) + { + ebo->compileBuffer(); + _currentEBO = ebo; + } + else if (ebo != _currentEBO) + { + ebo->bindBuffer(); + _currentEBO = ebo; + } } inline void unbindElementBufferObject() @@ -104,7 +116,8 @@ public: void assignTexCoordArrayDispatcher(unsigned int numUnits); void assignVertexAttribArrayDispatcher(unsigned int numUnits); - inline bool isVertexBufferObjectSupported() const { return true; } + inline void setVertexBufferObjectSupported(bool flag) { _isVertexBufferObjectSupported = flag; } + inline bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupported; } void setArray(ArrayDispatch* vad, osg::State& state, const osg::Array* new_array); void setArray(ArrayDispatch* vad, osg::State& state, GLint size, GLenum type, GLsizei stride, const GLvoid *ptr, GLboolean normalized); @@ -173,6 +186,8 @@ public: osg::State* _state; osg::ref_ptr _ext; + bool _isVertexBufferObjectSupported; + GLuint _vertexArrayObject; diff --git a/src/osg/VertexArrayState.cpp b/src/osg/VertexArrayState.cpp index 99861e4ef..d6df6d986 100644 --- a/src/osg/VertexArrayState.cpp +++ b/src/osg/VertexArrayState.cpp @@ -127,7 +127,7 @@ struct VertexArrayDispatch : public VertexArrayState::ArrayDispatch virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" VertexArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } @@ -146,7 +146,7 @@ struct VertexArrayDispatch : public VertexArrayState::ArrayDispatch virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" VertexArrayDispatch::dispatch("<getNumElements()<<", vbo"<getNumElements()<<", vbo"<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } @@ -186,7 +186,7 @@ struct ColorArrayDispatch : public VertexArrayState::ArrayDispatch virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" ColorArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); @@ -200,7 +200,7 @@ struct ColorArrayDispatch : public VertexArrayState::ArrayDispatch virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" ColorArrayDispatch::dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getDataSize(), new_array->getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } @@ -234,7 +234,7 @@ struct NormalArrayDispatch : public VertexArrayState::ArrayDispatch virtual void enable_and_dispatch(osg::State&, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" NormalArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } @@ -253,7 +253,7 @@ struct NormalArrayDispatch : public VertexArrayState::ArrayDispatch virtual void dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" NormalArrayDispatch::dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getDataType(), 0, (const GLvoid *)(vbo->getOffset(new_array->getBufferIndex()))); } @@ -378,7 +378,7 @@ struct TexCoordArrayDispatch : public VertexArrayState::ArrayDispatch virtual void enable_and_dispatch(osg::State& state, const osg::Array* new_array, const osg::GLBufferObject* vbo) { - VAS_NOTICE<<" TexCoordArrayDispatch::enable_and_dispatch("<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getNumElements()<<", vbo="<getNumElements()<<", vbo="<