Converted the template DrawElements primitive class into three seperate

non templated classes - UByteDrawElements, UShortDrawElements, UIntDrawElements.
This commit is contained in:
Robert Osfield
2002-06-27 13:15:34 +00:00
parent 532a32416f
commit fb3e705709
7 changed files with 242 additions and 163 deletions

View File

@@ -15,86 +15,87 @@
namespace osg {
enum ArrayType
{
AttributeArrayType = 0,
ByteArrayType = 1,
ShortArrayType = 2,
IntArrayType = 3,
UByteArrayType = 4,
UShortArrayType = 5,
UIntArrayType = 6,
UByte4ArrayType = 7,
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11
};
class SG_EXPORT AttributeArray : public Object
class SG_EXPORT Array : public Object
{
public:
AttributeArray(ArrayType arrayType=AttributeArrayType,GLint dataSize=0,GLenum dataType=0):
enum Type
{
ArrayType = 0,
ByteArrayType = 1,
ShortArrayType = 2,
IntArrayType = 3,
UByteArrayType = 4,
UShortArrayType = 5,
UIntArrayType = 6,
UByte4ArrayType = 7,
FloatArrayType = 8,
Vec2ArrayType = 9,
Vec3ArrayType = 10,
Vec4ArrayType = 11
};
Array(Type arrayType=ArrayType,GLint dataSize=0,GLenum dataType=0):
_arrayType(arrayType),
_dataSize(dataSize),
_dataType(dataType) {}
AttributeArray(const AttributeArray& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Array(const Array& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(array,copyop),
_arrayType(array._arrayType),
_dataSize(array._dataSize),
_dataType(array._dataType) {}
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const AttributeArray*>(obj)!=NULL; }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Array*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const;
ArrayType arrayType() const { return _arrayType; }
Type getType() const { return _arrayType; }
GLint dataSize() const { return _dataSize; }
GLenum dataType() const { return _dataType; }
virtual const GLvoid* dataPointer() const = 0;
protected:
virtual ~AttributeArray() {}
virtual ~Array() {}
ArrayType _arrayType;
Type _arrayType;
GLint _dataSize;
GLenum _dataType;
};
template<typename T, ArrayType ARRAYTYPE, int DataSize, int DataType>
class TemplateArray : public AttributeArray, public std::vector<T>
template<typename T, Array::Type ARRAYTYPE, int DataSize, int DataType>
class TemplateArray : public Array, public std::vector<T>
{
public:
TemplateArray() : AttributeArray(ARRAYTYPE,DataSize,DataType) {}
TemplateArray() : Array(ARRAYTYPE,DataSize,DataType) {}
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
AttributeArray(ta,copyop),
Array(ta,copyop),
std::vector<T>(ta) {}
TemplateArray(unsigned int no) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
Array(ARRAYTYPE,DataSize,DataType),
std::vector<T>(no) {}
TemplateArray(unsigned int no,T* ptr) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
Array(ARRAYTYPE,DataSize,DataType),
std::vector<T>(ptr,ptr+no) {}
template <class InputIterator>
TemplateArray(InputIterator first,InputIterator last) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
Array(ARRAYTYPE,DataSize,DataType),
std::vector<T>(first,last) {}
// TemplateArray(T* first,T* last) :
// AttributeArray(ARRAYTYPE,DataSize,DataType),
// Array(ARRAYTYPE,DataSize,DataType),
// std::vector<T>(first,last) {}
virtual Object* cloneType() const { return osgNew TemplateArray(); }
@@ -103,17 +104,17 @@ class TemplateArray : public AttributeArray, public std::vector<T>
virtual const GLvoid* dataPointer() const { if (!empty()) return &front(); else return 0; }
};
typedef TemplateArray<char,ByteArrayType,1,GL_BYTE> ByteArray;
typedef TemplateArray<short,ShortArrayType,1,GL_SHORT> ShortArray;
typedef TemplateArray<int,IntArrayType,1,GL_INT> IntArray;
typedef TemplateArray<unsigned char,UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
typedef TemplateArray<unsigned short,UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
typedef TemplateArray<unsigned int,UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
typedef TemplateArray<unsigned int,UByte4ArrayType,4,GL_UNSIGNED_BYTE> UByte4Array;
typedef TemplateArray<float,FloatArrayType,1,GL_FLOAT> FloatArray;
typedef TemplateArray<Vec2,Vec2ArrayType,2,GL_FLOAT> Vec2Array;
typedef TemplateArray<Vec3,Vec3ArrayType,3,GL_FLOAT> Vec3Array;
typedef TemplateArray<Vec4,Vec4ArrayType,4,GL_FLOAT> Vec4Array;
typedef TemplateArray<char,Array::ByteArrayType,1,GL_BYTE> ByteArray;
typedef TemplateArray<short,Array::ShortArrayType,1,GL_SHORT> ShortArray;
typedef TemplateArray<int,Array::IntArrayType,1,GL_INT> IntArray;
typedef TemplateArray<unsigned char,Array::UByteArrayType,1,GL_UNSIGNED_BYTE> UByteArray;
typedef TemplateArray<unsigned short,Array::UShortArrayType,1,GL_UNSIGNED_SHORT> UShortArray;
typedef TemplateArray<unsigned int,Array::UIntArrayType,1,GL_UNSIGNED_INT> UIntArray;
typedef TemplateArray<unsigned int,Array::UByte4ArrayType,4,GL_UNSIGNED_BYTE> UByte4Array;
typedef TemplateArray<float,Array::FloatArrayType,1,GL_FLOAT> FloatArray;
typedef TemplateArray<Vec2,Array::Vec2ArrayType,2,GL_FLOAT> Vec2Array;
typedef TemplateArray<Vec3,Array::Vec3ArrayType,3,GL_FLOAT> Vec3Array;
typedef TemplateArray<Vec4,Array::Vec4ArrayType,4,GL_FLOAT> Vec4Array;
}

View File

@@ -54,17 +54,17 @@ class SG_EXPORT Geometry : public Drawable
void setColorBinding(AttributeBinding ab) { _colorBinding = ab; }
AttributeBinding getColorBinding() const { return _colorBinding; }
void setColorArray(AttributeArray* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; dirtyDisplayList(); }
AttributeArray* getColorArray() { return _colorArray.get(); }
const AttributeArray* getColorArray() const { return _colorArray.get(); }
void setColorArray(Array* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; dirtyDisplayList(); }
Array* getColorArray() { return _colorArray.get(); }
const Array* getColorArray() const { return _colorArray.get(); }
typedef std::vector< ref_ptr<AttributeArray> > TexCoordArrayList;
typedef std::vector< ref_ptr<Array> > TexCoordArrayList;
void setTexCoordArray(unsigned int unit,AttributeArray*);
AttributeArray* getTexCoordArray(unsigned int unit);
const AttributeArray* getTexCoordArray(unsigned int unit) const;
void setTexCoordArray(unsigned int unit,Array*);
Array* getTexCoordArray(unsigned int unit);
const Array* getTexCoordArray(unsigned int unit) const;
unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); }
TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; }
@@ -118,7 +118,7 @@ class SG_EXPORT Geometry : public Drawable
ref_ptr<Vec3Array> _normalArray;
AttributeBinding _colorBinding;
ref_ptr<AttributeArray> _colorArray;
ref_ptr<Array> _colorArray;
TexCoordArrayList _texCoordList;

