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:
@@ -299,15 +299,15 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
int getNvOptimusEnablement() const;
|
||||
|
||||
|
||||
enum GeometryImplementation
|
||||
enum VertexBufferHint
|
||||
{
|
||||
OLD_GEOMETRY_IMPLEMENTATION,
|
||||
NEW_GEOMETRY_IMPLEMENTATION,
|
||||
NO_PREFERENCE,
|
||||
VERTEX_BUFFER_OBJECT,
|
||||
VERTEX_ARRAY_OBJECT
|
||||
};
|
||||
|
||||
void setGeometryImplementation(GeometryImplementation gi) { _geometryImplementation = gi; }
|
||||
GeometryImplementation getGeometryImplementation() const { return _geometryImplementation; }
|
||||
void setVertexBufferHint(VertexBufferHint gi) { _vertexBufferHint = gi; }
|
||||
VertexBufferHint getVertexBufferHint() const { return _vertexBufferHint; }
|
||||
|
||||
|
||||
void setKeystoneHint(bool enabled) { _keystoneHint = enabled; }
|
||||
@@ -399,7 +399,7 @@ class OSG_EXPORT DisplaySettings : public osg::Referenced
|
||||
SwapMethod _swapMethod;
|
||||
unsigned int _syncSwapBuffers;
|
||||
|
||||
GeometryImplementation _geometryImplementation;
|
||||
VertexBufferHint _vertexBufferHint;
|
||||
|
||||
bool _keystoneHint;
|
||||
FileNames _keystoneFileNames;
|
||||
|
||||
@@ -55,6 +55,8 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define INLINE_DRAWABLE_DRAW
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
@@ -256,7 +258,11 @@ class OSG_EXPORT Drawable : public Node
|
||||
* \c virtual). Subclasses should override
|
||||
* \c drawImplementation() instead.
|
||||
*/
|
||||
#ifdef INLINE_DRAWABLE_DRAW
|
||||
inline void draw(RenderInfo& renderInfo) const;
|
||||
#else
|
||||
void draw(RenderInfo& renderInfo) const;
|
||||
#endif
|
||||
|
||||
inline void drawInner(RenderInfo& renderInfo) const
|
||||
{
|
||||
@@ -491,12 +497,11 @@ class OSG_EXPORT Drawable : public Node
|
||||
ref_ptr<DrawCallback> _drawCallback;
|
||||
};
|
||||
|
||||
#if 1
|
||||
#ifdef INLINE_DRAWABLE_DRAW
|
||||
inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
{
|
||||
State& state = *renderInfo.getState();
|
||||
bool useVertexArrayObject = _useVertexBufferObjects && state.useVertexArrayObject();
|
||||
|
||||
bool useVertexArrayObject = state.useVertexArrayObject(_useVertexArrayObject);
|
||||
if (useVertexArrayObject)
|
||||
{
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
@@ -560,46 +565,6 @@ inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
drawInner(renderInfo);
|
||||
}
|
||||
}
|
||||
#else
|
||||
inline void Drawable::draw(RenderInfo& renderInfo) const
|
||||
{
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
if (_useDisplayList && !(_supportsVertexBufferObjects && _useVertexBufferObjects && renderInfo.getState()->isVertexBufferObjectSupported()))
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
if( globj == 0 )
|
||||
{
|
||||
// compile the display list
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
|
||||
glEndList();
|
||||
}
|
||||
|
||||
// call the display list
|
||||
glCallList( globj);
|
||||
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// draw object as nature intended..
|
||||
if (_drawCallback.valid())
|
||||
_drawCallback->drawImplementation(renderInfo,this);
|
||||
else
|
||||
drawImplementation(renderInfo);
|
||||
}
|
||||
#endif
|
||||
|
||||
class AttributeFunctorArrayVisitor : public ArrayVisitor
|
||||
|
||||
@@ -716,10 +716,11 @@ class OSG_EXPORT State : public Referenced
|
||||
|
||||
|
||||
inline bool isVertexBufferObjectSupported() const { return _isVertexBufferObjectSupported; }
|
||||
inline bool useVertexBufferObject(bool useVBO) const { return _forceVertexBufferObject || (_isVertexBufferObjectSupported && useVBO); }
|
||||
|
||||
inline bool isVertexArrayObjectSupported() const { return _isVertexArrayObjectSupported; }
|
||||
inline bool useVertexArrayObject(bool useVAO) const { return _forceVertexArrayObject || (_isVertexArrayObjectSupported && useVAO); }
|
||||
|
||||
inline bool useVertexArrayObject() const { return _useVertexArrayObject; }
|
||||
|
||||
inline void setLastAppliedProgramObject(const Program::PerContextProgram* program)
|
||||
{
|
||||
@@ -1306,8 +1307,8 @@ class OSG_EXPORT State : public Referenced
|
||||
bool _isFogCoordSupported;
|
||||
bool _isVertexBufferObjectSupported;
|
||||
bool _isVertexArrayObjectSupported;
|
||||
|
||||
bool _useVertexArrayObject;
|
||||
bool _forceVertexBufferObject;
|
||||
bool _forceVertexArrayObject;
|
||||
|
||||
typedef void (GL_APIENTRY * ActiveTextureProc) (GLenum texture);
|
||||
typedef void (GL_APIENTRY * FogCoordPointerProc) (GLenum type, GLsizei stride, const GLvoid *pointer);
|
||||
|
||||
@@ -161,6 +161,8 @@ public:
|
||||
void setRequiresSetArrays(bool flag) { _requiresSetArrays = flag; }
|
||||
bool getRequiresSetArrays() const { return _requiresSetArrays; }
|
||||
|
||||
void dirty();
|
||||
|
||||
void release();
|
||||
|
||||
public:
|
||||
|
||||
@@ -116,7 +116,7 @@ void DisplaySettings::setDisplaySettings(const DisplaySettings& vs)
|
||||
_glContextProfileMask = vs._glContextProfileMask;
|
||||
_swapMethod = vs._swapMethod;
|
||||
|
||||
_geometryImplementation = vs._geometryImplementation;
|
||||
_vertexBufferHint = vs._vertexBufferHint;
|
||||
|
||||
_keystoneHint = vs._keystoneHint;
|
||||
_keystoneFileNames = vs._keystoneFileNames;
|
||||
@@ -243,8 +243,9 @@ void DisplaySettings::setDefaults()
|
||||
_swapMethod = SWAP_DEFAULT;
|
||||
_syncSwapBuffers = 0;
|
||||
|
||||
// _geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||
_geometryImplementation = OLD_GEOMETRY_IMPLEMENTATION;
|
||||
_vertexBufferHint = NO_PREFERENCE;
|
||||
// _vertexBufferHint = VERTEX_BUFFER_OBJECT;
|
||||
// _vertexBufferHint = VERTEX_ARRAY_OBJECT;
|
||||
|
||||
_keystoneHint = false;
|
||||
|
||||
@@ -367,8 +368,8 @@ static ApplicationUsageProxy DisplaySetting_e31(ApplicationUsage::ENVIRONMENTAL_
|
||||
"OSG_NvOptimusEnablement <value>",
|
||||
"Set the hint to NvOptimus of whether to enable it or not, set 1 to enable, 0 to disable");
|
||||
static ApplicationUsageProxy DisplaySetting_e32(ApplicationUsage::ENVIRONMENTAL_VARIABLE,
|
||||
"OSG_GEOMETRY_IMPLEMENTATION <value>",
|
||||
"Set the hint to what backend osg::Geometry implementation to use. OLD | NEW | VERTEX_ARRAY_OBJECT");
|
||||
"OSG_VERTEX_BUFFER_HINT <value>",
|
||||
"Set the hint to what backend osg::Geometry implementation to use. NO_PREFERENCE | VERTEX_BUFFER_OBJECT | VERTEX_ARRAY_OBJECT");
|
||||
|
||||
void DisplaySettings::readEnvironmentalVariables()
|
||||
{
|
||||
@@ -680,19 +681,22 @@ void DisplaySettings::readEnvironmentalVariables()
|
||||
}
|
||||
|
||||
|
||||
if ((ptr = getenv("OSG_GEOMETRY_IMPLEMENTATION")) != 0)
|
||||
if ((ptr = getenv("OSG_VERTEX_BUFFER_HINT")) != 0)
|
||||
{
|
||||
if (strcmp(ptr,"OLD")==0)
|
||||
if (strcmp(ptr,"VERTEX_BUFFER_OBJECT")==0 || strcmp(ptr,"VBO")==0)
|
||||
{
|
||||
_geometryImplementation = OLD_GEOMETRY_IMPLEMENTATION;
|
||||
}
|
||||
else if (strcmp(ptr,"NEW")==0 )
|
||||
{
|
||||
_geometryImplementation = NEW_GEOMETRY_IMPLEMENTATION;
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_BUFFER_OBJECT"<<std::endl;
|
||||
_vertexBufferHint = VERTEX_BUFFER_OBJECT;
|
||||
}
|
||||
else if (strcmp(ptr,"VERTEX_ARRAY_OBJECT")==0 || strcmp(ptr,"VAO")==0)
|
||||
{
|
||||
_geometryImplementation = VERTEX_ARRAY_OBJECT;
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to VERTEX_ARRAY_OBJECT"<<std::endl;
|
||||
_vertexBufferHint = VERTEX_ARRAY_OBJECT;
|
||||
}
|
||||
else
|
||||
{
|
||||
OSG_NOTICE<<"OSG_VERTEX_BUFFER_HINT set to NO_PREFERENCE"<<std::endl;
|
||||
_vertexBufferHint = NO_PREFERENCE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ Drawable::Drawable()
|
||||
_useVertexBufferObjects = false;
|
||||
#else
|
||||
_supportsVertexBufferObjects = true;
|
||||
_useVertexBufferObjects = false;
|
||||
_useVertexBufferObjects = true;
|
||||
#endif
|
||||
|
||||
_useVertexArrayObject = false;
|
||||
@@ -426,7 +426,7 @@ void Drawable::setUseVertexBufferObjects(bool flag)
|
||||
// if was previously set to true, remove display list.
|
||||
if (_useVertexBufferObjects)
|
||||
{
|
||||
dirtyDisplayList();
|
||||
dirtyGLObjects();
|
||||
}
|
||||
|
||||
_useVertexBufferObjects = flag;
|
||||
@@ -454,11 +454,7 @@ void Drawable::dirtyGLObjects()
|
||||
for(i=0; i<_vertexArrayStateList.size(); ++i)
|
||||
{
|
||||
VertexArrayState* vas = _vertexArrayStateList[i].get();
|
||||
if (vas)
|
||||
{
|
||||
vas->release();
|
||||
_vertexArrayStateList[i] = 0;
|
||||
}
|
||||
if (vas) vas->dirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -624,7 +620,86 @@ void Drawable::compileGLObjects(RenderInfo& renderInfo) const
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef INLINE_DRAWABLE_DRAW
|
||||
|
||||
void Drawable::draw(RenderInfo& renderInfo) const
|
||||
{
|
||||
// OSG_NOTICE<<"Geometry::draw() "<<this<<std::endl;
|
||||
|
||||
State& state = *renderInfo.getState();
|
||||
bool useVertexArrayObject = state.useVertexArrayObject(_useVertexArrayObject);
|
||||
if (useVertexArrayObject)
|
||||
{
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
VertexArrayState* vas = _vertexArrayStateList[contextID].get();
|
||||
if (!vas)
|
||||
{
|
||||
_vertexArrayStateList[contextID] = vas = createVertexArrayState(renderInfo, true);
|
||||
// OSG_NOTICE<<" Geometry::draw() "<<this<<", assigned _vertexArrayStateList[renderInfo.getContextID()]="<<_vertexArrayStateList[renderInfo.getContextID()].get()<<", vas="<<vas<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
// vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC);
|
||||
// OSG_NOTICE<<" Geometry::draw() "<<this<<", reusing _vertexArrayStateList[renderInfo.getContextID()]="<<_vertexArrayStateList[renderInfo.getContextID()].get()<<", vas="<<vas<< std::endl;
|
||||
}
|
||||
|
||||
|
||||
State::SetCurrentVertexArrayStateProxy setVASProxy(state, vas);
|
||||
|
||||
vas->bindVertexArrayObject();
|
||||
|
||||
drawInner(renderInfo);
|
||||
|
||||
vas->setRequiresSetArrays(getDataVariance()==osg::Object::DYNAMIC);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO, add check against whether VOA is active and supported
|
||||
if (state.getCurrentVertexArrayState()) state.getCurrentVertexArrayState()->bindVertexArrayObject();
|
||||
|
||||
|
||||
#ifdef OSG_GL_DISPLAYLISTS_AVAILABLE
|
||||
if (_useDisplayList)
|
||||
{
|
||||
// get the contextID (user defined ID of 0 upwards) for the
|
||||
// current OpenGL context.
|
||||
unsigned int contextID = renderInfo.getContextID();
|
||||
|
||||
// get the globj for the current contextID.
|
||||
GLuint& globj = _globjList[contextID];
|
||||
|
||||
if( globj == 0 )
|
||||
{
|
||||
// compile the display list
|
||||
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
||||
glNewList( globj, GL_COMPILE );
|
||||
|
||||
drawInner(renderInfo);
|
||||
|
||||
glEndList();
|
||||
}
|
||||
|
||||
// call the display list
|
||||
glCallList( globj);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
// if state.previousVertexArrayState() is different than currentVertexArrayState bind current
|
||||
|
||||
// OSG_NOTICE<<"Fallback drawInner()........................"<<std::endl;
|
||||
|
||||
drawInner(renderInfo);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
VertexArrayState* Drawable::createVertexArrayState(RenderInfo& renderInfo, bool usingVBOs) const
|
||||
{
|
||||
return new osg::VertexArrayState(renderInfo.getState());
|
||||
VertexArrayState* vos = new osg::VertexArrayState(renderInfo.getState());
|
||||
vos->assignAllDispatchers();
|
||||
return vos;
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -196,15 +196,16 @@ void DrawElementsUByte::draw(State& state, bool useVertexBufferObjects) const
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
|
||||
if (ebo)
|
||||
{
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_BYTE, (const GLvoid *)(ebo->getOffset(getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.getCurrentVertexArrayState()->unbindElementBufferObject();
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_BYTE, &front(), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_BYTE, &front());
|
||||
}
|
||||
@@ -257,15 +258,16 @@ void DrawElementsUShort::draw(State& state, bool useVertexBufferObjects) const
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
|
||||
if (ebo)
|
||||
{
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_SHORT, (const GLvoid *)(ebo->getOffset(getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.getCurrentVertexArrayState()->unbindElementBufferObject();
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_SHORT, &front(), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_SHORT, &front());
|
||||
}
|
||||
@@ -317,15 +319,16 @@ void DrawElementsUInt::draw(State& state, bool useVertexBufferObjects) const
|
||||
if (useVertexBufferObjects)
|
||||
{
|
||||
GLBufferObject* ebo = getOrCreateGLBufferObject(state.getContextID());
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
|
||||
if (ebo)
|
||||
{
|
||||
state.getCurrentVertexArrayState()->bindElementBufferObject(ebo);
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_INT, (const GLvoid *)(ebo->getOffset(getBufferIndex())));
|
||||
}
|
||||
else
|
||||
{
|
||||
state.getCurrentVertexArrayState()->unbindElementBufferObject();
|
||||
if (_numInstances>=1) state.glDrawElementsInstanced(mode, size(), GL_UNSIGNED_INT, &front(), _numInstances);
|
||||
else glDrawElements(mode, size(), GL_UNSIGNED_INT, &front());
|
||||
}
|
||||
|
||||
@@ -96,7 +96,9 @@ State::State():
|
||||
_isFogCoordSupported = false;
|
||||
_isVertexBufferObjectSupported = false;
|
||||
_isVertexArrayObjectSupported = false;
|
||||
_useVertexArrayObject = false;
|
||||
|
||||
_forceVertexBufferObject = false;
|
||||
_forceVertexArrayObject = false;
|
||||
|
||||
_lastAppliedProgramObject = 0;
|
||||
|
||||
@@ -176,7 +178,8 @@ void State::initializeExtensionProcs()
|
||||
_isVertexArrayObjectSupported = _glExtensions->isVAOSupported;
|
||||
|
||||
const DisplaySettings* ds = getDisplaySettings() ? getDisplaySettings() : osg::DisplaySettings::instance();
|
||||
_useVertexArrayObject = _isVertexArrayObjectSupported && (ds->getGeometryImplementation()==DisplaySettings::VERTEX_ARRAY_OBJECT);
|
||||
_forceVertexArrayObject = _isVertexArrayObjectSupported && (ds->getVertexBufferHint()==DisplaySettings::VERTEX_ARRAY_OBJECT);
|
||||
_forceVertexBufferObject = _forceVertexArrayObject || (_isVertexBufferObjectSupported && (ds->getVertexBufferHint()==DisplaySettings::VERTEX_BUFFER_OBJECT));
|
||||
|
||||
|
||||
// Set up up global VertexArrayState object
|
||||
|
||||
@@ -719,3 +719,9 @@ void VertexArrayState::setInterleavedArrays( osg::State& state, GLenum format, G
|
||||
dirtyAllVertexArrays();
|
||||
#endif
|
||||
}
|
||||
|
||||
void VertexArrayState::dirty()
|
||||
{
|
||||
setRequiresSetArrays(true);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user