Added lazy setting of arrays for osg::Geometry using vertex_array_object

This commit is contained in:
Robert Osfield
2016-08-02 12:28:05 +01:00
parent 4b4cd13d31
commit 078598872f
5 changed files with 39 additions and 10 deletions

View File

@@ -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;
};

View File

@@ -635,6 +635,8 @@ void Drawable::draw(RenderInfo& renderInfo) const
drawInner(renderInfo);
vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC);
return;
}
#endif

View File

@@ -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
}

View File

@@ -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

View File

@@ -341,7 +341,8 @@ VertexArrayState::VertexArrayState(osg::GLExtensions* ext):
_ext(ext),
_vertexArrayObject(0),
_currentVBO(0),
_currentEBO(0)
_currentEBO(0),
_requiresSetArrays(true)
{
}