2002-06-27 18:50:19 +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_PRIMTIVE
|
|
|
|
#define OSG_PRIMTIVE 1
|
|
|
|
|
|
|
|
#include <osg/Drawable>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
class Primitive : public Object
|
2002-06-27 18:50:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
enum Type
|
|
|
|
{
|
2002-06-28 16:47:23 +08:00
|
|
|
PrimitiveType,
|
|
|
|
DrawArraysPrimitiveType,
|
|
|
|
UByteDrawElementsPrimitiveType,
|
|
|
|
UShortDrawElementsPrimitiveType,
|
|
|
|
UIntDrawElementsPrimitiveType
|
2002-06-27 21:15:34 +08:00
|
|
|
};
|
|
|
|
|
2002-06-27 18:50:19 +08:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
Primitive(Type primType=PrimitiveType,GLenum mode=0):
|
2002-06-27 18:50:19 +08:00
|
|
|
_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"; }
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual const char* className() const { return "Primitve"; }
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
Type getType() const { return _primitiveType; }
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
void setMode(GLenum mode) { _mode = mode; }
|
|
|
|
GLenum getMode() const { return _mode; }
|
|
|
|
|
|
|
|
virtual void draw() const = 0;
|
|
|
|
|
|
|
|
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor&) {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
Type _primitiveType;
|
2002-06-27 18:50:19 +08:00
|
|
|
GLenum _mode;
|
|
|
|
};
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
class SG_EXPORT DrawArrays : public Primitive
|
2002-06-27 18:50:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DrawArrays(GLenum mode=0):
|
2002-06-27 21:15:34 +08:00
|
|
|
Primitive(DrawArraysPrimitiveType,mode)
|
2002-06-27 18:50:19 +08:00
|
|
|
{}
|
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual void draw() const;
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
|
|
|
|
|
|
|
protected:
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
GLint _first;
|
|
|
|
GLsizei _count;
|
|
|
|
};
|
|
|
|
|
2002-07-04 22:49:37 +08:00
|
|
|
typedef std::vector<GLubyte> UByteVector;
|
|
|
|
class SG_EXPORT UByteDrawElements : public Primitive, public UByteVector
|
2002-06-27 18:50:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
UByteDrawElements(GLenum mode=0):
|
|
|
|
Primitive(UByteDrawElementsPrimitiveType,mode) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
UByteDrawElements(const UByteDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-27 18:50:19 +08:00
|
|
|
Primitive(array,copyop),
|
2002-07-04 22:49:37 +08:00
|
|
|
UByteVector(array) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
UByteDrawElements(GLenum mode,unsigned int no,unsigned char* ptr) :
|
|
|
|
Primitive(UByteDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UByteVector(ptr,ptr+no) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
UByteDrawElements(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(UByteDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UByteVector(no) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
2002-06-27 21:15:34 +08:00
|
|
|
UByteDrawElements(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(UByteDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UByteVector(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
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; }
|
2002-06-27 18:50:19 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual const char* className() const { return "UByteDrawElements"; }
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual void draw() const ;
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
|
|
|
|
};
|
|
|
|
|
2002-07-04 22:49:37 +08:00
|
|
|
|
|
|
|
typedef std::vector<GLushort> UShortVector;
|
|
|
|
class SG_EXPORT UShortDrawElements : public Primitive, public UShortVector
|
2002-06-27 21:15:34 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
UShortDrawElements(GLenum mode=0):
|
|
|
|
Primitive(UShortDrawElementsPrimitiveType,mode) {}
|
|
|
|
|
|
|
|
UShortDrawElements(const UShortDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Primitive(array,copyop),
|
2002-07-04 22:49:37 +08:00
|
|
|
UShortVector(array) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
UShortDrawElements(GLenum mode,unsigned int no,unsigned short* ptr) :
|
|
|
|
Primitive(UShortDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UShortVector(ptr,ptr+no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
UShortDrawElements(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(UShortDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UShortVector(no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
UShortDrawElements(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(UShortDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UShortVector(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2002-07-04 22:49:37 +08:00
|
|
|
typedef std::vector<GLuint> UIntVector;
|
|
|
|
class SG_EXPORT UIntDrawElements : public Primitive, public UIntVector
|
2002-06-27 21:15:34 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
UIntDrawElements(GLenum mode=0):
|
|
|
|
Primitive(UIntDrawElementsPrimitiveType,mode) {}
|
|
|
|
|
|
|
|
UIntDrawElements(const UIntDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Primitive(array,copyop),
|
2002-07-04 22:49:37 +08:00
|
|
|
UIntVector(array) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
UIntDrawElements(GLenum mode,unsigned int no,unsigned int* ptr) :
|
|
|
|
Primitive(UIntDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UIntVector(ptr,ptr+no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
UIntDrawElements(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(UIntDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UIntVector(no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
UIntDrawElements(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(UIntDrawElementsPrimitiveType,mode),
|
2002-07-04 22:49:37 +08:00
|
|
|
UIntVector(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
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);
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|