diff --git a/include/osg/VertexArrayState b/include/osg/VertexArrayState index 093323ee7..335d5044e 100644 --- a/include/osg/VertexArrayState +++ b/include/osg/VertexArrayState @@ -147,7 +147,8 @@ public: void releaseGLObjects(); - + void setRequiresSetArrays(bool flag) { _requiresSetArrays = flag; } + bool getRequiresSetArrays() const { return _requiresSetArrays; } public: @@ -174,6 +175,8 @@ public: GLBufferObject* _currentVBO; GLBufferObject* _currentEBO; + + bool _requiresSetArrays; }; diff --git a/src/osg/Drawable.cpp b/src/osg/Drawable.cpp index 36aac7d73..c13fd5c21 100644 --- a/src/osg/Drawable.cpp +++ b/src/osg/Drawable.cpp @@ -635,6 +635,8 @@ void Drawable::draw(RenderInfo& renderInfo) const drawInner(renderInfo); + vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC); + return; } #endif diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index c05d358a0..51b67fac4 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -1180,6 +1180,14 @@ GLExtensions::GLExtensions(unsigned int in_contextID): glMaxTextureUnits = 0; glMaxTextureCoords = 0; } + + #if !defined(OSG_GL_FIXED_FUNCTION_AVAILABLE) + _useVertexAttributeAliasing = true; + #else + _useVertexAttributeAliasing = false; + #endif + + } diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 1b708484f..309c20c1a 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -800,9 +800,15 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const drawPrimitivesImplementation(renderInfo); - // unbind the VBO's if any are used. - state.unbindVertexBufferObject(); - state.unbindElementBufferObject(); + const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); + bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + unsigned int contextID = renderInfo.getContextID(); + if (!useVertexArrayObject || _vertexArrayStateList[contextID]->getRequiresSetArrays()) + { + // unbind the VBO's if any are used. + state.unbindVertexBufferObject(); + state.unbindElementBufferObject(); + } if (checkForGLErrors) state.checkGLErrors("end of Geometry::drawImplementation()."); } @@ -818,11 +824,6 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const arrayDispatchers.reset(); arrayDispatchers.setUseVertexAttribAlias(state.getUseVertexAttributeAliasing()); - arrayDispatchers.activateNormalArray(_normalArray.get()); - arrayDispatchers.activateColorArray(_colorArray.get()); - arrayDispatchers.activateSecondaryColorArray(_secondaryColorArray.get()); - arrayDispatchers.activateFogCoordArray(_fogCoordArray.get()); - if (handleVertexAttributes) { for(unsigned int unit=0;unit<_vertexAttribList.size();++unit) @@ -831,9 +832,23 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const } } + arrayDispatchers.activateNormalArray(_normalArray.get()); + arrayDispatchers.activateColorArray(_colorArray.get()); + arrayDispatchers.activateSecondaryColorArray(_secondaryColorArray.get()); + arrayDispatchers.activateFogCoordArray(_fogCoordArray.get()); + // dispatch any attributes that are bound overall arrayDispatchers.dispatch(osg::Array::BIND_OVERALL,0); + + const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance(); + bool useVertexArrayObject = _useVertexBufferObjects && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT); + unsigned int contextID = renderInfo.getContextID(); + if (useVertexArrayObject) + { + if (!_vertexArrayStateList[contextID]->getRequiresSetArrays()) return; + } + state.lazyDisablingOfVertexAttributes(); // set up arrays diff --git a/src/osg/VertexArrayState.cpp b/src/osg/VertexArrayState.cpp index 52cf3be1d..e7adc9462 100644 --- a/src/osg/VertexArrayState.cpp +++ b/src/osg/VertexArrayState.cpp @@ -341,7 +341,8 @@ VertexArrayState::VertexArrayState(osg::GLExtensions* ext): _ext(ext), _vertexArrayObject(0), _currentVBO(0), - _currentEBO(0) + _currentEBO(0), + _requiresSetArrays(true) { }