View File

@@ -9,19 +9,20 @@
namespace osg {
enum PrimitiveType
{
PrimitivePrimitiveType = 0,
DrawArraysPrimitiveType = 1,
UByteDrawElementsPrimitiveType = 2,
UShortDrawElementsPrimitiveType = 3,
UIntDrawElementsPrimitiveType = 4,
};
class SG_EXPORT Primitive : public Object
class Primitive : public Object
{
public:
enum Type
{
PrimitiveType = 0,
DrawArraysPrimitiveType = 1,
UByteDrawElementsPrimitiveType = 2,
UShortDrawElementsPrimitiveType = 3,
UIntDrawElementsPrimitiveType = 4,
};
enum Mode
{
POINTS = GL_POINTS,
@@ -36,7 +37,7 @@ class SG_EXPORT Primitive : public Object
POLYGON = GL_POLYGON
};
Primitive(PrimitiveType primType=PrimitivePrimitiveType,GLenum mode=0):
Primitive(Type primType=PrimitiveType,GLenum mode=0):
_primitiveType(primType),
_mode(mode) {}
@@ -47,9 +48,9 @@ class SG_EXPORT Primitive : public Object
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Primitive*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const;
virtual const char* className() const { return "Primitve"; }
PrimitiveType primitiveType() const { return _primitiveType; }
Type getType() const { return _primitiveType; }
void setMode(GLenum mode) { _mode = mode; }
GLenum getMode() const { return _mode; }
@@ -60,16 +61,16 @@ class SG_EXPORT Primitive : public Object
protected:
PrimitiveType _primitiveType;
Type _primitiveType;
GLenum _mode;
};
class DrawArrays : public Primitive
class SG_EXPORT DrawArrays : public Primitive
{
public:
DrawArrays(GLenum mode=0):
Primitive(DrawArraysPrimitiveType,0)
Primitive(DrawArraysPrimitiveType,mode)
{}
DrawArrays(GLenum mode, GLint first, GLsizei count):
@@ -102,71 +103,122 @@ class DrawArrays : public Primitive
void setCount(GLsizei count) { _count = count; }
GLsizei getCount() const { return _count; }
virtual void draw() const
{
glDrawArrays(_mode,_first,_count);
}
virtual void draw() const;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
functor.drawArrays(_mode,_first,_count);
}
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
protected:
GLint _first;
GLsizei _count;
};
template<typename T, PrimitiveType PRIMTYPE, int DataType>
class DrawElements : public Primitive, public std::vector<T>
class SG_EXPORT UByteDrawElements : public Primitive, public std::vector<unsigned char>
{
public:
DrawElements(GLenum mode=0):
Primitive(PRIMTYPE,mode),
_dataType(DataType) {}
UByteDrawElements(GLenum mode=0):
Primitive(UByteDrawElementsPrimitiveType,mode) {}
DrawElements(const DrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
UByteDrawElements(const UByteDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<T>(array),
_dataType(array._dataType) {}
std::vector<unsigned char>(array) {}
DrawElements(GLenum mode,unsigned int no,T* ptr) :
Primitive(PRIMTYPE,mode),
std::vector<T>(ptr,ptr+no),
_dataType(DataType) {}
UByteDrawElements(GLenum mode,unsigned int no,unsigned char* ptr) :
Primitive(UByteDrawElementsPrimitiveType,mode),
std::vector<unsigned char>(ptr,ptr+no) {}
DrawElements(GLenum mode,unsigned int no) :
Primitive(PRIMTYPE,mode),
std::vector<T>(no),
_dataType(DataType) {}
UByteDrawElements(GLenum mode,unsigned int no) :
Primitive(UByteDrawElementsPrimitiveType,mode),
std::vector<unsigned char>(no) {}
template <class InputIterator>
DrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(PRIMTYPE,mode),
std::vector<T>(first,last),
_dataType(DataType) {}
UByteDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UByteDrawElementsPrimitiveType,mode),
std::vector<unsigned char>(first,last) {}
virtual Object* cloneType() const { return osgNew DrawElements(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawElements(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElements*>(obj)!=NULL; }
virtual Object* cloneType() const { return osgNew UByteDrawElements(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew UByteDrawElements(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UByteDrawElements*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UByteDrawElements"; }
virtual void draw() const
{
glDrawElements(_mode,size(),_dataType,&front());
}
virtual void draw() const ;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
if (!empty()) functor.drawElements(_mode,size(),&front());
}
GLenum _dataType;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
};
class SG_EXPORT UShortDrawElements : public Primitive, public std::vector<unsigned short>
{
public:
UShortDrawElements(GLenum mode=0):
Primitive(UShortDrawElementsPrimitiveType,mode) {}
UShortDrawElements(const UShortDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<unsigned short>(array) {}
UShortDrawElements(GLenum mode,unsigned int no,unsigned short* ptr) :
Primitive(UShortDrawElementsPrimitiveType,mode),
std::vector<unsigned short>(ptr,ptr+no) {}
UShortDrawElements(GLenum mode,unsigned int no) :
Primitive(UShortDrawElementsPrimitiveType,mode),
std::vector<unsigned short>(no) {}
template <class InputIterator>
UShortDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UShortDrawElementsPrimitiveType,mode),
std::vector<unsigned short>(first,last) {}
virtual Object* cloneType() const { return osgNew UShortDrawElements(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew UShortDrawElements(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UShortDrawElements*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UShortDrawElements"; }
virtual void draw() const;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
};
class UIntDrawElements : public Primitive, public std::vector<unsigned int>
{
public:
UIntDrawElements(GLenum mode=0):
Primitive(UIntDrawElementsPrimitiveType,mode) {}
UIntDrawElements(const UIntDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<unsigned int>(array) {}
UIntDrawElements(GLenum mode,unsigned int no,unsigned int* ptr) :
Primitive(UIntDrawElementsPrimitiveType,mode),
std::vector<unsigned int>(ptr,ptr+no) {}
UIntDrawElements(GLenum mode,unsigned int no) :
Primitive(UIntDrawElementsPrimitiveType,mode),
std::vector<unsigned int>(no) {}
template <class InputIterator>
UIntDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UIntDrawElementsPrimitiveType,mode),
std::vector<unsigned int>(first,last) {}
virtual Object* cloneType() const { return osgNew UIntDrawElements(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew UIntDrawElements(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const UIntDrawElements*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UIntDrawElements"; }
virtual void draw() const;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
};
typedef DrawElements<unsigned char,UByteDrawElementsPrimitiveType,GL_UNSIGNED_BYTE> UByteDrawElements;
typedef DrawElements<unsigned short,UShortDrawElementsPrimitiveType,GL_UNSIGNED_SHORT> UShortDrawElements;
typedef DrawElements<unsigned int,UIntDrawElementsPrimitiveType,GL_UNSIGNED_INT> UIntDrawElements;
}
#endif