Further work on the new VBO support

This commit is contained in:
Robert Osfield 2007-04-27 14:52:30 +00:00
parent 2168eac1d4
commit 4968eb7136
11 changed files with 570 additions and 56 deletions

View File

@ -271,14 +271,14 @@ class OSG_EXPORT Drawable : public Object
/** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
method to use OpenGL vertex buffer objects for rendering.*/
void setUseVertexBufferObjects(bool flag);
virtual void setUseVertexBufferObjects(bool flag);
/** Return whether OpenGL vertex buffer objects should be used when supported by OpenGL driver.*/
inline bool getUseVertexBufferObjects() const { return _useVertexBufferObjects; }
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
void dirtyDisplayList();
virtual void dirtyDisplayList();
/** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.

View File

@ -142,18 +142,18 @@ class OSG_EXPORT Geometry : public Drawable
*/
static const ArrayData s_InvalidArrayData;
typedef std::vector< ArrayData > ArrayList;
typedef std::vector< ArrayData > ArrayDataList;
void setVertexArray(Array* array) { _vertexData.array = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); }
void setVertexArray(Array* array);
Array* getVertexArray() { return _vertexData.array.get(); }
const Array* getVertexArray() const { return _vertexData.array.get(); }
void setVertexIndices(IndexArray* array) { _vertexData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); }
void setVertexIndices(IndexArray* array);
IndexArray* getVertexIndices() { return _vertexData.indices.get(); }
const IndexArray* getVertexIndices() const { return _vertexData.indices.get(); }
void setVertexData(const ArrayData& arrayData) { _vertexData = arrayData; computeFastPathsUsed(); dirtyDisplayList(); dirtyBound(); }
void setVertexData(const ArrayData& arrayData);
ArrayData& getVertexData() { return _vertexData; }
const ArrayData& getVertexData() const { return _vertexData; }
@ -161,30 +161,30 @@ class OSG_EXPORT Geometry : public Drawable
void setNormalBinding(AttributeBinding ab);
AttributeBinding getNormalBinding() const { return _normalData.binding; }
void setNormalArray(Array* array) { _normalData.array = array; if (!_normalData.array.valid()) _normalData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
void setNormalArray(Array* array);
Array* getNormalArray() { return _normalData.array.get(); }
const Array* getNormalArray() const { return _normalData.array.get(); }
void setNormalIndices(IndexArray* array) { _normalData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
void setNormalIndices(IndexArray* array);
IndexArray* getNormalIndices() { return _normalData.indices.get(); }
const IndexArray* getNormalIndices() const { return _normalData.indices.get(); }
void setNormalData(const ArrayData& arrayData) { _normalData = arrayData; computeFastPathsUsed(); dirtyDisplayList();}
void setNormalData(const ArrayData& arrayData);
ArrayData& getNormalData() { return _normalData; }
const ArrayData& getNormalData() const { return _normalData; }
void setColorBinding(AttributeBinding ab);
AttributeBinding getColorBinding() const { return _colorData.binding; }
void setColorArray(Array* array) { _colorData.array = array; if (!_colorData.array.valid()) _colorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
void setColorArray(Array* array);
Array* getColorArray() { return _colorData.array.get(); }
const Array* getColorArray() const { return _colorData.array.get(); }
void setColorIndices(IndexArray* array) { _colorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
void setColorIndices(IndexArray* array);
IndexArray* getColorIndices() { return _colorData.indices.get(); }
const IndexArray* getColorIndices() const { return _colorData.indices.get(); }
void setColorData(const ArrayData& arrayData) { _colorData = arrayData; computeFastPathsUsed(); dirtyDisplayList();}
void setColorData(const ArrayData& arrayData);
ArrayData& getColorData() { return _colorData; }
const ArrayData& getColorData() const { return _colorData; }
@ -192,15 +192,15 @@ class OSG_EXPORT Geometry : public Drawable
void setSecondaryColorBinding(AttributeBinding ab);
AttributeBinding getSecondaryColorBinding() const { return _secondaryColorData.binding; }
void setSecondaryColorArray(Array* array) { _secondaryColorData.array = array; if (!_secondaryColorData.array.valid()) _secondaryColorData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
void setSecondaryColorArray(Array* array);
Array* getSecondaryColorArray() { return _secondaryColorData.array.get(); }
const Array* getSecondaryColorArray() const { return _secondaryColorData.array.get(); }
void setSecondaryColorIndices(IndexArray* array) { _secondaryColorData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
void setSecondaryColorIndices(IndexArray* array);
IndexArray* getSecondaryColorIndices() { return _secondaryColorData.indices.get(); }
const IndexArray* getSecondaryColorIndices() const { return _secondaryColorData.indices.get(); }
void setSecondaryColorData(const ArrayData& arrayData) { _secondaryColorData = arrayData; computeFastPathsUsed(); dirtyDisplayList(); }
void setSecondaryColorData(const ArrayData& arrayData);
ArrayData& getSecondaryColorData() { return _secondaryColorData; }
const ArrayData& getSecondaryColorData() const { return _secondaryColorData; }
@ -208,19 +208,18 @@ class OSG_EXPORT Geometry : public Drawable
void setFogCoordBinding(AttributeBinding ab);
AttributeBinding getFogCoordBinding() const { return _fogCoordData.binding; }
void setFogCoordArray(Array* array) { _fogCoordData.array = array; if (!_fogCoordData.array.valid()) _fogCoordData.binding=BIND_OFF; computeFastPathsUsed(); dirtyDisplayList(); }
void setFogCoordArray(Array* array);
Array* getFogCoordArray() { return _fogCoordData.array.get(); }
const Array* getFogCoordArray() const { return _fogCoordData.array.get(); }
void setFogCoordIndices(IndexArray* array) { _fogCoordData.indices = array; computeFastPathsUsed(); dirtyDisplayList(); }
void setFogCoordIndices(IndexArray* array);
IndexArray* getFogCoordIndices() { return _fogCoordData.indices.get(); }
const IndexArray* getFogCoordIndices() const { return _fogCoordData.indices.get(); }
void setFogCoordData(const ArrayData& arrayData) { _fogCoordData = arrayData; computeFastPathsUsed(); dirtyDisplayList(); }
void setFogCoordData(const ArrayData& arrayData);
ArrayData& getFogCoordData() { return _fogCoordData; }
const ArrayData& getFogCoordData() const { return _fogCoordData; }
void setTexCoordArray(unsigned int unit,Array*);
Array* getTexCoordArray(unsigned int unit);
@ -235,8 +234,8 @@ class OSG_EXPORT Geometry : public Drawable
const ArrayData& getTexCoordData(unsigned int index) const;
unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); }
ArrayList& getTexCoordArrayList() { return _texCoordList; }
const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
ArrayDataList& getTexCoordArrayList() { return _texCoordList; }
const ArrayDataList& getTexCoordArrayList() const { return _texCoordList; }
@ -259,8 +258,8 @@ class OSG_EXPORT Geometry : public Drawable
const ArrayData& getVertexAttribData(unsigned int index) const;
unsigned int getNumVertexAttribArrays() const { return _vertexAttribList.size(); }
ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
ArrayDataList& getVertexAttribArrayList() { return _vertexAttribList; }
const ArrayDataList& getVertexAttribArrayList() const { return _vertexAttribList; }
@ -293,6 +292,25 @@ class OSG_EXPORT Geometry : public Drawable
unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
/** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
method to use OpenGL vertex buffer objects for rendering.*/
virtual void setUseVertexBufferObjects(bool flag);
/** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
virtual void dirtyDisplayList();
typedef std::vector<osg::Array*> ArrayList;
bool getArrayList(ArrayList& arrayList);
typedef std::vector<osg::DrawElements*> DrawElementsList;
bool getDrawElementsList(DrawElementsList& drawElementsList);
osg::VertexBufferObject* getOrCreateVertexBufferObject();
osg::ElementsBufferObject* getOrCreateElementsBufferObject();
/** Set whether fast paths should be used when supported. */
void setFastPathHint(bool on) { _fastPathHint = on; }
@ -375,6 +393,9 @@ class OSG_EXPORT Geometry : public Drawable
void computeCorrectBindingsAndArraySizes(ArrayData& arrayData,const char* arrayName);
void computeCorrectBindingsAndArraySizes(Vec3ArrayData& arrayData,const char* arrayName);
void addVertexBufferObjectIfRequired(osg::Array* array);
void addElementsBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
PrimitiveSetList _primitives;
ArrayData _vertexData;
@ -382,8 +403,8 @@ class OSG_EXPORT Geometry : public Drawable
ArrayData _colorData;
ArrayData _secondaryColorData;
ArrayData _fogCoordData;
ArrayList _texCoordList;
ArrayList _vertexAttribList;
ArrayDataList _texCoordList;
ArrayDataList _vertexAttribList;
mutable bool _fastPath;
bool _fastPathHint;

View File

@ -171,6 +171,8 @@ public:
virtual void end() = 0;
};
class DrawElements;
class OSG_EXPORT PrimitiveSet : public Object
{
public:
@ -220,6 +222,9 @@ class OSG_EXPORT PrimitiveSet : public Object
virtual const GLvoid* getDataPointer() const { return 0; }
virtual unsigned int getTotalDataSize() const { return 0; }
virtual bool supportsBufferObject() const { return false; }
virtual DrawElements* getDrawElements() { return 0; }
virtual const DrawElements* getDrawElements() const { return 0; }
void setMode(GLenum mode) { _mode = mode; }
GLenum getMode() const { return _mode; }
@ -415,6 +420,9 @@ class DrawElements : public PrimitiveSet
_eboIndex(0) {}
virtual DrawElements* getDrawElements() { return this; }
virtual const DrawElements* getDrawElements() const { return this; }
/** Set the ElementsBufferObject.*/
inline void setElementsBufferObject(osg::ElementsBufferObject* ebo)
{

View File

@ -603,6 +603,8 @@ void Drawable::setUseDisplayList(bool flag)
void Drawable::setUseVertexBufferObjects(bool flag)
{
osg::notify(osg::NOTICE)<<"Drawable::setUseVertexBufferObjects("<<flag<<")"<<std::endl;
// if value unchanged simply return.
if (_useVertexBufferObjects==flag) return;

View File

@ -443,14 +443,14 @@ Geometry::Geometry(const Geometry& geometry,const CopyOp& copyop):
if (primitive) _primitives.push_back(primitive);
}
for(ArrayList::const_iterator titr=geometry._texCoordList.begin();
for(ArrayDataList::const_iterator titr=geometry._texCoordList.begin();
titr!=geometry._texCoordList.end();
++titr)
{
_texCoordList.push_back(ArrayData(*titr, copyop));
}
for(ArrayList::const_iterator vitr=geometry._vertexAttribList.begin();
for(ArrayDataList::const_iterator vitr=geometry._vertexAttribList.begin();
vitr!=geometry._vertexAttribList.end();
++vitr)
{
@ -479,6 +479,139 @@ bool Geometry::empty() const
return true;
}
void Geometry::setVertexArray(Array* array)
{
_vertexData.array = array;
computeFastPathsUsed();
dirtyDisplayList();
dirtyBound();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setVertexIndices(IndexArray* array)
{
_vertexData.indices = array;
computeFastPathsUsed();
dirtyDisplayList();
dirtyBound();
}
void Geometry::setVertexData(const ArrayData& arrayData)
{
_vertexData = arrayData;
computeFastPathsUsed();
dirtyDisplayList();
dirtyBound();
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
void Geometry::setNormalArray(Array* array)
{
_normalData.array = array;
if (!_normalData.array.valid()) _normalData.binding=BIND_OFF;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setNormalIndices(IndexArray* array)
{
_normalData.indices = array;
computeFastPathsUsed();
dirtyDisplayList();
}
void Geometry::setNormalData(const ArrayData& arrayData)
{
_normalData = arrayData;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
void Geometry::setColorArray(Array* array)
{
_colorData.array = array;
if (!_colorData.array.valid()) _colorData.binding=BIND_OFF;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setColorIndices(IndexArray* array)
{
_colorData.indices = array;
computeFastPathsUsed();
dirtyDisplayList();
}
void Geometry::setColorData(const ArrayData& arrayData)
{
_colorData = arrayData;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
void Geometry::setSecondaryColorArray(Array* array)
{
_secondaryColorData.array = array;
if (!_secondaryColorData.array.valid()) _secondaryColorData.binding=BIND_OFF;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setSecondaryColorIndices(IndexArray* array)
{
_secondaryColorData.indices = array;
computeFastPathsUsed();
dirtyDisplayList();
}
void Geometry::setSecondaryColorData(const ArrayData& arrayData)
{
_secondaryColorData = arrayData;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
void Geometry::setFogCoordArray(Array* array)
{
_fogCoordData.array = array;
if (!_fogCoordData.array.valid()) _fogCoordData.binding=BIND_OFF;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
void Geometry::setFogCoordIndices(IndexArray* array)
{
_fogCoordData.indices = array;
computeFastPathsUsed();
dirtyDisplayList();
}
void Geometry::setFogCoordData(const ArrayData& arrayData)
{
_fogCoordData = arrayData;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
void Geometry::setNormalBinding(AttributeBinding ab)
{
if (_normalData.binding == ab) return;
@ -521,6 +654,8 @@ void Geometry::setTexCoordData(unsigned int unit,const ArrayData& arrayData)
_texCoordList.resize(unit+1);
_texCoordList[unit] = arrayData;
if (_useVertexBufferObjects && arrayData.array.valid()) addVertexBufferObjectIfRequired(arrayData.array.get());
}
Geometry::ArrayData& Geometry::getTexCoordData(unsigned int unit)
@ -546,6 +681,8 @@ void Geometry::setTexCoordArray(unsigned int unit,Array* array)
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
Array* Geometry::getTexCoordArray(unsigned int unit)
@ -587,9 +724,11 @@ void Geometry::setVertexAttribData(unsigned int index, const Geometry::ArrayData
_vertexAttribList.resize(index+1);
_vertexAttribList[index] = attrData;
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && attrData.array.valid()) addVertexBufferObjectIfRequired(attrData.array.get());
}
Geometry::ArrayData& Geometry::getVertexAttribData(unsigned int index)
@ -614,6 +753,8 @@ void Geometry::setVertexAttribArray(unsigned int index, Array* array)
computeFastPathsUsed();
dirtyDisplayList();
if (_useVertexBufferObjects && array) addVertexBufferObjectIfRequired(array);
}
Array *Geometry::getVertexAttribArray(unsigned int index)
@ -680,6 +821,8 @@ bool Geometry::addPrimitiveSet(PrimitiveSet* primitiveset)
{
if (primitiveset)
{
if (_useVertexBufferObjects) addElementsBufferObjectIfRequired(primitiveset);
_primitives.push_back(primitiveset);
dirtyDisplayList();
dirtyBound();
@ -693,6 +836,8 @@ bool Geometry::setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
if (i<_primitives.size() && primitiveset)
{
if (_useVertexBufferObjects) addElementsBufferObjectIfRequired(primitiveset);
_primitives[i] = primitiveset;
dirtyDisplayList();
dirtyBound();
@ -704,8 +849,11 @@ bool Geometry::setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
bool Geometry::insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
if (primitiveset)
{
if (_useVertexBufferObjects) addElementsBufferObjectIfRequired(primitiveset);
if (i<_primitives.size())
{
_primitives.insert(_primitives.begin()+i,primitiveset);
@ -717,6 +865,7 @@ bool Geometry::insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset)
{
return addPrimitiveSet(primitiveset);
}
}
notify(WARN)<<"Warning: invalid index i or primitiveset passed to osg::Geometry::insertPrimitiveSet(i,primitiveset), ignoring call."<<std::endl;
return false;
@ -876,6 +1025,198 @@ unsigned int Geometry::getGLObjectSizeHint() const
return totalSize;
}
bool Geometry::getArrayList(ArrayList& arrayList)
{
unsigned int startSize = arrayList.size();
if (_vertexData.array.valid()) arrayList.push_back(_vertexData.array.get());
if (_normalData.array.valid()) arrayList.push_back(_normalData.array.get());
if (_colorData.array.valid()) arrayList.push_back(_colorData.array.get());
if (_secondaryColorData.array.valid()) arrayList.push_back(_secondaryColorData.array.get());
if (_fogCoordData.array.valid()) arrayList.push_back(_fogCoordData.array.get());
return arrayList.size()!=startSize;
}
bool Geometry::getDrawElementsList(DrawElementsList& drawElementsList)
{
unsigned int startSize = drawElementsList.size();
for(PrimitiveSetList::iterator itr = _primitives.begin();
itr != _primitives.end();
++itr)
{
osg::DrawElements* de = (*itr)->getDrawElements();
if (de) drawElementsList.push_back(de);
}
return drawElementsList.size()!=startSize;
}
void Geometry::addVertexBufferObjectIfRequired(osg::Array* array)
{
if (_useVertexBufferObjects)
{
if (!array->getVertexBufferObject())
{
array->setVertexBufferObject(getOrCreateVertexBufferObject());
}
}
}
void Geometry::addElementsBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet)
{
if (_useVertexBufferObjects)
{
osg::DrawElements* drawElements = primitiveSet->getDrawElements();
if (drawElements && !drawElements->getElementsBufferObject())
{
drawElements->setElementsBufferObject(getOrCreateElementsBufferObject());
}
}
}
osg::VertexBufferObject* Geometry::getOrCreateVertexBufferObject()
{
ArrayList arrayList;
getArrayList(arrayList);
osg::VertexBufferObject* vbo = 0;
ArrayList::iterator vitr;
for(vitr = arrayList.begin();
vitr != arrayList.end() && !vbo;
++vitr)
{
osg::Array* array = *vitr;
if (!array->getVertexBufferObject()) vbo = array->getVertexBufferObject();
}
if (!vbo) vbo = new osg::VertexBufferObject;
return vbo;
}
osg::ElementsBufferObject* Geometry::getOrCreateElementsBufferObject()
{
DrawElementsList drawElementsList;
getDrawElementsList(drawElementsList);
osg::ElementsBufferObject* ebo = 0;
DrawElementsList::iterator deitr;
for(deitr = drawElementsList.begin();
deitr != drawElementsList.end();
++deitr)
{
osg::DrawElements* elements = *deitr;
if (!elements->getElementsBufferObject()) ebo = elements->getElementsBufferObject();
}
if (!ebo) ebo = new osg::ElementsBufferObject;
return ebo;
}
void Geometry::setUseVertexBufferObjects(bool flag)
{
osg::notify(osg::NOTICE)<<"Geometry::setUseVertexBufferObjects("<<flag<<")"<<std::endl;
if (_useVertexBufferObjects==flag) return;
Drawable::setUseVertexBufferObjects(flag);
osg::notify(osg::NOTICE)<<" setting up"<<std::endl;
ArrayList arrayList;
getArrayList(arrayList);
DrawElementsList drawElementsList;
getDrawElementsList(drawElementsList);
typedef std::vector<osg::VertexBufferObject*> VertexBufferObjectList;
typedef std::vector<osg::ElementsBufferObject*> ElementsBufferObjectList;
if (_useVertexBufferObjects)
{
if (!arrayList.empty())
{
VertexBufferObjectList vboList;
osg::VertexBufferObject* vbo = 0;
ArrayList::iterator vitr;
for(vitr = arrayList.begin();
vitr != arrayList.end() && !vbo;
++vitr)
{
osg::Array* array = *vitr;
if (!array->getVertexBufferObject()) vbo = array->getVertexBufferObject();
}
if (!vbo) vbo = new osg::VertexBufferObject;
for(vitr = arrayList.begin();
vitr != arrayList.end();
++vitr)
{
osg::Array* array = *vitr;
if (!array->getVertexBufferObject()) array->setVertexBufferObject(vbo);
}
}
if (!drawElementsList.empty())
{
ElementsBufferObjectList eboList;
osg::ElementsBufferObject* ebo = 0;
DrawElementsList::iterator deitr;
for(deitr = drawElementsList.begin();
deitr != drawElementsList.end();
++deitr)
{
osg::DrawElements* elements = *deitr;
if (!elements->getElementsBufferObject()) ebo = elements->getElementsBufferObject();
}
if (!ebo) ebo = new osg::ElementsBufferObject;
for(deitr = drawElementsList.begin();
deitr != drawElementsList.end();
++deitr)
{
osg::DrawElements* elements = *deitr;
if (!elements->getElementsBufferObject()) elements->setElementsBufferObject(ebo);
}
}
}
else
{
for(ArrayList::iterator vitr = arrayList.begin();
vitr != arrayList.end();
++vitr)
{
osg::Array* array = *vitr;
if (!array->getVertexBufferObject()) array->setVertexBufferObject(0);
}
for(DrawElementsList::iterator deitr = drawElementsList.begin();
deitr != drawElementsList.end();
++deitr)
{
osg::DrawElements* elements = *deitr;
if (!elements->getElementsBufferObject()) elements->setElementsBufferObject(0);
}
}
}
void Geometry::dirtyDisplayList()
{
Drawable::dirtyDisplayList();
}
void Geometry::drawImplementation(RenderInfo& renderInfo) const
{
State& state = *renderInfo.getState();
@ -962,12 +1303,73 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
if (areFastPathsUsed())
{
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// fast path.
//
if (usingVertexBufferObjects)
{
// first up lets check for new VBO support:
unsigned int numArraysWithVBO = 0;
unsigned int numArraysWithoutVBO = 0;
if (_vertexData.array.valid())
{
if (_vertexData.array->getVertexBufferObject())
++numArraysWithVBO;
else
++numArraysWithoutVBO;
}
if (_normalData.array.valid())
{
if (_normalData.array->getVertexBufferObject())
++numArraysWithVBO;
else
++numArraysWithoutVBO;
}
if (_colorData.array.valid())
{
if (_colorData.array->getVertexBufferObject())
++numArraysWithVBO;
else
++numArraysWithoutVBO;
}
unsigned int unit;
for(unit=0;unit<_texCoordList.size();++unit)
{
if (_texCoordList[unit].array.valid())
{
if (_texCoordList[unit].array->getVertexBufferObject())
++numArraysWithVBO;
else
++numArraysWithoutVBO;
}
}
if( handleVertexAttributes )
{
for(unit=0;unit<_vertexAttribList.size();++unit)
{
if (_vertexAttribList[unit].array.valid())
{
if (_vertexAttribList[unit].array->getVertexBufferObject())
++numArraysWithVBO;
else
++numArraysWithoutVBO;
}
}
}
osg::notify(osg::NOTICE)<<"Geometry::drawImplementation "<<std::endl;
osg::notify(osg::NOTICE)<<" numArraysWithVBO = "<<numArraysWithVBO<<std::endl;
osg::notify(osg::NOTICE)<<" numArraysWithoutVBO = "<<numArraysWithoutVBO<<std::endl;
//
// Vertex Buffer Object path for defining vertex arrays.
//
@ -1002,7 +1404,6 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
if (_fogCoordData.array.valid()) totalSize += _fogCoordData.array->getTotalDataSize();
unsigned int unit;
for(unit=0;unit<_texCoordList.size();++unit)
{
_texCoordList[unit].offset = totalSize;
@ -1074,10 +1475,13 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
}
else
{
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,buffer);
}
//std::cout << "binding VertexBuffer "<<buffer<<std::endl;
extensions->glBindBuffer(GL_ARRAY_BUFFER_ARB,buffer);
if( _vertexData.array.valid() )
state.setVertexPointer(_vertexData.array->getDataSize(),_vertexData.array->getDataType(),0,(const GLvoid*)_vertexData.offset);
@ -1104,7 +1508,6 @@ void Geometry::drawImplementation(RenderInfo& renderInfo) const
else
state.disableFogCoordPointer();
unsigned int unit;
for(unit=0;unit<_texCoordList.size();++unit)
{
const Array* array = _texCoordList[unit].array.get();
@ -2501,14 +2904,14 @@ bool Geometry::verifyBindings() const
if (!verifyBindings(_secondaryColorData)) return false;
if (!verifyBindings(_fogCoordData)) return false;
for(ArrayList::const_iterator titr=_texCoordList.begin();
for(ArrayDataList::const_iterator titr=_texCoordList.begin();
titr!=_texCoordList.end();
++titr)
{
if (!verifyBindings(*titr)) return false;
}
for(ArrayList::const_iterator vitr=_vertexAttribList.begin();
for(ArrayDataList::const_iterator vitr=_vertexAttribList.begin();
vitr!=_vertexAttribList.end();
++vitr)
{
@ -2527,14 +2930,14 @@ void Geometry::computeCorrectBindingsAndArraySizes()
computeCorrectBindingsAndArraySizes(_secondaryColorData,"_secondaryColorData");
computeCorrectBindingsAndArraySizes(_fogCoordData,"_fogCoordData");
for(ArrayList::iterator titr=_texCoordList.begin();
for(ArrayDataList::iterator titr=_texCoordList.begin();
titr!=_texCoordList.end();
++titr)
{
computeCorrectBindingsAndArraySizes(*titr,"_texCoordList[]");
}
for(ArrayList::iterator vitr=_vertexAttribList.begin();
for(ArrayDataList::iterator vitr=_vertexAttribList.begin();
vitr!=_vertexAttribList.end();
++vitr)
{

View File

@ -128,7 +128,7 @@ void Geometry::write(DataOutputStream* out){
out->writeArray(getFogCoordIndices());
}
// Write texture coord arrays
Geometry::ArrayList& tcal = getTexCoordArrayList();
Geometry::ArrayDataList& tcal = getTexCoordArrayList();
out->writeInt(tcal.size());
unsigned int j;
for(j=0;j<tcal.size();j++)
@ -146,7 +146,7 @@ void Geometry::write(DataOutputStream* out){
}
// Write vertex attributes
Geometry::ArrayList& vaal = getVertexAttribArrayList();
Geometry::ArrayDataList& vaal = getVertexAttribArrayList();
out->writeInt(vaal.size());
for(j=0;j<vaal.size();j++)
{

View File

@ -1185,7 +1185,7 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
Array_writeLocalData(*geom.getFogCoordIndices(),fw);
}
const Geometry::ArrayList& tcal=geom.getTexCoordArrayList();
const Geometry::ArrayDataList& tcal=geom.getTexCoordArrayList();
unsigned int i;
for(i=0;i<tcal.size();++i)
{
@ -1201,7 +1201,7 @@ bool Geometry_writeLocalData(const Object& obj, Output& fw)
}
}
const Geometry::ArrayList& vaal=geom.getVertexAttribArrayList();
const Geometry::ArrayDataList& vaal=geom.getVertexAttribArrayList();
for(i=0;i<vaal.size();++i)
{
const osg::Geometry::ArrayData& arrayData = vaal[i];

View File

@ -449,8 +449,8 @@ void Tessellator::handleNewVertices(osg::Geometry& geom,VertexPtrToIndexMap &ver
arrays.push_back(geom.getFogCoordArray());
}
osg::Geometry::ArrayList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayList::iterator tcalItr=tcal.begin();
osg::Geometry::ArrayDataList& tcal = geom.getTexCoordArrayList();
for(osg::Geometry::ArrayDataList::iterator tcalItr=tcal.begin();
tcalItr!=tcal.end();
++tcalItr)
{

View File

@ -224,7 +224,7 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Drawable)
"Return OpenGL display list for specified contextID. ",
"");
I_Method1(void, setUseVertexBufferObjects, IN, bool, flag,
Properties::NON_VIRTUAL,
Properties::VIRTUAL,
__void__setUseVertexBufferObjects__bool,
"When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation method to use OpenGL vertex buffer objects for rendering. ",
"");
@ -234,7 +234,7 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::Drawable)
"Return whether OpenGL vertex buffer objects should be used when supported by OpenGL driver. ",
"");
I_Method0(void, dirtyDisplayList,
Properties::NON_VIRTUAL,
Properties::VIRTUAL,
__void__dirtyDisplayList,
"Force a recompile on next draw() of any OpenGL display list associated with this geoset. ",
"");

View File

@ -11,6 +11,7 @@
#include <osgIntrospection/Attributes>
#include <osg/Array>
#include <osg/BufferObject>
#include <osg/CopyOp>
#include <osg/Drawable>
#include <osg/Geometry>
@ -26,10 +27,14 @@
#undef OUT
#endif
TYPE_NAME_ALIAS(std::vector< osg::Geometry::ArrayData >, osg::Geometry::ArrayList)
TYPE_NAME_ALIAS(std::vector< osg::Geometry::ArrayData >, osg::Geometry::ArrayDataList)
TYPE_NAME_ALIAS(std::vector< osg::ref_ptr< osg::PrimitiveSet > >, osg::Geometry::PrimitiveSetList)
TYPE_NAME_ALIAS(std::vector< osg::Array * >, osg::Geometry::ArrayList)
TYPE_NAME_ALIAS(std::vector< osg::DrawElements * >, osg::Geometry::DrawElementsList)
BEGIN_ENUM_REFLECTOR(osg::Geometry::AttributeBinding)
I_EnumLabel(osg::Geometry::BIND_OFF);
I_EnumLabel(osg::Geometry::BIND_OVERALL);
@ -402,14 +407,14 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
__unsigned_int__getNumTexCoordArrays,
"",
"");
I_Method0(osg::Geometry::ArrayList &, getTexCoordArrayList,
I_Method0(osg::Geometry::ArrayDataList &, getTexCoordArrayList,
Properties::NON_VIRTUAL,
__ArrayList_R1__getTexCoordArrayList,
__ArrayDataList_R1__getTexCoordArrayList,
"",
"");
I_Method0(const osg::Geometry::ArrayList &, getTexCoordArrayList,
I_Method0(const osg::Geometry::ArrayDataList &, getTexCoordArrayList,
Properties::NON_VIRTUAL,
__C5_ArrayList_R1__getTexCoordArrayList,
__C5_ArrayDataList_R1__getTexCoordArrayList,
"",
"");
I_Method2(void, setVertexAttribArray, IN, unsigned int, index, IN, osg::Array *, array,
@ -482,14 +487,14 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
__unsigned_int__getNumVertexAttribArrays,
"",
"");
I_Method0(osg::Geometry::ArrayList &, getVertexAttribArrayList,
I_Method0(osg::Geometry::ArrayDataList &, getVertexAttribArrayList,
Properties::NON_VIRTUAL,
__ArrayList_R1__getVertexAttribArrayList,
__ArrayDataList_R1__getVertexAttribArrayList,
"",
"");
I_Method0(const osg::Geometry::ArrayList &, getVertexAttribArrayList,
I_Method0(const osg::Geometry::ArrayDataList &, getVertexAttribArrayList,
Properties::NON_VIRTUAL,
__C5_ArrayList_R1__getVertexAttribArrayList,
__C5_ArrayDataList_R1__getVertexAttribArrayList,
"",
"");
I_Method1(void, setPrimitiveSetList, IN, const osg::Geometry::PrimitiveSetList &, primitives,
@ -547,6 +552,36 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
__unsigned_int__getPrimitiveSetIndex__C5_PrimitiveSet_P1,
"Get the index number of a primitive set, return a value between 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet(). ",
"When checking for a valid find value use if ((value=geometry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet())");
I_Method1(void, setUseVertexBufferObjects, IN, bool, flag,
Properties::VIRTUAL,
__void__setUseVertexBufferObjects__bool,
"When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation method to use OpenGL vertex buffer objects for rendering. ",
"");
I_Method0(void, dirtyDisplayList,
Properties::VIRTUAL,
__void__dirtyDisplayList,
"Force a recompile on next draw() of any OpenGL display list associated with this geoset. ",
"");
I_Method1(bool, getArrayList, IN, osg::Geometry::ArrayList &, arrayList,
Properties::NON_VIRTUAL,
__bool__getArrayList__ArrayList_R1,
"",
"");
I_Method1(bool, getDrawElementsList, IN, osg::Geometry::DrawElementsList &, drawElementsList,
Properties::NON_VIRTUAL,
__bool__getDrawElementsList__DrawElementsList_R1,
"",
"");
I_Method0(osg::VertexBufferObject *, getOrCreateVertexBufferObject,
Properties::NON_VIRTUAL,
__osg_VertexBufferObject_P1__getOrCreateVertexBufferObject,
"",
"");
I_Method0(osg::ElementsBufferObject *, getOrCreateElementsBufferObject,
Properties::NON_VIRTUAL,
__osg_ElementsBufferObject_P1__getOrCreateElementsBufferObject,
"",
"");
I_Method1(void, setFastPathHint, IN, bool, on,
Properties::NON_VIRTUAL,
__void__setFastPathHint__bool,
@ -686,6 +721,18 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
__void__computeCorrectBindingsAndArraySizes__Vec3ArrayData_R1__C5_char_P1,
"",
"");
I_ProtectedMethod1(void, addVertexBufferObjectIfRequired, IN, osg::Array *, array,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__addVertexBufferObjectIfRequired__osg_Array_P1,
"",
"");
I_ProtectedMethod1(void, addElementsBufferObjectIfRequired, IN, osg::PrimitiveSet *, primitiveSet,
Properties::NON_VIRTUAL,
Properties::NON_CONST,
__void__addElementsBufferObjectIfRequired__osg_PrimitiveSet_P1,
"",
"");
I_SimpleProperty(osg::Array *, ColorArray,
__Array_P1__getColorArray,
__void__setColorArray__Array_P1);
@ -760,8 +807,8 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
0,
0,
0);
I_SimpleProperty(osg::Geometry::ArrayList &, TexCoordArrayList,
__ArrayList_R1__getTexCoordArrayList,
I_SimpleProperty(osg::Geometry::ArrayDataList &, TexCoordArrayList,
__ArrayDataList_R1__getTexCoordArrayList,
0);
I_ArrayProperty(const osg::Geometry::ArrayData &, TexCoordData,
__C5_ArrayData_R1__getTexCoordData__unsigned_int,
@ -777,6 +824,9 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
0,
0,
0);
I_SimpleProperty(bool, UseVertexBufferObjects,
0,
__void__setUseVertexBufferObjects__bool);
I_SimpleProperty(osg::Array *, VertexArray,
__Array_P1__getVertexArray,
__void__setVertexArray__Array_P1);
@ -787,8 +837,8 @@ BEGIN_OBJECT_REFLECTOR(osg::Geometry)
0,
0,
0);
I_SimpleProperty(osg::Geometry::ArrayList &, VertexAttribArrayList,
__ArrayList_R1__getVertexAttribArrayList,
I_SimpleProperty(osg::Geometry::ArrayDataList &, VertexAttribArrayList,
__ArrayDataList_R1__getVertexAttribArrayList,
0);
I_ArrayProperty(osg::Geometry::AttributeBinding, VertexAttribBinding,
__AttributeBinding__getVertexAttribBinding__unsigned_int,
@ -921,6 +971,10 @@ BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osg::PrimitiveSet >)
0);
END_REFLECTOR
STD_VECTOR_REFLECTOR(std::vector< osg::Array * >)
STD_VECTOR_REFLECTOR(std::vector< osg::DrawElements * >)
STD_VECTOR_REFLECTOR(std::vector< osg::Geometry::ArrayData >)
STD_VECTOR_REFLECTOR(std::vector< osg::ref_ptr< osg::PrimitiveSet > >)

View File

@ -241,6 +241,16 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::DrawElements)
____DrawElements__C5_DrawElements_R1__C5_CopyOp_R1,
"",
"");
I_Method0(osg::DrawElements *, getDrawElements,
Properties::VIRTUAL,
__DrawElements_P1__getDrawElements,
"",
"");
I_Method0(const osg::DrawElements *, getDrawElements,
Properties::VIRTUAL,
__C5_DrawElements_P1__getDrawElements,
"",
"");
I_Method1(void, setElementsBufferObject, IN, osg::ElementsBufferObject *, ebo,
Properties::NON_VIRTUAL,
__void__setElementsBufferObject__osg_ElementsBufferObject_P1,
@ -266,6 +276,9 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::DrawElements)
__unsigned_int__getElementsBufferObjectIndex,
"Get the index into the ElementsBufferObject, if used. ",
"");
I_SimpleProperty(osg::DrawElements *, DrawElements,
__DrawElements_P1__getDrawElements,
0);
I_SimpleProperty(osg::ElementsBufferObject *, ElementsBufferObject,
__osg_ElementsBufferObject_P1__getElementsBufferObject,
__void__setElementsBufferObject__osg_ElementsBufferObject_P1);
@ -823,6 +836,16 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::PrimitiveSet)
__bool__supportsBufferObject,
"",
"");
I_Method0(osg::DrawElements *, getDrawElements,
Properties::VIRTUAL,
__DrawElements_P1__getDrawElements,
"",
"");
I_Method0(const osg::DrawElements *, getDrawElements,
Properties::VIRTUAL,
__C5_DrawElements_P1__getDrawElements,
"",
"");
I_Method1(void, setMode, IN, GLenum, mode,
Properties::NON_VIRTUAL,
__void__setMode__GLenum,
@ -901,6 +924,9 @@ BEGIN_ABSTRACT_OBJECT_REFLECTOR(osg::PrimitiveSet)
I_SimpleProperty(const GLvoid *, DataPointer,
__C5_GLvoid_P1__getDataPointer,
0);
I_SimpleProperty(osg::DrawElements *, DrawElements,
__DrawElements_P1__getDrawElements,
0);
I_SimpleProperty(GLenum, Mode,
__GLenum__getMode,
__void__setMode__GLenum);