2002-06-21 03:54:08 +08:00
|
|
|
//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_GEOMETRY
|
|
|
|
#define OSG_GEOMETRY 1
|
|
|
|
|
|
|
|
#include <osg/Drawable>
|
|
|
|
#include <osg/Vec2>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2002-06-21 03:54:08 +08:00
|
|
|
class AttributeArray : public Object
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
AttributeArray(ArrayType arrayType=AttributeArrayType,GLint dataSize=0,GLenum dataType=0):
|
|
|
|
_arrayType(arrayType),
|
|
|
|
_dataSize(dataSize),
|
|
|
|
_dataType(dataType) {}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
AttributeArray(const AttributeArray& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Object(array,copyop),
|
2002-06-22 00:45:45 +08:00
|
|
|
_arrayType(array._arrayType),
|
2002-06-21 03:54:08 +08:00
|
|
|
_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"; }
|
2002-06-25 05:37:34 +08:00
|
|
|
virtual const char* className() const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
ArrayType arrayType() const { return _arrayType; }
|
2002-06-21 03:54:08 +08:00
|
|
|
GLint dataSize() const { return _dataSize; }
|
|
|
|
GLenum dataType() const { return _dataType; }
|
|
|
|
virtual const GLvoid* dataPointer() const = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~AttributeArray() {}
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
ArrayType _arrayType;
|
|
|
|
GLint _dataSize;
|
|
|
|
GLenum _dataType;
|
2002-06-21 03:54:08 +08:00
|
|
|
};
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
template<typename T, ArrayType ARRAYTYPE, int DataSize, int DataType>
|
2002-06-21 03:54:08 +08:00
|
|
|
class TemplateArray : public AttributeArray, public std::vector<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
TemplateArray() : AttributeArray(ARRAYTYPE,DataSize,DataType) {}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
TemplateArray(const TemplateArray& ta,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
AttributeArray(ta,copyop),
|
|
|
|
std::vector<T>(ta) {}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
TemplateArray(unsigned int no,T* ptr) :
|
|
|
|
AttributeArray(ARRAYTYPE,DataSize,DataType),
|
|
|
|
std::vector<T>(ptr,ptr+no) {}
|
|
|
|
|
|
|
|
TemplateArray(T* first,T* last) :
|
|
|
|
AttributeArray(ARRAYTYPE,DataSize,DataType),
|
|
|
|
std::vector<T>(first,last) {}
|
|
|
|
|
2002-06-21 03:54:08 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew TemplateArray(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew TemplateArray(*this,copyop); }
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
virtual const GLvoid* dataPointer() const { if (!empty()) return &front(); else return 0; }
|
2002-06-21 03:54:08 +08:00
|
|
|
};
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
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,
|
2002-06-25 05:37:34 +08:00
|
|
|
DrawArraysPrimitiveType = 1,
|
2002-06-22 00:45:45 +08:00
|
|
|
UByteDrawElementsPrimitiveType = 2,
|
|
|
|
UShortDrawElementsPrimitiveType = 3,
|
|
|
|
UIntDrawElementsPrimitiveType = 4,
|
|
|
|
};
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
class Primitive : public Object
|
2002-06-21 03:54:08 +08:00
|
|
|
{
|
|
|
|
public:
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
enum Mode
|
2002-06-21 03:54:08 +08:00
|
|
|
{
|
|
|
|
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
|
|
|
|
};
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
Primitive(PrimitiveType primType=PrimitivePrimitiveType):_primitiveType(primType) {}
|
|
|
|
|
|
|
|
Primitive(const Primitive& prim,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Object(prim,copyop) {}
|
|
|
|
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Primitive*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-06-25 05:37:34 +08:00
|
|
|
virtual const char* className() const;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
PrimitiveType primitiveType() const { return _primitiveType; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
virtual void draw() const = 0;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
PrimitiveType _primitiveType;
|
|
|
|
};
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
class DrawArrays : public Primitive
|
2002-06-22 00:45:45 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
DrawArrays():
|
|
|
|
Primitive(DrawArraysPrimitiveType)
|
2002-06-22 00:45:45 +08:00
|
|
|
{}
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
DrawArrays(GLenum mode, GLint first, GLsizei count):
|
|
|
|
Primitive(DrawArraysPrimitiveType),
|
2002-06-22 00:45:45 +08:00
|
|
|
_mode(mode),
|
|
|
|
_first(first),
|
|
|
|
_count(count) {}
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
DrawArrays(const DrawArrays& da,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-22 00:45:45 +08:00
|
|
|
Primitive(da,copyop),
|
|
|
|
_mode(da._mode),
|
|
|
|
_first(da._first),
|
|
|
|
_count(da._count) {}
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
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; }
|
2002-06-22 00:45:45 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-06-24 05:43:46 +08:00
|
|
|
virtual const char* className() const { return "DrawArrays"; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
|
|
|
|
void set(GLenum mode, GLint first, GLsizei count)
|
|
|
|
{
|
|
|
|
_mode = mode;
|
|
|
|
_first = first;
|
|
|
|
_count = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setMode(GLenum mode) { _mode = mode; }
|
|
|
|
GLenum getMode() const { return _mode; }
|
|
|
|
|
|
|
|
void setFirst(GLint first) { _first = first; }
|
|
|
|
GLint getFirst() const { return _first; }
|
|
|
|
|
|
|
|
void setCount(GLsizei count) { _count = count; }
|
|
|
|
GLsizei getCount() const { return _count; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
virtual void draw() const
|
|
|
|
{
|
|
|
|
glDrawArrays(_mode,_first,_count);
|
|
|
|
}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
GLenum _mode;
|
|
|
|
GLint _first;
|
|
|
|
GLsizei _count;
|
|
|
|
};
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
template<typename T, PrimitiveType PRIMTYPE, int DataType>
|
2002-06-22 00:45:45 +08:00
|
|
|
class DrawElements : public Primitive, public std::vector<T>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
DrawElements(GLenum mode=0):
|
|
|
|
Primitive(PRIMTYPE),
|
|
|
|
_mode(mode),
|
|
|
|
_dataType(DataType) {}
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
DrawElements(const DrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-24 05:43:46 +08:00
|
|
|
Primitive(array,copyop),
|
|
|
|
std::vector<T>(array),
|
|
|
|
_mode(array._mode),
|
|
|
|
_dataType(array._dataType) {}
|
|
|
|
|
|
|
|
DrawElements(GLenum mode,unsigned int no,T* ptr) :
|
|
|
|
Primitive(PRIMTYPE),
|
|
|
|
std::vector<T>(ptr,ptr+no),
|
|
|
|
_mode(mode),
|
|
|
|
_dataType(DataType) {}
|
|
|
|
|
|
|
|
DrawElements(GLenum mode, T* first,T* last) :
|
|
|
|
Primitive(PRIMTYPE),
|
|
|
|
std::vector<T>(first,last),
|
|
|
|
_mode(mode),
|
|
|
|
_dataType(DataType) {}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
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"; }
|
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
void setMode(GLenum mode) { _mode = mode; }
|
|
|
|
GLenum getMode() const { return _mode; }
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
virtual void draw() const
|
|
|
|
{
|
|
|
|
glDrawElements(_mode,size(),_dataType,&front());
|
|
|
|
}
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
GLenum _mode;
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
/* ******************************************************************************************************************* */
|
|
|
|
|
|
|
|
|
|
|
|
/** Experiemntal replacement for GeoSet.
|
|
|
|
*/
|
|
|
|
class SG_EXPORT Geometry : public Drawable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
Geometry();
|
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
Geometry(const Geometry& Geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
virtual Object* cloneType() const { return osgNew Geometry(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew Geometry(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Geometry*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "Geometry"; }
|
|
|
|
|
|
|
|
enum AttributeBinding
|
|
|
|
{
|
2002-06-24 05:43:46 +08:00
|
|
|
BIND_OFF=0,
|
|
|
|
BIND_OVERALL,
|
|
|
|
BIND_PER_PRIMITIVE,
|
|
|
|
BIND_PER_VERTEX,
|
2002-06-22 00:45:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void setVertexArray(Vec3Array* array) { _vertexArray = array; }
|
|
|
|
Vec3Array* getVertexArray() { return _vertexArray.get(); }
|
|
|
|
const Vec3Array* getVertexArray() const { return _vertexArray.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
void setNormalBinding(AttributeBinding ab) { _normalBinding = ab; }
|
|
|
|
AttributeBinding getNormalBinding() const { return _normalBinding; }
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
void setNormalArray(Vec3Array* array) { _normalArray = array; if (!_normalArray.valid()) _normalBinding=BIND_OFF; }
|
2002-06-22 00:45:45 +08:00
|
|
|
Vec3Array* getNormalArray() { return _normalArray.get(); }
|
|
|
|
const Vec3Array* getNormalArray() const { return _normalArray.get(); }
|
|
|
|
|
|
|
|
|
|
|
|
void setColorBinding(AttributeBinding ab) { _colorBinding = ab; }
|
|
|
|
AttributeBinding getColorBinding() const { return _colorBinding; }
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
void setColorArray(AttributeArray* array) { _colorArray = array; if (!_colorArray.valid()) _colorBinding=BIND_OFF; }
|
2002-06-22 00:45:45 +08:00
|
|
|
AttributeArray* getColorArray() { return _colorArray.get(); }
|
|
|
|
const AttributeArray* getColorArray() const { return _colorArray.get(); }
|
|
|
|
|
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
typedef std::vector< ref_ptr<AttributeArray> > TexCoordArrayList;
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
void setTexCoordArray(unsigned int unit,AttributeArray*);
|
|
|
|
AttributeArray* getTexCoordArray(unsigned int unit);
|
|
|
|
const AttributeArray* getTexCoordArray(unsigned int unit) const;
|
2002-06-25 05:37:34 +08:00
|
|
|
|
|
|
|
unsigned int getNumTexCoordArrays() const { return _texCoordList.size(); }
|
|
|
|
TexCoordArrayList& getTexCoordArrayList() { return _texCoordList; }
|
|
|
|
const TexCoordArrayList& getTexCoordArrayList() const { return _texCoordList; }
|
2002-06-22 00:45:45 +08:00
|
|
|
|
|
|
|
|
|
|
|
typedef std::vector< ref_ptr<Primitive> > PrimitiveList;
|
|
|
|
|
|
|
|
void setPrimitiveList(const PrimitiveList& primitives) { _primitives = primitives; }
|
|
|
|
PrimitiveList& getPrimitiveList() { return _primitives; }
|
|
|
|
const PrimitiveList& getPrimitiveList() const { return _primitives; }
|
|
|
|
|
2002-06-24 05:43:46 +08:00
|
|
|
void addPrimitive(Primitive* primitive) { if (primitive) _primitives.push_back(primitive); }
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** draw Geometry directly ignoring an OpenGL display list which could be attached.
|
|
|
|
* This is the internal draw method which does the drawing itself,
|
|
|
|
* and is the method to override when deriving from Geometry for user-drawn objects.
|
|
|
|
*/
|
|
|
|
virtual void drawImmediateMode(State& state);
|
|
|
|
|
|
|
|
/** Statistics collection for each drawable- 26.09.01
|
|
|
|
*/
|
|
|
|
bool getStats(Statistics &);
|
|
|
|
|
|
|
|
|
|
|
|
/** return the attributes supported by applyAttrbuteUpdate() as an AttributeBitMask.*/
|
|
|
|
virtual AttributeBitMask suppportsAttributeOperation() const;
|
|
|
|
|
|
|
|
/** return the attributes successully applied in applyAttributeUpdate.*/
|
|
|
|
virtual AttributeBitMask applyAttributeOperation(AttributeFunctor& auf);
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Geometry& operator = (const Geometry&) { return *this;}
|
|
|
|
|
|
|
|
virtual ~Geometry();
|
|
|
|
|
|
|
|
virtual const bool computeBound() const;
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
PrimitiveList _primitives;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
ref_ptr<Vec3Array> _vertexArray;
|
|
|
|
|
|
|
|
AttributeBinding _normalBinding;
|
|
|
|
ref_ptr<Vec3Array> _normalArray;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-22 00:45:45 +08:00
|
|
|
AttributeBinding _colorBinding;
|
|
|
|
ref_ptr<AttributeArray> _colorArray;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
2002-06-25 05:37:34 +08:00
|
|
|
TexCoordArrayList _texCoordList;
|
2002-06-21 03:54:08 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|