Added VertexBufferObject and ElementBufferObject class interfaces, and wired

up osg::Array and osg::DrawElements* to these respectively.

Updated wrappers
This commit is contained in:
Robert Osfield
2007-04-25 18:50:11 +00:00
parent 2ca0075426
commit 4b71e3948b
7 changed files with 465 additions and 29 deletions

View File

@@ -27,6 +27,7 @@
#include <osg/Vec3b>
#include <osg/Vec4b>
#include <osg/BufferObject>
#include <osg/Object>
#include <osg/GL>
@@ -71,14 +72,16 @@ class OSG_EXPORT Array : public Object
_arrayType(arrayType),
_dataSize(dataSize),
_dataType(dataType),
_modifiedCount(0) {}
_modifiedCount(0),
_vboIndex(0) {}
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(array,copyop),
_arrayType(array._arrayType),
_dataSize(array._dataSize),
_dataType(array._dataType),
_modifiedCount(0) {}
_modifiedCount(0),
_vboIndex(0) {}
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
@@ -113,14 +116,31 @@ class OSG_EXPORT Array : public Object
/** Get modified count value.*/
inline unsigned int getModifiedCount() const { return _modifiedCount; }
/** Set the VertexBufferObject.*/
inline void setVertexBufferObject(osg::VertexBufferObject* vbo) { _vbo = vbo; }
/** Get the VertexBufferObject. If no VBO is assigned returns NULL*/
inline osg::VertexBufferObject* getVertexBufferObject() { return _vbo.get(); }
/** Get the const VertexBufferObject. If no VBO is assigned returns NULL*/
inline const osg::VertexBufferObject* getVertexBufferObject() const { return _vbo.get(); }
/** Set the index into the VertexBufferObject, if used.*/
inline void setVertexBufferObjectIndex(unsigned int index) { _vboIndex = index; }
/** Get the index into the VertexBufferObject, if used.*/
inline unsigned int getVertexBufferObjectIndex() const { return _vboIndex; }
protected:
virtual ~Array() {}
Type _arrayType;
GLint _dataSize;
GLenum _dataType;
unsigned int _modifiedCount;
Type _arrayType;
GLint _dataSize;
GLenum _dataType;
unsigned int _modifiedCount;
osg::ref_ptr<osg::VertexBufferObject> _vbo;
unsigned int _vboIndex;
};
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>

View File

