From b5a3e0d532cc3ca93552e58f27f37065fc037ae9 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sun, 31 Dec 2017 12:35:44 +0000 Subject: [PATCH] Fixed handling of reassignment of ArrayDispatch when vertex aliasing is toggled --- include/osg/VertexArrayState | 4 +++ src/osg/VertexArrayState.cpp | 50 ++++++++++++++++++++++++------------ 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/osg/VertexArrayState b/include/osg/VertexArrayState index 6673d40cb..5b66db4a9 100644 --- a/include/osg/VertexArrayState +++ b/include/osg/VertexArrayState @@ -34,6 +34,8 @@ class OSG_EXPORT VertexArrayState : public osg::Referenced modifiedCount(0xffffffff), active(false) {} + virtual bool isVertexAttribDispatch() const { return false; } + virtual const char* className() const = 0; // { return "ArrayDispatch"; } virtual void enable_and_dispatch(osg::State& /*state*/, const osg::Array* /*new_array*/) {} // = 0; @@ -108,6 +110,8 @@ class OSG_EXPORT VertexArrayState : public osg::Referenced void resetBufferObjectPointers() { _currentVBO = 0; _currentEBO = 0; } + bool correctArrayDispatchAssigned(const ArrayDispatch* ad); + void assignAllDispatchers(); void assignVertexArrayDispatcher(); diff --git a/src/osg/VertexArrayState.cpp b/src/osg/VertexArrayState.cpp index f39391a97..364eb4f80 100644 --- a/src/osg/VertexArrayState.cpp +++ b/src/osg/VertexArrayState.cpp @@ -450,6 +450,8 @@ struct VertexAttribArrayDispatch : public VertexArrayState::ArrayDispatch virtual const char* className() const { return "VertexAttribArrayDispatch"; } + virtual bool isVertexAttribDispatch() const { return true; } + inline void callVertexAttribPointer(GLExtensions* ext, const osg::Array* new_array, const GLvoid * ptr) { if (new_array->getPreserveDataType()) @@ -544,9 +546,18 @@ void VertexArrayState::deleteVertexArrayObject() } } +bool VertexArrayState::correctArrayDispatchAssigned(const ArrayDispatch* ad) +{ +#ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE + return ad && (_state->getUseVertexAttributeAliasing()==ad->isVertexAttribDispatch()); +#else + return ad!=0; +#endif + } + void VertexArrayState::assignVertexArrayDispatcher() { - if (_vertexArray.valid()) return; + if (correctArrayDispatchAssigned(_vertexArray.get())) return; #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (!_state->getUseVertexAttributeAliasing()) @@ -556,6 +567,7 @@ void VertexArrayState::assignVertexArrayDispatcher() else #endif { + if (_vertexArray.valid()) return; VAS_NOTICE<<"VertexArrayState::assignNormalArrayDispatcher() _state->getVertexAlias()._location="<<_state->getVertexAlias()._location<getVertexAlias()._location); } @@ -563,7 +575,7 @@ void VertexArrayState::assignVertexArrayDispatcher() void VertexArrayState::assignNormalArrayDispatcher() { - if (_normalArray.valid()) return; + if (correctArrayDispatchAssigned(_normalArray.get())) return; #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (!_state->getUseVertexAttributeAliasing()) @@ -580,7 +592,7 @@ void VertexArrayState::assignNormalArrayDispatcher() void VertexArrayState::assignColorArrayDispatcher() { - if (_colorArray.valid()) return; + if (correctArrayDispatchAssigned(_colorArray.get())) return; #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (!_state->getUseVertexAttributeAliasing()) @@ -597,7 +609,7 @@ void VertexArrayState::assignColorArrayDispatcher() void VertexArrayState::assignSecondaryColorArrayDispatcher() { - if (_secondaryColorArray.valid()) return; + if (correctArrayDispatchAssigned(_secondaryColorArray.get())) return; #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (!_state->getUseVertexAttributeAliasing()) @@ -613,7 +625,7 @@ void VertexArrayState::assignSecondaryColorArrayDispatcher() void VertexArrayState::assignFogCoordArrayDispatcher() { - if (_fogCoordArray.valid()) return; + if (correctArrayDispatchAssigned(_fogCoordArray.get())) return; #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE if (!_state->getUseVertexAttributeAliasing()) @@ -629,30 +641,34 @@ void VertexArrayState::assignFogCoordArrayDispatcher() void VertexArrayState::assignTexCoordArrayDispatcher(unsigned int numUnits) { + _texCoordArrays.resize(numUnits); + + for(unsigned int i=0; i<_texCoordArrays.size(); ++i) + { + if (correctArrayDispatchAssigned(_texCoordArrays[i].get())) continue; + #ifdef OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE - if (!_state->getUseVertexAttributeAliasing()) - { - for(unsigned int i=_texCoordArrays.size(); igetUseVertexAttributeAliasing()) { - _texCoordArrays.push_back( new TexCoordArrayDispatch(i) ); + _texCoordArrays[i] = new TexCoordArrayDispatch(i); } - } - else + else #endif - { - for(unsigned int i=_texCoordArrays.size(); igetTexCoordAliasList()[i]._location="<<_state->getTexCoordAliasList()[i]._location<getTexCoordAliasList()[i]._location) ); + _texCoordArrays[i] = new VertexAttribArrayDispatch(_state->getTexCoordAliasList()[i]._location); } } } void VertexArrayState::assignVertexAttribArrayDispatcher(unsigned int numUnits) { - for(unsigned int i=_vertexAttribArrays.size(); i