Restructred the enabling of vertex array object support to allow one to set enable the default via osg::State.

Added OSG_VERTEX_BUFFER_HINT env var to osg::DisplaySettings with VERTEX_BUFFER_OBJECT/VBO, VERTEX_ARRAY_OBJECT/VAO and NO_PREFERENCE to allow one to foce on VBO or VAO usage.

Restructred BufferObject assigned in osg::Geometry

Added
This commit is contained in:
Robert Osfield
2016-08-12 18:44:38 +01:00
parent d8fdf33be5
commit 94891778c4
10 changed files with 175 additions and 116 deletions

View File

@@ -70,7 +70,7 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
if ((copyop.getCopyFlags() & osg::CopyOp::DEEP_COPY_ARRAYS) || (copyop.getCopyFlags() & osg::CopyOp::DEEP_COPY_PRIMITIVES))
{
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
// copying of arrays doesn't set up buffer objects so we'll need to force
// Geometry to assign these, we'll do this by changing the cached value to false then re-enabling.
@@ -114,7 +114,7 @@ void Geometry::setVertexArray(Array* array)
dirtyDisplayList();
dirtyBound();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setNormalArray(Array* array, osg::Array::Binding binding)
@@ -125,7 +125,7 @@ void Geometry::setNormalArray(Array* array, osg::Array::Binding binding)
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setColorArray(Array* array, osg::Array::Binding binding)
@@ -136,7 +136,7 @@ void Geometry::setColorArray(Array* array, osg::Array::Binding binding)
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setSecondaryColorArray(Array* array, osg::Array::Binding binding)
@@ -147,7 +147,7 @@ void Geometry::setSecondaryColorArray(Array* array, osg::Array::Binding binding)
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setFogCoordArray(Array* array, osg::Array::Binding binding)
@@ -158,7 +158,7 @@ void Geometry::setFogCoordArray(Array* array, osg::Array::Binding binding)
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
@@ -178,7 +178,7 @@ void Geometry::setTexCoordArray(unsigned int index,Array* array, osg::Array::Bin
dirtyDisplayList();
if (_useVertexBufferObjects && array)
if (/*_useVertexBufferObjects && */array)
{
addVertexBufferObjectIfRequired(array);
}
@@ -202,7 +202,7 @@ void Geometry::setTexCoordArrayList(const ArrayList& arrayList)
dirtyDisplayList();
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
for(ArrayList::iterator itr = _texCoordList.begin();
itr != _texCoordList.end();
@@ -224,7 +224,7 @@ void Geometry::setVertexAttribArray(unsigned int index, Array* array, osg::Array
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
if (/*_useVertexBufferObjects && */array) addVertexBufferObjectIfRequired(array);
}
Array *Geometry::getVertexAttribArray(unsigned int index)
@@ -245,7 +245,7 @@ void Geometry::setVertexAttribArrayList(const ArrayList& arrayList)
dirtyDisplayList();
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
for(ArrayList::iterator itr = _vertexAttribList.begin();
itr != _vertexAttribList.end();
@@ -261,7 +261,7 @@ bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset)
{
if (primitiveset)
{
if (_useVertexBufferObjects) addElementBufferObjectIfRequired(primitiveset);
/*if (_useVertexBufferObjects)*/ addElementBufferObjectIfRequired(primitiveset);
_primitives.push_back(primitiveset);
dirtyDisplayList();
@@ -277,7 +277,7 @@ bool Geometry::setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
if (i<_primitives.size() && primitiveset)
{
if (_useVertexBufferObjects) addElementBufferObjectIfRequired(primitiveset);
/*if (_useVertexBufferObjects)*/ addElementBufferObjectIfRequired(primitiveset);
_primitives[i] = primitiveset;
dirtyDisplayList();
@@ -293,7 +293,7 @@ bool Geometry::insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
if (primitiveset)
{
if (_useVertexBufferObjects) addElementBufferObjectIfRequired(primitiveset);
/*if (_useVertexBufferObjects)*/ addElementBufferObjectIfRequired(primitiveset);
if (i<_primitives.size())
{
@@ -315,7 +315,7 @@ bool Geometry::insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
void Geometry::setPrimitiveSetList(const PrimitiveSetList& primitives)
{
_primitives = primitives;
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
for (unsigned int primitiveSetIndex=0;primitiveSetIndex<_primitives.size();++primitiveSetIndex)
{
@@ -451,7 +451,7 @@ bool Geometry::getDrawElementsList(DrawElementsList& drawElementsList) const
void Geometry::addVertexBufferObjectIfRequired(osg::Array* array)
{
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
if (!array->getVertexBufferObject())
{
@@ -462,7 +462,7 @@ void Geometry::addVertexBufferObjectIfRequired(osg::Array* array)
void Geometry::addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet)
{
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
osg::DrawElements* drawElements = primitiveSet->getDrawElements();
if (drawElements && !drawElements->getElementBufferObject())
@@ -525,7 +525,7 @@ void Geometry::setUseVertexBufferObjects(bool flag)
typedef std::vector<osg::VertexBufferObject*> VertexBufferObjectList;
typedef std::vector<osg::ElementBufferObject*> ElementBufferObjectList;
if (_useVertexBufferObjects)
/*if (_useVertexBufferObjects)*/
{
if (!arrayList.empty())
{
@@ -580,6 +580,7 @@ void Geometry::setUseVertexBufferObjects(bool flag)
}
}
}
/*
else
{
for(ArrayList::iterator vitr = arrayList.begin();
@@ -598,6 +599,7 @@ void Geometry::setUseVertexBufferObjects(bool flag)
if (elements->getElementBufferObject()) elements->setElementBufferObject(0);
}
}
*/
}
void Geometry::dirtyGLObjects()
@@ -636,7 +638,14 @@ void Geometry::releaseGLObjects(State* state) const
{
Drawable::releaseGLObjects(state);
if (state) _vertexArrayStateList[state->getContextID()];
if (state)
{
if (_vertexArrayStateList[state->getContextID()].valid())
{
_vertexArrayStateList[state->getContextID()]->release();
_vertexArrayStateList[state->getContextID()] = 0;
}
}
else _vertexArrayStateList.clear();
ArrayList arrays;
@@ -665,13 +674,11 @@ void Geometry::releaseGLObjects(State* state) const
VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const
{
OSG_NOTICE<<"Creating new osg::VertexArrayState"<<std::endl;
State& state = *renderInfo.getState();
const DisplaySettings* ds = state.getDisplaySettings() ? state.getDisplaySettings() : osg::DisplaySettings::instance();
VertexArrayState* vas = 0;
VertexArrayState* vas = new osg::VertexArrayState(&state);
_vertexArrayStateList[state.getContextID()] = vas = new osg::VertexArrayState(&state);
// OSG_NOTICE<<"Creating new osg::VertexArrayState "<< vas<<std::endl;
if (_vertexArray.valid()) vas->assignVertexArrayDispatcher();
if (_colorArray.valid()) vas->assignColorArrayDispatcher();
@@ -682,15 +689,15 @@ VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo, bool
if (!_texCoordList.empty()) vas->assignTexCoordArrayDispatcher(_texCoordList.size());
if (!_vertexAttribList.empty()) vas->assignVertexAttribArrayDispatcher(_vertexAttribList.size());
if (usingVBOs && ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT)
if (state.useVertexArrayObject(_useVertexArrayObject))
{
OSG_NOTICE<<" Setup VertexArrayState to use VAO"<<std::endl;
// OSG_NOTICE<<" Setup VertexArrayState to use VAO "<<vas<<std::endl;
vas->generateVertexArrayObject();
}
else
{
OSG_NOTICE<<" Setup VertexArrayState to without using VAO"<<std::endl;
// OSG_NOTICE<<" Setup VertexArrayState to without using VAO "<<vas<<std::endl;
}
return vas;
@@ -699,10 +706,7 @@ VertexArrayState* Geometry::createVertexArrayState(RenderInfo& renderInfo, bool
void Geometry::compileGLObjects(RenderInfo& renderInfo) const
{
State& state = *renderInfo.getState();
bool useVertexArrays = _supportsVertexBufferObjects &&
_useVertexBufferObjects &&
renderInfo.getState()->isVertexBufferObjectSupported();
if (useVertexArrays)
if (renderInfo.getState()->useVertexBufferObject(_supportsVertexBufferObjects && _useVertexBufferObjects))
{
unsigned int contextID = state.getContextID();
GLExtensions* extensions = state.get<GLExtensions>();
@@ -760,7 +764,7 @@ void Geometry::compileGLObjects(RenderInfo& renderInfo) const
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,0);
extensions->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB,0);
if (state.useVertexArrayObject() && !bufferObjects.empty())
if (state.useVertexArrayObject(_useVertexArrayObject) && !bufferObjects.empty())
{
VertexArrayState* vas = 0;
@@ -806,9 +810,7 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
drawPrimitivesImplementation(renderInfo);
bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject();
unsigned int contextID = renderInfo.getContextID();
if (!useVertexArrayObject || _vertexArrayStateList[contextID]->getRequiresSetArrays())
if (!state.useVertexArrayObject(_useVertexArrayObject) || state.getCurrentVertexArrayState()->getRequiresSetArrays())
{
// unbind the VBO's if any are used.
state.unbindVertexBufferObject();
@@ -846,11 +848,9 @@ void Geometry::drawVertexArraysImplementation(RenderInfo& renderInfo) const
arrayDispatchers.dispatch(osg::Array::BIND_OVERALL,0);
bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject();
unsigned int contextID = renderInfo.getContextID();
if (useVertexArrayObject)
if (state.useVertexArrayObject(_useVertexArrayObject))
{
if (!_vertexArrayStateList[contextID]->getRequiresSetArrays()) return;
if (!state.getCurrentVertexArrayState()->getRequiresSetArrays()) return;
}
state.lazyDisablingOfVertexAttributes();
@@ -909,7 +909,7 @@ void Geometry::drawPrimitivesImplementation(RenderInfo& renderInfo) const
{
State& state = *renderInfo.getState();
ArrayDispatchers& arrayDispatchers = state.getArrayDispatchers();
bool usingVertexBufferObjects = _useVertexBufferObjects && state.isVertexBufferObjectSupported();
bool usingVertexBufferObjects = state.useVertexBufferObject(_supportsVertexBufferObjects && _useVertexBufferObjects);
bool bindPerPrimitiveSetActive = arrayDispatchers.active(osg::Array::BIND_PER_PRIMITIVE_SET);
for(unsigned int primitiveSetNum=0; primitiveSetNum!=_primitives.size(); ++primitiveSetNum)