From 164981f7a3d53ceaaec649ff1ffdd8f33446a0de Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 16 Aug 2016 10:01:38 +0100 Subject: [PATCH] Replaced osg::State:set*Pointer() calls with VertexArrayState::set*Array() calls --- src/osg/Geometry.cpp | 31 +++++++++++-------------------- src/osg/VertexArrayState.cpp | 17 ++++++++++++----- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 58960df3c..654fb6b49 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -823,6 +823,7 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const { State& state = *renderInfo.getState(); + VertexArrayState* vas = state.getCurrentVertexArrayState(); bool handleVertexAttributes = !_vertexAttribList.empty(); @@ -850,33 +851,33 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const if (state.useVertexArrayObject(_useVertexArrayObject)) { - if (!state.getCurrentVertexArrayState()->getRequiresSetArrays()) return; + if (!vas->getRequiresSetArrays()) return; } - state.lazyDisablingOfVertexAttributes(); + vas->lazyDisablingOfVertexAttributes(); // set up arrays if( _vertexArray.valid() ) - state.setVertexPointer(_vertexArray.get()); + vas->setVertexArray(state, _vertexArray.get()); if (_normalArray.valid() && _normalArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setNormalPointer(_normalArray.get()); + vas->setNormalArray(state, _normalArray.get()); if (_colorArray.valid() && _colorArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setColorPointer(_colorArray.get()); + vas->setColorArray(state, _colorArray.get()); if (_secondaryColorArray.valid() && _secondaryColorArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setSecondaryColorPointer(_secondaryColorArray.get()); + vas->setSecondaryColorArray(state, _secondaryColorArray.get()); if (_fogCoordArray.valid() && _fogCoordArray->getBinding()==osg::Array::BIND_PER_VERTEX) - state.setFogCoordPointer(_fogCoordArray.get()); + vas->setFogCoordArray(state, _fogCoordArray.get()); for(unsigned int unit=0;unit<_texCoordList.size();++unit) { const Array* array = _texCoordList[unit].get(); if (array) { - state.setTexCoordPointer(unit,array); + vas->setTexCoordArray(state, unit,array); } } @@ -887,22 +888,12 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const const Array* array = _vertexAttribList[index].get(); if (array && array->getBinding()==osg::Array::BIND_PER_VERTEX) { - if (array->getPreserveDataType()) - { - GLenum dataType = array->getDataType(); - if (dataType==GL_FLOAT) state.setVertexAttribPointer( index, array ); - else if (dataType==GL_DOUBLE) state.setVertexAttribLPointer( index, array ); - else state.setVertexAttribIPointer( index, array ); - } - else - { - state.setVertexAttribPointer( index, array ); - } + vas->setVertexAttribArray(state, index, array); } } } - state.applyDisablingOfVertexAttributes(); + vas->applyDisablingOfVertexAttributes(state); } void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const diff --git a/src/osg/VertexArrayState.cpp b/src/osg/VertexArrayState.cpp index 075127248..6fa0a97e7 100644 --- a/src/osg/VertexArrayState.cpp +++ b/src/osg/VertexArrayState.cpp @@ -419,12 +419,19 @@ struct VertexAttribArrayDispatch : public VertexArrayState::ArrayDispatch inline void callVertexAttribPointer(GLExtensions* ext, const osg::Array* new_array, const GLvoid * ptr) { - if (new_array->getDataType()==GL_FLOAT) - ext->glVertexAttribPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), new_array->getNormalize(), 0, ptr); - else if (array->getDataType()==GL_DOUBLE) - ext->glVertexAttribLPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), 0, ptr); + if (array->getPreserveDataType()) + { + if (new_array->getDataType()==GL_FLOAT) + ext->glVertexAttribPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), new_array->getNormalize(), 0, ptr); + else if (array->getDataType()==GL_DOUBLE) + ext->glVertexAttribLPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), 0, ptr); + else + ext->glVertexAttribIPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), 0, ptr); + } else - ext->glVertexAttribIPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), 0, ptr); + { + ext->glVertexAttribPointer(static_cast(unit), new_array->getDataSize(), new_array->getDataType(), new_array->getNormalize(), 0, ptr); + } } virtual void enable_and_dispatch(osg::State& state, const osg::Array* new_array)