OpenSceneGraph/include/osg/Primitive

228 lines
8.0 KiB
Plaintext
Raw Normal View History

//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 {
class Primitive : public Object
{
public:
enum Type
{
PrimitiveType,
DrawArraysPrimitiveType,
UByteDrawElementsPrimitiveType,
UShortDrawElementsPrimitiveType,
UIntDrawElementsPrimitiveType
};
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(Type primType=PrimitiveType,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 { return "Primitve"; }
Type getType() 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:
Type _primitiveType;
GLenum _mode;
};
class SG_EXPORT DrawArrays : public Primitive
{
public:
DrawArrays(GLenum mode=0):
Primitive(DrawArraysPrimitiveType,mode)
{}
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;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
protected:
GLint _first;
GLsizei _count;
};
typedef std::vector<GLubyte> UByteVector;
class SG_EXPORT UByteDrawElements : public Primitive, public UByteVector
{
public:
UByteDrawElements(GLenum mode=0):
Primitive(UByteDrawElementsPrimitiveType,mode) {}
UByteDrawElements(const UByteDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
UByteVector(array) {}
UByteDrawElements(GLenum mode,unsigned int no,unsigned char* ptr) :
Primitive(UByteDrawElementsPrimitiveType,mode),
UByteVector(ptr,ptr+no) {}
UByteDrawElements(GLenum mode,unsigned int no) :
Primitive(UByteDrawElementsPrimitiveType,mode),
UByteVector(no) {}
template <class InputIterator>
UByteDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UByteDrawElementsPrimitiveType,mode),
UByteVector(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; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UByteDrawElements"; }
virtual void draw() const ;
virtual void applyPrimitiveOperation(Drawable::PrimitiveFunctor& functor);
};
typedef std::vector<GLushort> UShortVector;
class SG_EXPORT UShortDrawElements : public Primitive, public UShortVector
{
public:
UShortDrawElements(GLenum mode=0):
Primitive(UShortDrawElementsPrimitiveType,mode) {}
UShortDrawElements(const UShortDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
UShortVector(array) {}
UShortDrawElements(GLenum mode,unsigned int no,unsigned short* ptr) :
Primitive(UShortDrawElementsPrimitiveType,mode),
UShortVector(ptr,ptr+no) {}
UShortDrawElements(GLenum mode,unsigned int no) :
Primitive(UShortDrawElementsPrimitiveType,mode),
UShortVector(no) {}
template <class InputIterator>
UShortDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UShortDrawElementsPrimitiveType,mode),
UShortVector(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);
};
typedef std::vector<GLuint> UIntVector;
class SG_EXPORT UIntDrawElements : public Primitive, public UIntVector
{
public:
UIntDrawElements(GLenum mode=0):
Primitive(UIntDrawElementsPrimitiveType,mode) {}
UIntDrawElements(const UIntDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
UIntVector(array) {}
UIntDrawElements(GLenum mode,unsigned int no,unsigned int* ptr) :
Primitive(UIntDrawElementsPrimitiveType,mode),
UIntVector(ptr,ptr+no) {}
UIntDrawElements(GLenum mode,unsigned int no) :
Primitive(UIntDrawElementsPrimitiveType,mode),
UIntVector(no) {}
template <class InputIterator>
UIntDrawElements(GLenum mode, InputIterator first,InputIterator last) :
Primitive(UIntDrawElementsPrimitiveType,mode),
UIntVector(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);
};
}
#endif