@@ -216,9 +216,6 @@ class OSG_EXPORT BufferObject : public Object
typedef osg::buffered_value<GLuint> GLObjectList;
typedef std::pair< BufferEntry, ref_ptr<Array> > BufferEntryArrayPair;
typedef std::pair< BufferEntry, ref_ptr<PrimitiveSet> > BufferEntryPrimitiveSetPair;
mutable GLObjectList _bufferObjectList;
GLenum _target;
@@ -226,6 +223,70 @@ class OSG_EXPORT BufferObject : public Object
mutable unsigned int _totalSize;
};
class Array;
class OSG_EXPORT VertexBufferObject : public BufferObject
{
public:
VertexBufferObject();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
VertexBufferObject(const VertexBufferObject& vbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg,VertexBufferObject);
typedef std::pair< BufferEntry, Array* > BufferEntryArrayPair;
typedef std::vector< BufferEntryArrayPair > BufferEntryArrayPairs;
unsigned int addArray(osg::Array* array);
void setArray(unsigned int i, Array* array);
Array* getArray(unsigned int i) { return _bufferEntryArrayPairs[i].second; }
const Array* getArray(unsigned int i) const { return _bufferEntryArrayPairs[i].second; }
virtual bool needsCompile(unsigned int contextID) const;
virtual void compileBuffer(State& state) const;
protected:
virtual ~VertexBufferObject();
BufferEntryArrayPairs _bufferEntryArrayPairs;
};
class DrawElements;
class OSG_EXPORT ElementsBufferObject : public BufferObject
{
public:
ElementsBufferObject();
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
ElementsBufferObject(const ElementsBufferObject& pbo,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Object(osg,ElementsBufferObject);
typedef std::pair< BufferEntry, DrawElements* > BufferEntryDrawElementstPair;
typedef std::vector< BufferEntryDrawElementstPair > BufferEntryDrawElementsPairs;
unsigned int addDrawElements(osg::DrawElements* PrimitiveSet);
void setDrawElements(unsigned int i, DrawElements* PrimitiveSet);
DrawElements* getDrawElements(unsigned int i) { return _bufferEntryDrawElementsPairs[i].second; }
const DrawElements* getDrawElements(unsigned int i) const { return _bufferEntryDrawElementsPairs[i].second; }
virtual bool needsCompile(unsigned int contextID) const;
virtual void compileBuffer(State& state) const;
protected:
virtual ~ElementsBufferObject();
BufferEntryDrawElementsPairs _bufferEntryDrawElementsPairs;
};
class Image;
class OSG_EXPORT PixelBufferObject : public BufferObject
{

View File

@@ -21,6 +21,8 @@
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/BufferObject>
#include <vector>
namespace osg {
@@ -400,25 +402,60 @@ class OSG_EXPORT DrawArrayLengths : public PrimitiveSet, public VectorGLsizei
GLint _first;
};
class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte
class DrawElements : public PrimitiveSet
{
public:
DrawElements(Type primType=PrimitiveType, GLenum mode=0):
PrimitiveSet(primType,mode),
_eboIndex(0) {}
DrawElements(const DrawElements& copy,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
PrimitiveSet(copy,copyop),
_eboIndex(0) {}
/** Set the ElementsBufferObject.*/
inline void setElementsBufferObject(osg::ElementsBufferObject* ebo) { _ebo = ebo; }
/** Get the ElementsBufferObject. If no EBO is assigned returns NULL*/
inline osg::ElementsBufferObject* getElementsBufferObject() { return _ebo.get(); }
/** Get the const ElementsBufferObject. If no EBO is assigned returns NULL*/
inline const osg::ElementsBufferObject* getElementsBufferObject() const { return _ebo.get(); }
/** Set the index into the ElementsBufferObject, if used.*/
inline void setElementsBufferObjectIndex(unsigned int index) { _eboIndex = index; }
/** Get the index into the ElementsBufferObject, if used.*/
inline unsigned int getElementsBufferObjectIndex() const { return _eboIndex; }
protected:
osg::ref_ptr<ElementsBufferObject> _ebo;
unsigned int _eboIndex;
};
class OSG_EXPORT DrawElementsUByte : public DrawElements, public VectorGLubyte
{
public:
typedef VectorGLubyte vector_type;
DrawElementsUByte(GLenum mode=0):
PrimitiveSet(DrawElementsUBytePrimitiveType,mode) {}
DrawElements(DrawElementsUBytePrimitiveType,mode) {}
DrawElementsUByte(const DrawElementsUByte& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
PrimitiveSet(array,copyop),
DrawElements(array,copyop),
vector_type(array) {}
DrawElementsUByte(GLenum mode,unsigned int no,GLubyte* ptr) :
PrimitiveSet(DrawElementsUBytePrimitiveType,mode),
DrawElements(DrawElementsUBytePrimitiveType,mode),
vector_type(ptr,ptr+no) {}
DrawElementsUByte(GLenum mode,unsigned int no) :
PrimitiveSet(DrawElementsUBytePrimitiveType,mode),
DrawElements(DrawElementsUBytePrimitiveType,mode),
vector_type(no) {}
virtual Object* cloneType() const { return new DrawElementsUByte(); }
@@ -478,30 +515,30 @@ class OSG_EXPORT DrawElementsUByte : public PrimitiveSet, public VectorGLubyte
};
class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort
class OSG_EXPORT DrawElementsUShort : public DrawElements, public VectorGLushort
{
public:
typedef VectorGLushort vector_type;
DrawElementsUShort(GLenum mode=0):
PrimitiveSet(DrawElementsUShortPrimitiveType,mode) {}
DrawElements(DrawElementsUShortPrimitiveType,mode) {}
DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
PrimitiveSet(array,copyop),
DrawElements(array,copyop),
vector_type(array) {}
DrawElementsUShort(GLenum mode,unsigned int no,GLushort* ptr) :
PrimitiveSet(DrawElementsUShortPrimitiveType,mode),
DrawElements(DrawElementsUShortPrimitiveType,mode),
vector_type(ptr,ptr+no) {}
DrawElementsUShort(GLenum mode,unsigned int no) :
PrimitiveSet(DrawElementsUShortPrimitiveType,mode),
DrawElements(DrawElementsUShortPrimitiveType,mode),
vector_type(no) {}
template <class InputIterator>
DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) :
PrimitiveSet(DrawElementsUShortPrimitiveType,mode),
DrawElements(DrawElementsUShortPrimitiveType,mode),
vector_type(first,last) {}
virtual Object* cloneType() const { return new DrawElementsUShort(); }
@@ -559,30 +596,30 @@ class OSG_EXPORT DrawElementsUShort : public PrimitiveSet, public VectorGLushort
mutable GLObjectList _vboList;
};
class OSG_EXPORT DrawElementsUInt : public PrimitiveSet, public VectorGLuint
class OSG_EXPORT DrawElementsUInt : public DrawElements, public VectorGLuint
{
public:
typedef VectorGLuint vector_type;
DrawElementsUInt(GLenum mode=0):
PrimitiveSet(DrawElementsUIntPrimitiveType,mode) {}
DrawElements(DrawElementsUIntPrimitiveType,mode) {}
DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
PrimitiveSet(array,copyop),
DrawElements(array,copyop),
vector_type(array) {}
DrawElementsUInt(GLenum mode,unsigned int no,GLuint* ptr) :
PrimitiveSet(DrawElementsUIntPrimitiveType,mode),
DrawElements(DrawElementsUIntPrimitiveType,mode),
vector_type(ptr,ptr+no) {}
DrawElementsUInt(GLenum mode,unsigned int no) :
PrimitiveSet(DrawElementsUIntPrimitiveType,mode),
DrawElements(DrawElementsUIntPrimitiveType,mode),
vector_type(no) {}
template <class InputIterator>
DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) :
PrimitiveSet(DrawElementsUIntPrimitiveType,mode),
DrawElements(DrawElementsUIntPrimitiveType,mode),
vector_type(first,last) {}
virtual Object* cloneType() const { return new DrawElementsUInt(); }