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
|
|
|
|
{
|
|
|
|
PrimitiveType = 0,
|
|
|
|
DrawArraysPrimitiveType = 1,
|
|
|
|
UByteDrawElementsPrimitiveType = 2,
|
|
|
|
UShortDrawElementsPrimitiveType = 3,
|
|
|
|
UIntDrawElementsPrimitiveType = 4,
|
|
|
|
};
|
|
|
|
|
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-06-27 21:15:34 +08:00
|
|
|
class SG_EXPORT UByteDrawElements : public Primitive, public std::vector<unsigned char>
|
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-06-27 21:15:34 +08:00
|
|
|
std::vector<unsigned char>(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),
|
|
|
|
std::vector<unsigned char>(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),
|
|
|
|
std::vector<unsigned char>(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),
|
|
|
|
std::vector<unsigned char>(first,last) {}
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
2002-06-27 23:18:10 +08:00
|
|
|
class SG_EXPORT UIntDrawElements : public Primitive, public std::vector<unsigned int>
|
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),
|
|
|
|
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);
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|