2002-07-17 04:07:32 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
|
2002-06-27 18:50:19 +08:00
|
|
|
//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-07-08 01:42:34 +08:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
|
|
|
|
typedef std::vector<GLsizei> VectorSizei;
|
|
|
|
typedef std::vector<GLubyte> VectorUByte;
|
|
|
|
typedef std::vector<GLushort> VectorUShort;
|
|
|
|
typedef std::vector<GLuint> VectorUInt;
|
|
|
|
|
|
|
|
#else // _MSC_VER
|
|
|
|
|
2002-07-08 06:12:51 +08:00
|
|
|
// Following Vector wrapper classes are work arounds for MS linker problems with
|
|
|
|
// multiply implemented methods.
|
|
|
|
//
|
|
|
|
// An alternative, sent in by Clay Fowler, is workaround in VS to prevent the problem:
|
|
|
|
// the following changes have to be made to the project to make it compile,
|
|
|
|
// but NO changes are required to the actual source code:
|
|
|
|
// In the osgUtil project, go to the project properties, select the Linker/Command Line property page,
|
|
|
|
// and add the following switch in the "Additional Options" field:
|
|
|
|
// FORCE:MULTIPLE
|
|
|
|
|
2002-07-08 01:42:34 +08:00
|
|
|
class VectorSizei: public std::vector<GLsizei> {
|
|
|
|
typedef std::vector<value_type> inherited;
|
|
|
|
public:
|
|
|
|
VectorSizei(): inherited() {}
|
|
|
|
explicit VectorSizei(size_type n): inherited(n) {}
|
|
|
|
VectorSizei(const VectorSizei ©): inherited(copy) {}
|
2002-07-11 19:36:25 +08:00
|
|
|
//VectorSizei(value_type *beg_, value_type *end_): inherited(beg_, end_) {}
|
2002-07-08 01:42:34 +08:00
|
|
|
template<class InputIterator>
|
|
|
|
VectorSizei(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VectorUByte: public std::vector<GLubyte> {
|
|
|
|
typedef std::vector<value_type> inherited;
|
|
|
|
public:
|
|
|
|
VectorUByte(): inherited() {}
|
|
|
|
explicit VectorUByte(size_type n): inherited(n) {}
|
|
|
|
VectorUByte(const VectorUByte ©): inherited(copy) {}
|
2002-07-11 19:36:25 +08:00
|
|
|
//VectorUByte(value_type *beg_, value_type *end_): inherited(beg_, end_) {}
|
2002-07-08 01:42:34 +08:00
|
|
|
template<class InputIterator>
|
|
|
|
VectorUByte(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VectorUShort: public std::vector<GLushort> {
|
|
|
|
typedef std::vector<value_type> inherited;
|
|
|
|
public:
|
|
|
|
VectorUShort(): inherited() {}
|
|
|
|
explicit VectorUShort(size_type n): inherited(n) {}
|
|
|
|
VectorUShort(const VectorUShort ©): inherited(copy) {}
|
2002-07-11 19:36:25 +08:00
|
|
|
//VectorUShort(value_type *beg_, value_type *end_): inherited(beg_, end_) {}
|
2002-07-08 01:42:34 +08:00
|
|
|
template<class InputIterator>
|
|
|
|
VectorUShort(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
class VectorUInt: public std::vector<GLuint> {
|
|
|
|
typedef std::vector<value_type> inherited;
|
|
|
|
public:
|
|
|
|
VectorUInt(): inherited() {}
|
|
|
|
explicit VectorUInt(size_type n): inherited(n) {}
|
|
|
|
VectorUInt(const VectorUInt ©): inherited(copy) {}
|
2002-07-11 19:36:25 +08:00
|
|
|
//VectorUInt(value_type *beg_, value_type *end_): inherited(beg_, end_) {}
|
2002-07-08 01:42:34 +08:00
|
|
|
template<class InputIterator>
|
|
|
|
VectorUInt(InputIterator beg_, InputIterator end_): inherited(beg_, end_) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
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,
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawArrayLengthsPrimitiveType,
|
|
|
|
DrawElementsUBytePrimitiveType,
|
|
|
|
DrawElementsUShortPrimitiveType,
|
|
|
|
DrawElementsUIntPrimitiveType
|
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;
|
|
|
|
|
2002-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor&) {}
|
2002-07-18 08:53:03 +08:00
|
|
|
|
|
|
|
virtual void offsetIndices(int offset) = 0;
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
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-07-07 22:40:41 +08:00
|
|
|
Primitive(DrawArraysPrimitiveType,mode),
|
|
|
|
_first(0),
|
|
|
|
_count(0) {}
|
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-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
virtual void offsetIndices(int offset) { _first += offset; }
|
|
|
|
|
2002-06-27 21:15:34 +08:00
|
|
|
protected:
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
GLint _first;
|
|
|
|
GLsizei _count;
|
|
|
|
};
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
class SG_EXPORT DrawArrayLengths : public Primitive, public VectorSizei
|
2002-06-27 18:50:19 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawArrayLengths(GLenum mode=0):
|
|
|
|
Primitive(DrawArrayLengthsPrimitiveType,mode),
|
|
|
|
_first(0) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawArrayLengths(const DrawArrayLengths& dal,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
|
|
|
Primitive(dal,copyop),
|
|
|
|
VectorSizei(dal),
|
|
|
|
_first(dal._first) {}
|
|
|
|
|
|
|
|
DrawArrayLengths(GLenum mode, GLint first, unsigned int no, GLsizei* ptr) :
|
|
|
|
Primitive(DrawArrayLengthsPrimitiveType,mode),
|
|
|
|
VectorSizei(ptr,ptr+no),
|
|
|
|
_first(first) {}
|
|
|
|
|
|
|
|
DrawArrayLengths(GLenum mode,GLint first, unsigned int no) :
|
|
|
|
Primitive(DrawArrayLengthsPrimitiveType,mode),
|
|
|
|
VectorSizei(no),
|
|
|
|
_first(first) {}
|
|
|
|
|
|
|
|
template <class InputIterator>
|
|
|
|
DrawArrayLengths(GLenum mode, GLint first, InputIterator firstItr,InputIterator lastItr) :
|
|
|
|
Primitive(DrawArrayLengthsPrimitiveType,mode),
|
|
|
|
VectorSizei(firstItr,lastItr),
|
|
|
|
_first(first) {}
|
|
|
|
|
|
|
|
virtual Object* cloneType() const { return osgNew DrawArrayLengths(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawArrayLengths(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawArrayLengths*>(obj)!=NULL; }
|
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
|
|
|
virtual const char* className() const { return "DrawArrayLengths"; }
|
|
|
|
|
|
|
|
|
|
|
|
void setFirst(GLint first) { _first = first; }
|
|
|
|
GLint getFirst() const { return _first; }
|
|
|
|
|
|
|
|
virtual void draw() const;
|
|
|
|
|
2002-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
2002-07-07 22:40:41 +08:00
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
virtual void offsetIndices(int offset) { _first += offset; }
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
GLint _first;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SG_EXPORT DrawElementsUByte : public Primitive, public VectorUByte
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
DrawElementsUByte(GLenum mode=0):
|
|
|
|
Primitive(DrawElementsUBytePrimitiveType,mode) {}
|
|
|
|
|
|
|
|
DrawElementsUByte(const DrawElementsUByte& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-27 18:50:19 +08:00
|
|
|
Primitive(array,copyop),
|
2002-07-07 22:40:41 +08:00
|
|
|
VectorUByte(array) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-07-11 16:28:09 +08:00
|
|
|
DrawElementsUByte(GLenum mode,unsigned int no,GLubyte* ptr) :
|
2002-07-07 22:40:41 +08:00
|
|
|
Primitive(DrawElementsUBytePrimitiveType,mode),
|
|
|
|
VectorUByte(ptr,ptr+no) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUByte(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(DrawElementsUBytePrimitiveType,mode),
|
|
|
|
VectorUByte(no) {}
|
2002-06-27 18:50:19 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUByte(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(DrawElementsUBytePrimitiveType,mode),
|
|
|
|
VectorUByte(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew DrawElementsUByte(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawElementsUByte(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUByte*>(obj)!=NULL; }
|
2002-06-27 18:50:19 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual const char* className() const { return "DrawElementsUByte"; }
|
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-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
2002-07-18 08:53:03 +08:00
|
|
|
|
|
|
|
virtual void offsetIndices(int offset);
|
2002-06-27 21:15:34 +08:00
|
|
|
};
|
|
|
|
|
2002-07-04 22:49:37 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
class SG_EXPORT DrawElementsUShort : public Primitive, public VectorUShort
|
2002-06-27 21:15:34 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUShort(GLenum mode=0):
|
|
|
|
Primitive(DrawElementsUShortPrimitiveType,mode) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUShort(const DrawElementsUShort& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-27 21:15:34 +08:00
|
|
|
Primitive(array,copyop),
|
2002-07-07 22:40:41 +08:00
|
|
|
VectorUShort(array) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-11 16:28:09 +08:00
|
|
|
DrawElementsUShort(GLenum mode,unsigned int no,GLushort* ptr) :
|
2002-07-07 22:40:41 +08:00
|
|
|
Primitive(DrawElementsUShortPrimitiveType,mode),
|
|
|
|
VectorUShort(ptr,ptr+no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUShort(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(DrawElementsUShortPrimitiveType,mode),
|
|
|
|
VectorUShort(no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUShort(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(DrawElementsUShortPrimitiveType,mode),
|
|
|
|
VectorUShort(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew DrawElementsUShort(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawElementsUShort(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUShort*>(obj)!=NULL; }
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual const char* className() const { return "DrawElementsUShort"; }
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
virtual void draw() const;
|
|
|
|
|
2002-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
2002-07-18 08:53:03 +08:00
|
|
|
|
|
|
|
virtual void offsetIndices(int offset);
|
2002-06-27 21:15:34 +08:00
|
|
|
};
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
class SG_EXPORT DrawElementsUInt : public Primitive, public VectorUInt
|
2002-06-27 21:15:34 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUInt(GLenum mode=0):
|
|
|
|
Primitive(DrawElementsUIntPrimitiveType,mode) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUInt(const DrawElementsUInt& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
2002-06-27 21:15:34 +08:00
|
|
|
Primitive(array,copyop),
|
2002-07-07 22:40:41 +08:00
|
|
|
VectorUInt(array) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-11 16:28:09 +08:00
|
|
|
DrawElementsUInt(GLenum mode,unsigned int no,GLuint* ptr) :
|
2002-07-07 22:40:41 +08:00
|
|
|
Primitive(DrawElementsUIntPrimitiveType,mode),
|
|
|
|
VectorUInt(ptr,ptr+no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUInt(GLenum mode,unsigned int no) :
|
|
|
|
Primitive(DrawElementsUIntPrimitiveType,mode),
|
|
|
|
VectorUInt(no) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
template <class InputIterator>
|
2002-07-07 22:40:41 +08:00
|
|
|
DrawElementsUInt(GLenum mode, InputIterator first,InputIterator last) :
|
|
|
|
Primitive(DrawElementsUIntPrimitiveType,mode),
|
|
|
|
VectorUInt(first,last) {}
|
2002-06-27 21:15:34 +08:00
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual Object* cloneType() const { return osgNew DrawElementsUInt(); }
|
|
|
|
virtual Object* clone(const CopyOp& copyop) const { return osgNew DrawElementsUInt(*this,copyop); }
|
|
|
|
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const DrawElementsUInt*>(obj)!=NULL; }
|
2002-06-27 21:15:34 +08:00
|
|
|
virtual const char* libraryName() const { return "osg"; }
|
2002-07-07 22:40:41 +08:00
|
|
|
virtual const char* className() const { return "DrawElementsUInt"; }
|
2002-06-27 21:15:34 +08:00
|
|
|
|
|
|
|
virtual void draw() const;
|
|
|
|
|
2002-07-18 23:36:14 +08:00
|
|
|
virtual void accept(Drawable::PrimitiveFunctor& functor);
|
2002-06-27 18:50:19 +08:00
|
|
|
|
2002-07-18 08:53:03 +08:00
|
|
|
virtual void offsetIndices(int offset);
|
2002-06-27 18:50:19 +08:00
|
|
|
};
|
|
|
|
|
2002-07-07 22:40:41 +08:00
|
|
|
// backwards compatibility with first incarnation of DrawElements nameing convention.
|
|
|
|
typedef DrawElementsUByte UByteDrawElements;
|
|
|
|
typedef DrawElementsUShort UShortDrawElements;
|
|
|
|
typedef DrawElementsUInt UIntDrawElements;
|
|
|
|
|
2002-06-27 18:50:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|