diff --git a/include/osg/PrimitiveSet b/include/osg/PrimitiveSet index 9f815cffd..4438fb16c 100644 --- a/include/osg/PrimitiveSet +++ b/include/osg/PrimitiveSet @@ -40,7 +40,7 @@ namespace osg { class VectorGLsizei: public std::vector { typedef std::vector vector_type; -public: +public: VectorGLsizei(): vector_type() {} VectorGLsizei(const VectorGLsizei ©): vector_type(copy) {} VectorGLsizei(GLsizei* beg, GLsizei* end): vector_type(beg, end) {} @@ -50,7 +50,7 @@ public: class VectorGLubyte: public std::vector { typedef std::vector vector_type; -public: +public: VectorGLubyte(): vector_type() {} VectorGLubyte(const VectorGLubyte ©): vector_type(copy) {} VectorGLubyte(GLubyte* beg, GLubyte* end): vector_type(beg, end) {} @@ -60,7 +60,7 @@ public: class VectorGLushort: public std::vector { typedef std::vector vector_type; -public: +public: VectorGLushort(): vector_type() {} VectorGLushort(const VectorGLushort ©): vector_type(copy) {} VectorGLushort(GLushort* beg, GLushort* end): vector_type(beg, end) {} @@ -79,30 +79,73 @@ public: // ************************************************************************** -class State; +class State; +/** A \c PrimitiveFunctor is used (in conjunction with + * osg::Drawable::accept (PrimitiveFunctor&)) to get access to the + * primitives that compose the things drawn by OSG. + *

If \c osg::Drawable::accept() is called with a \c PrimitiveFunctor + * parameter, the \c Drawable will "pretend" it is drawing itself, but instead + * of calling real OpenGL functions, it will call PrimitiveFunctor's + * member functions that "mimic" the OpenGL calls. + *

Concrete subclasses of \c PrimitiveFunctor must implement these methods + * so that they performs whatever they want. + */ class PrimitiveFunctor { public: virtual ~PrimitiveFunctor() {} + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ virtual void setVertexArray(unsigned int count,const Vec2* vertices) = 0; + + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ virtual void setVertexArray(unsigned int count,const Vec3* vertices) = 0; + + /** Sets the array of vertices used to describe the primitives. Somehow + * mimics the OpenGL \c glVertexPointer() function. + */ virtual void setVertexArray(unsigned int count,const Vec4* vertices) = 0; + /// Mimics the OpenGL \c glDrawArrays() function. virtual void drawArrays(GLenum mode,GLint first,GLsizei count) = 0; + + /// Mimics the OpenGL \c glDrawElements() function. virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0; + + /// Mimics the OpenGL \c glDrawElements() function. virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0; + + /// Mimics the OpenGL \c glDrawElements() function. virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0; + /// Mimics the OpenGL \c glBegin() function. virtual void begin(GLenum mode) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(const Vec2& vert) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(const Vec3& vert) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(const Vec4& vert) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(float x,float y) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(float x,float y,float z) = 0; + + /// Mimics the OpenGL \c glVertex() "family of functions". virtual void vertex(float x,float y,float z,float w) = 0; + + /// Mimics the OpenGL \c glEnd() function. virtual void end() = 0; }; diff --git a/include/osg/TriangleFunctor b/include/osg/TriangleFunctor index bd44357b6..ad294c71e 100644 --- a/include/osg/TriangleFunctor +++ b/include/osg/TriangleFunctor @@ -19,6 +19,21 @@ namespace osg { + +/** Provides access to the triangles that compose an \c osg::Drawable. If the \c + * Drawable is not composed of triangles, the \c TriangleFunctor will convert + * the primitives to triangles whenever possible. + *

Notice that \c TriangleFunctor is a class template, and that it inherits + * from its template parameter \c T. This template parameter must implement + * T::operator() (const osg::Vec3 v1, const osg::Vec3 v2, const osg::Vec3 + * v3, bool treatVertexDataAsTemporary), which will be called for every + * triangle when the functor is applied to a \c Drawable. Parameters \c v1, \c + * v2, and \c v3 are the triangle vertices. The fourth parameter, \c + * treatVertexDataAsTemporary, indicates whether these vertices are coming from + * a "real" vertex array, or from a temporary vertex array, created by the \c + * TriangleFunctor from some other geometry representation. + * @see \c PrimitiveFunctor for general usage hints. + */ template class TriangleFunctor : public PrimitiveFunctor, public T { @@ -31,13 +46,13 @@ public: _modeCache=0; _treatVertexDataAsTemporary=false; } - + virtual ~TriangleFunctor() {} - + void setTreatVertexDataAsTemporary(bool treatVertexDataAsTemporary) { _treatVertexDataAsTemporary=treatVertexDataAsTemporary; } bool getTreatVertexDataAsTemporary() const { return _treatVertexDataAsTemporary; } - virtual void setVertexArray(unsigned int,const Vec2*) + virtual void setVertexArray(unsigned int,const Vec2*) { notify(WARN)<<"Triangle Functor does not support Vec2* vertex arrays"<