//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 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(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(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 { public: UByteDrawElements(GLenum mode=0): Primitive(UByteDrawElementsPrimitiveType,mode) {} UByteDrawElements(const UByteDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Primitive(array,copyop), std::vector(array) {} UByteDrawElements(GLenum mode,unsigned int no,unsigned char* ptr) : Primitive(UByteDrawElementsPrimitiveType,mode), std::vector(ptr,ptr+no) {} UByteDrawElements(GLenum mode,unsigned int no) : Primitive(UByteDrawElementsPrimitiveType,mode), std::vector(no) {} template UByteDrawElements(GLenum mode, InputIterator first,InputIterator last) : Primitive(UByteDrawElementsPrimitiveType,mode), std::vector(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(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 { public: UShortDrawElements(GLenum mode=0): Primitive(UShortDrawElementsPrimitiveType,mode) {} UShortDrawElements(const UShortDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Primitive(array,copyop), std::vector(array) {} UShortDrawElements(GLenum mode,unsigned int no,unsigned short* ptr) : Primitive(UShortDrawElementsPrimitiveType,mode), std::vector(ptr,ptr+no) {} UShortDrawElements(GLenum mode,unsigned int no) : Primitive(UShortDrawElementsPrimitiveType,mode), std::vector(no) {} template UShortDrawElements(GLenum mode, InputIterator first,InputIterator last) : Primitive(UShortDrawElementsPrimitiveType,mode), std::vector(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(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); }; class SG_EXPORT UIntDrawElements : public Primitive, public std::vector { public: UIntDrawElements(GLenum mode=0): Primitive(UIntDrawElementsPrimitiveType,mode) {} UIntDrawElements(const UIntDrawElements& array,const CopyOp& copyop=CopyOp::SHALLOW_COPY): Primitive(array,copyop), std::vector(array) {} UIntDrawElements(GLenum mode,unsigned int no,unsigned int* ptr) : Primitive(UIntDrawElementsPrimitiveType,mode), std::vector(ptr,ptr+no) {} UIntDrawElements(GLenum mode,unsigned int no) : Primitive(UIntDrawElementsPrimitiveType,mode), std::vector(no) {} template UIntDrawElements(GLenum mode, InputIterator first,InputIterator last) : Primitive(UIntDrawElementsPrimitiveType,mode), std::vector(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(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