Moved the AttributeArray and Primitive classes into their own header and

source files.
This commit is contained in:
Robert Osfield 2002-06-27 10:50:19 +00:00
parent 726d680184
commit 532a32416f
9 changed files with 363 additions and 316 deletions

View File

@ -101,6 +101,10 @@ SOURCE=..\..\src\osg\AnimationPath.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Array.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Billboard.cpp
# End Source File
# Begin Source File
@ -309,6 +313,10 @@ SOURCE=..\..\src\osg\PositionAttitudeTransform.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Primitive.cpp
# End Source File
# Begin Source File
SOURCE=..\..\src\osg\Projection.cpp
# End Source File
# Begin Source File
@ -393,6 +401,10 @@ SOURCE=..\..\Include\Osg\AnimationPath
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Array
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Billboard
# End Source File
# Begin Source File
@ -637,6 +649,10 @@ SOURCE=..\..\Include\Osg\Projection
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Primitive
# End Source File
# Begin Source File
SOURCE=..\..\Include\Osg\Quat
# End Source File
# Begin Source File

120
include/osg/Array Normal file
View File

@ -0,0 +1,120 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_ARRAY
#define OSG_ARRAY 1
#include <osg/Object>
#include <osg/GL>
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <vector>
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
{
public:
AttributeArray(ArrayType arrayType=AttributeArrayType,GLint dataSize=0,GLenum dataType=0):
_arrayType(arrayType),
_dataSize(dataSize),
_dataType(dataType) {}
AttributeArray(const AttributeArray& 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 const char* libraryName() const { return "osg"; }
virtual const char* className() const;
ArrayType arrayType() const { return _arrayType; }
GLint dataSize() const { return _dataSize; }
GLenum dataType() const { return _dataType; }
virtual const GLvoid* dataPointer() const = 0;
protected:
virtual ~AttributeArray() {}
ArrayType _arrayType;
GLint _dataSize;
GLenum _dataType;
};
template<typename T, ArrayType ARRAYTYPE, int DataSize, int DataType>
class TemplateArray : public AttributeArray, public std::vector<T>
{
public:
TemplateArray() : AttributeArray(ARRAYTYPE,DataSize,DataType) {}
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
AttributeArray(ta,copyop),
std::vector<T>(ta) {}
TemplateArray(unsigned int no) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(no) {}
TemplateArray(unsigned int no,T* ptr) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(ptr,ptr+no) {}
template <class InputIterator>
TemplateArray(InputIterator first,InputIterator last) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(first,last) {}
// TemplateArray(T* first,T* last) :
// AttributeArray(ARRAYTYPE,DataSize,DataType),
// std::vector<T>(first,last) {}
virtual Object* cloneType() const { return osgNew TemplateArray(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); }
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;
}
#endif

View File

@ -9,281 +9,11 @@
#include <osg/Vec2>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Array>
#include <osg/Primitive>
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
{
public:
AttributeArray(ArrayType arrayType=AttributeArrayType,GLint dataSize=0,GLenum dataType=0):
_arrayType(arrayType),
_dataSize(dataSize),
_dataType(dataType) {}
AttributeArray(const AttributeArray& 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 const char* libraryName() const { return "osg"; }
virtual const char* className() const;
ArrayType arrayType() const { return _arrayType; }
GLint dataSize() const { return _dataSize; }
GLenum dataType() const { return _dataType; }
virtual const GLvoid* dataPointer() const = 0;
protected:
virtual ~AttributeArray() {}
ArrayType _arrayType;
GLint _dataSize;
GLenum _dataType;
};
template<typename T, ArrayType ARRAYTYPE, int DataSize, int DataType>
class TemplateArray : public AttributeArray, public std::vector<T>
{
public:
TemplateArray() : AttributeArray(ARRAYTYPE,DataSize,DataType) {}
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
AttributeArray(ta,copyop),
std::vector<T>(ta) {}
TemplateArray(unsigned int no) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(no) {}
TemplateArray(unsigned int no,T* ptr) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(ptr,ptr+no) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
TemplateArray(InputIterator first,InputIterator last) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(first,last) {}
#else
TemplateArray(T* first,T* last) :
AttributeArray(ARRAYTYPE,DataSize,DataType),
std::vector<T>(first,last) {}
#endif
virtual Object* cloneType() const { return osgNew TemplateArray(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); }
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;
/* ******************************************************************************************************************* */
enum PrimitiveType
{
PrimitivePrimitiveType = 0,
DrawArraysPrimitiveType = 1,
UByteDrawElementsPrimitiveType = 2,
UShortDrawElementsPrimitiveType = 3,
UIntDrawElementsPrimitiveType = 4,
};
class SG_EXPORT Primitive : public Object
{
public:
enum Mode
{
POINTS = GL_POINTS,
LINES = GL_LINES,
LINE_STRIP = GL_LINE_STRIP,
LINE_LOOP = GL_LINE_LOOP,
TRIANGLES = GL_TRIANGLES,
TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
TRIANGLE_FAN = GL_TRIANGLE_FAN,
QUADS = GL_QUADS,
QUAD_STRIP = GL_QUAD_STRIP,
POLYGON = GL_POLYGON
};
Primitive(PrimitiveType primType=PrimitivePrimitiveType,GLenum mode=0):
_primitiveType(primType),
_mode(mode) {}
Primitive(const Primitive& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(prim,copyop),
_primitiveType(prim._primitiveType),
_mode(prim._mode) {}
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;
PrimitiveType primitiveType() const { return _primitiveType; }
void setMode(GLenum mode) { _mode = mode; }
GLenum getMode() const { return _mode; }
virtual void draw() const = 0;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor&) {}
protected:
PrimitiveType _primitiveType;
GLenum _mode;
};
class DrawArrays : public Primitive
{
public:
DrawArrays():
Primitive(DrawArraysPrimitiveType,0)
{}
DrawArrays(GLenum mode, GLint first, GLsizei count):
Primitive(DrawArraysPrimitiveType,mode),
_first(first),
_count(count) {}
DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(da,copyop),
_first(da._first),
_count(da._count) {}
virtual Object* cloneType() const { return osgNew DrawArrays(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawArrays(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrays*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "DrawArrays"; }
void set(GLenum mode,GLint first, GLsizei count)
{
_mode = mode;
_first = first;
_count = count;
}
void setFirst(GLint first) { _first = first; }
GLint getFirst() const { return _first; }
void setCount(GLsizei count) { _count = count; }
GLsizei getCount() const { return _count; }
virtual void draw() const
{
glDrawArrays(_mode,_first,_count);
}
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
functor.drawArrays(_mode,_first,_count);
}
GLint _first;
GLsizei _count;
};
template<typename T, PrimitiveType PRIMTYPE, int DataType>
class DrawElements : public Primitive, public std::vector<T>
{
public:
DrawElements(GLenum mode=0):
Primitive(PRIMTYPE,mode),
_dataType(DataType) {}
DrawElements(const DrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<T>(array),
_dataType(array._dataType) {}
DrawElements(GLenum mode,unsigned int no,T* ptr) :
Primitive(PRIMTYPE,mode),
std::vector<T>(ptr,ptr+no),
_dataType(DataType) {}
DrawElements(GLenum mode,unsigned int no) :
Primitive(PRIMTYPE,mode),
std::vector<T>(no),
_dataType(DataType) {}
#ifdef __STL_MEMBER_TEMPLATES
template <class InputIterator>
DrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(PRIMTYPE,mode),
std::vector<T>(first,last),
_dataType(DataType) {}
#else
DrawElements(GLenum mode, T* first,T* last) :
Primitive(PRIMTYPE,mode),
std::vector<T>(first,last),
_dataType(DataType) {}
#endif
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 const char* libraryName() const { return "osg"; }
virtual void draw() const
{
glDrawElements(_mode,size(),_dataType,&front());
}
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
if (!empty()) functor.drawElements(_mode,size(),&front());
}
GLenum _dataType;
};
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;
/* ******************************************************************************************************************* */
class SG_EXPORT Geometry : public Drawable
{

172
include/osg/Primitive Normal file
View File

@ -0,0 +1,172 @@
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_PRIMTIVE
#define OSG_PRIMTIVE 1
#include <osg/Drawable>
namespace osg {
enum PrimitiveType
{
PrimitivePrimitiveType = 0,
DrawArraysPrimitiveType = 1,
UByteDrawElementsPrimitiveType = 2,
UShortDrawElementsPrimitiveType = 3,
UIntDrawElementsPrimitiveType = 4,
};
class SG_EXPORT Primitive : public Object
{
public:
enum Mode
{
POINTS = GL_POINTS,
LINES = GL_LINES,
LINE_STRIP = GL_LINE_STRIP,
LINE_LOOP = GL_LINE_LOOP,
TRIANGLES = GL_TRIANGLES,
TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
TRIANGLE_FAN = GL_TRIANGLE_FAN,
QUADS = GL_QUADS,
QUAD_STRIP = GL_QUAD_STRIP,
POLYGON = GL_POLYGON
};
Primitive(PrimitiveType primType=PrimitivePrimitiveType,GLenum mode=0):
_primitiveType(primType),
_mode(mode) {}
Primitive(const Primitive& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Object(prim,copyop),
_primitiveType(prim._primitiveType),
_mode(prim._mode) {}
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;
PrimitiveType primitiveType() const { return _primitiveType; }
void setMode(GLenum mode) { _mode = mode; }
GLenum getMode() const { return _mode; }
virtual void draw() const = 0;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor&) {}
protected:
PrimitiveType _primitiveType;
GLenum _mode;
};
class DrawArrays : public Primitive
{
public:
DrawArrays(GLenum mode=0):
Primitive(DrawArraysPrimitiveType,0)
{}
DrawArrays(GLenum mode, GLint first, GLsizei count):
Primitive(DrawArraysPrimitiveType,mode),
_first(first),
_count(count) {}
DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(da,copyop),
_first(da._first),
_count(da._count) {}
virtual Object* cloneType() const { return osgNew DrawArrays(); }
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawArrays(*this,copyop); }
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrays*>(obj)!=NULL; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "DrawArrays"; }
void set(GLenum mode,GLint first, GLsizei count)
{
_mode = mode;
_first = first;
_count = count;
}
void setFirst(GLint first) { _first = first; }
GLint getFirst() const { return _first; }
void setCount(GLsizei count) { _count = count; }
GLsizei getCount() const { return _count; }
virtual void draw() const
{
glDrawArrays(_mode,_first,_count);
}
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
functor.drawArrays(_mode,_first,_count);
}
GLint _first;
GLsizei _count;
};
template<typename T, PrimitiveType PRIMTYPE, int DataType>
class DrawElements : public Primitive, public std::vector<T>
{
public:
DrawElements(GLenum mode=0):
Primitive(PRIMTYPE,mode),
_dataType(DataType) {}
DrawElements(const DrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<T>(array),
_dataType(array._dataType) {}
DrawElements(GLenum mode,unsigned int no,T* ptr) :
Primitive(PRIMTYPE,mode),
std::vector<T>(ptr,ptr+no),
_dataType(DataType) {}
DrawElements(GLenum mode,unsigned int no) :
Primitive(PRIMTYPE,mode),
std::vector<T>(no),
_dataType(DataType) {}
template <class InputIterator>
DrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(PRIMTYPE,mode),
std::vector<T>(first,last),
_dataType(DataType) {}
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 const char* libraryName() const { return "osg"; }
virtual void draw() const
{
glDrawElements(_mode,size(),_dataType,&front());
}
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor)
{
if (!empty()) functor.drawElements(_mode,size(),&front());
}
GLenum _dataType;
};
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

View File

@ -20,7 +20,6 @@ Node *makeBase( void )
Vec3Array *coords = new Vec3Array(19);
Vec2Array *tcoords = new Vec2Array(19);
Vec4Array *colors = new Vec4Array(1);
int *lengths = new int[1];
(*colors)[0].set(1.0f,1.0f,1.0f,1.0f);

30
src/osg/Array.cpp Normal file
View File

@ -0,0 +1,30 @@
#include <osg/Array>
using namespace osg;
static char* s_ArrayNames[] =
{
"AttributeArray", // 0
"ByteArray", // 1
"ShortArray", // 2
"IntArray", // 3
"UByteArray", // 4
"UShortArray", // 5
"UIntArray", // 6
"UByte4Array", // 7
"FloatArray", // 8
"Vec2Array", // 9
"Vec3Array", // 10
"Vec4Array", // 11
};
const char* AttributeArray::className() const
{
if (_arrayType>=AttributeArrayType && _arrayType<=Vec4ArrayType)
return s_ArrayNames[_arrayType];
else
return "UnkownAttributeArray";
}

View File

@ -2,49 +2,6 @@
using namespace osg;
static char* s_ArrayNames[] =
{
"AttributeArray", // 0
"ByteArray", // 1
"ShortArray", // 2
"IntArray", // 3
"UByteArray", // 4
"UShortArray", // 5
"UIntArray", // 6
"UByte4Array", // 7
"FloatArray", // 8
"Vec2Array", // 9
"Vec3Array", // 10
"Vec4Array", // 11
};
const char* AttributeArray::className() const
{
if (_arrayType>=AttributeArrayType && _arrayType<=Vec4ArrayType)
return s_ArrayNames[_arrayType];
else
return "UnkownAttributeArray";
}
static char* s_PrimitiveNames[] =
{
"Primitive", // 0
"DrawArrays", // 1
"UByteDrawElements", // 2
"UShortDrawElements", // 3
"UIntDrawElements" // 4
};
const char* Primitive::className() const
{
if (_primitiveType>=PrimitivePrimitiveType && _primitiveType<=UIntDrawElementsPrimitiveType)
return s_PrimitiveNames[_primitiveType];
else
return "UnkownAttributeArray";
}
Geometry::Geometry()
{
_normalBinding = BIND_OFF;

View File

@ -4,6 +4,7 @@ include $(TOPDIR)/Make/makedefs
CXXFILES =\
AlphaFunc.cpp\
AnimationPath.cpp\
Array.cpp\
Billboard.cpp\
BoundingBox.cpp\
BoundingSphere.cpp\
@ -56,6 +57,7 @@ CXXFILES =\
PolygonMode.cpp\
PolygonOffset.cpp\
PositionAttitudeTransform.cpp\
Primitive.cpp\
Projection.cpp\
Quat.cpp\
ShadeModel.cpp\

21
src/osg/Primitive.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <osg/Primitive>
using namespace osg;
static char* s_PrimitiveNames[] =
{
"Primitive", // 0
"DrawArrays", // 1
"UByteDrawElements", // 2
"UShortDrawElements", // 3
"UIntDrawElements" // 4
};
const char* Primitive::className() const
{
if (_primitiveType>=PrimitivePrimitiveType && _primitiveType<=UIntDrawElementsPrimitiveType)
return s_PrimitiveNames[_primitiveType];
else
return "UnkownAttributeArray";
}