OpenSceneGraph/include/osg/Primitive

225 lines
8.1 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 = 0,
DrawArraysPrimitiveType = 1,
UByteDrawElementsPrimitiveType = 2,
UShortDrawElementsPrimitiveType = 3,
UIntDrawElementsPrimitiveType = 4,
};
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;
};
class SG_EXPORT UByteDrawElements : public Primitive, public std::vector<unsigned char>
{
public:
UByteDrawElements(GLenum mode=0):
Primitive(UByteDrawElementsPrimitiveType,mode) {}
UByteDrawElements(const UByteDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
Primitive(array,copyop),
std::vector<unsigned char>(array) {}
UByteDrawElements(GLenum mode,unsigned int no,unsigned char* ptr) :
Primitive(UByteDrawElementsPrimitiveType,mode),
std::vector<unsigned char>(ptr,ptr+no) {}
UByteDrawElements(GLenum mode,unsigned int no) :
Primitive(UByteDrawElementsPrimitiveType,mode),
std::vector<unsigned char>(no) {}
template <class InputIterator>
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; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "UByteDrawElements"; }
virtual void draw() const ;
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>
{
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);
};
}
#endif