From 4b4cd13d310af3c3287cae1c5d2f5b717d74ad98 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 23 Jul 2016 16:33:39 +0100 Subject: [PATCH] Implemented lighter weight setting of the CurrentVertexArrayState and introduced GlobalVertexArrayState. --- include/osg/State | 15 +++++++++++++-- include/osg/VertexArrayState | 2 +- src/osg/Drawable.cpp | 8 +------- src/osg/State.cpp | 8 ++++---- src/osg/VertexArrayState.cpp | 2 ++ 5 files changed, 21 insertions(+), 14 deletions(-) diff --git a/include/osg/State b/include/osg/State index ae8bc0cf0..c530562be 100644 --- a/include/osg/State +++ b/include/osg/State @@ -500,12 +500,22 @@ class OSG_EXPORT State : public Referenced void dirtyAllAttributes(); + struct SetCurrentVertexArrayStateProxy + { + SetCurrentVertexArrayStateProxy(osg::State& state, VertexArrayState* vas):_state(state) { _state.setCurrentVertexArrayState(vas); } + ~SetCurrentVertexArrayStateProxy() { _state.setCurrentToGloabalVertexArrayState(); } + osg::State& _state; + }; + /** Set the CurrentVetexArrayState object that take which vertex arrays are bound.*/ void setCurrentVertexArrayState(VertexArrayState* vas) { _currentVertexArrayState = vas; } /** Get the CurrentVetexArrayState object that take which vertex arrays are bound.*/ - VertexArrayState* getCurrentVertexArrayState() const { return _currentVertexArrayState.get(); } + VertexArrayState* getCurrentVertexArrayState() const { return _currentVertexArrayState; } + + /** Set the getCurrentVertexArrayState to the GloabalVertexArrayState.*/ + void setCurrentToGloabalVertexArrayState() { _currentVertexArrayState = _globalVertexArrayState.get(); } /** disable the vertex, normal, color, tex coords, secondary color, fog coord and index arrays.*/ @@ -1780,7 +1790,8 @@ class OSG_EXPORT State : public Referenced GraphicsContext* _graphicsContext; unsigned int _contextID; - osg::ref_ptr _currentVertexArrayState; + osg::ref_ptr _globalVertexArrayState; + VertexArrayState* _currentVertexArrayState; bool _shaderCompositionEnabled; bool _shaderCompositionDirty; diff --git a/include/osg/VertexArrayState b/include/osg/VertexArrayState index 97e35bcd8..093323ee7 100644 --- a/include/osg/VertexArrayState +++ b/include/osg/VertexArrayState @@ -153,7 +153,7 @@ public: public: - osg::GLBufferObject* getGLBufferObject(osg::Array* array); + // osg::GLBufferObject* getGLBufferObject(osg::Array* array); osg::ref_ptr _ext; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 41abb15d4..36aac7d73 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -629,18 +629,12 @@ void Drawable::draw(RenderInfo& renderInfo) const _vertexArrayStateList[contextID] = vas = setUpVertexArrayState(renderInfo, true); } - //state.pushVAO(localVAO); - osg::ref_ptr previous_vas = state.getCurrentVertexArrayState(); - - state.setCurrentVertexArrayState(vas); + State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas); vas->bindVertexArrayObject(); drawInner(renderInfo); - // state.popVAO(); - state.setCurrentVertexArrayState(previous_vas); - return; } #endif diff --git a/src/osg/State.cpp b/src/osg/State.cpp index b625cee99..8fcaa8764 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -140,8 +140,7 @@ State::State(): _gpuTimestamp = 0; _timestampBits = 0; - - + _currentVertexArrayState = 0; } State::~State() @@ -986,8 +985,9 @@ void State::initializeExtensionProcs() GLExtensions::Set(_contextID, _glExtensions.get()); #ifdef USE_VERTEXARRAYSTATE - _currentVertexArrayState = new VertexArrayState(_glExtensions.get()); - _currentVertexArrayState->assignAllDispatchers(); + _globalVertexArrayState = new VertexArrayState(_glExtensions.get()); + _globalVertexArrayState->assignAllDispatchers(); + setCurrentToGloabalVertexArrayState(); #endif setGLExtensionFuncPtr(_glClientActiveTexture,"glClientActiveTexture","glClientActiveTextureARB"); diff --git a/src/osg/VertexArrayState.cpp b/src/osg/VertexArrayState.cpp index eae4109cb..52cf3be1d 100644 --- a/src/osg/VertexArrayState.cpp +++ b/src/osg/VertexArrayState.cpp @@ -345,6 +345,7 @@ VertexArrayState::VertexArrayState(osg::GLExtensions* ext): { } +#if 0 osg::GLBufferObject* VertexArrayState::getGLBufferObject(osg::Array* array) { if (_ext->isBufferObjectSupported && array->getBufferObject()) @@ -356,6 +357,7 @@ osg::GLBufferObject* VertexArrayState::getGLBufferObject(osg::Array* array) return 0; } } +#endif void VertexArrayState::generateVretexArrayObject() {