From bc0a402dacf60389774142be89d846cf59e9fcd7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 27 Apr 2017 19:04:26 +0100 Subject: [PATCH] Improved indentation, making it consistent with the rest of the OSG headers --- include/osg/TemplatePrimitiveFunctor | 476 +++++++++++++-------------- include/osg/TriangleIndexFunctor | 30 +- 2 files changed, 244 insertions(+), 262 deletions(-) diff --git a/include/osg/TemplatePrimitiveFunctor b/include/osg/TemplatePrimitiveFunctor index 8fd3696ba..96f3aad80 100644 --- a/include/osg/TemplatePrimitiveFunctor +++ b/include/osg/TemplatePrimitiveFunctor @@ -20,271 +20,271 @@ namespace osg { - /** Provides access to the primitives that compose an \c osg::Drawable. - *

Notice that \c TemplatePrimitiveFunctor is a class template, and that it inherits - * from its template parameter \c T. This template parameter must implement - * operator()(const osg::Vec3 v1, const osg::Vec3 v2, const osg::Vec3 - * v3, bool treatVertexDataAsTemporary), - * operator()(const osg::Vec3 v1, const osg::Vec3 v2, bool - * treatVertexDataAsTemporary), operator()(const osg::Vec3 v1, - * const osg::Vec3 v2, const osg::Vec3 v3, bool treatVertexDataAsTemporary), - * and operator()(const osg::Vec3 v1, const osg::Vec3 v2, const osg::Vec3 v3, - * const osg::Vec3 v4, bool treatVertexDataAsTemporary) which will be called - * for the matching primitive when the functor is applied to a \c Drawable. - * Parameters \c v1, \c v2, \c v3, and \c v4 are the vertices of the primitive. - * The last parameter, \c treatVertexDataAsTemporary, indicates whether these - * vertices are coming from a "real" vertex array, or from a temporary vertex array, - * created by the \c TemplatePrimitiveFunctor from some other geometry representation. - * @see \c PrimitiveFunctor for general usage hints. - */ - template - class TemplatePrimitiveFunctor : public PrimitiveFunctor, public T +/** Provides access to the primitives that compose an \c osg::Drawable. + *

Notice that \c TemplatePrimitiveFunctor is a class template, and that it inherits + * from its template parameter \c T. This template parameter must implement + * operator()(const osg::Vec3 v1, const osg::Vec3 v2, const osg::Vec3 + * v3, bool treatVertexDataAsTemporary), + * operator()(const osg::Vec3 v1, const osg::Vec3 v2, bool + * treatVertexDataAsTemporary), operator()(const osg::Vec3 v1, + * const osg::Vec3 v2, const osg::Vec3 v3, bool treatVertexDataAsTemporary), + * and operator()(const osg::Vec3 v1, const osg::Vec3 v2, const osg::Vec3 v3, + * const osg::Vec3 v4, bool treatVertexDataAsTemporary) which will be called + * for the matching primitive when the functor is applied to a \c Drawable. + * Parameters \c v1, \c v2, \c v3, and \c v4 are the vertices of the primitive. + * The last parameter, \c treatVertexDataAsTemporary, indicates whether these + * vertices are coming from a "real" vertex array, or from a temporary vertex array, + * created by the \c TemplatePrimitiveFunctor from some other geometry representation. + * @see \c PrimitiveFunctor for general usage hints. + */ +template +class TemplatePrimitiveFunctor : public PrimitiveFunctor, public T +{ +public: + + TemplatePrimitiveFunctor() { - public: + _vertexArraySize=0; + _vertexArrayPtr=0; + } - TemplatePrimitiveFunctor() - { - _vertexArraySize=0; - _vertexArrayPtr=0; - } + virtual ~TemplatePrimitiveFunctor() {} - virtual ~TemplatePrimitiveFunctor() {} + virtual void setVertexArray(unsigned int,const Vec2*) + { + notify(WARN)<<"Triangle Functor does not support Vec2* vertex arrays"<operator()(*(vptr),*(vptr+1),*(vptr+2),false); + break; + } + case(GL_TRIANGLE_STRIP): { + const Vec3* vptr = &_vertexArrayPtr[first]; + for(GLsizei i=2;ioperator()(*(vptr),*(vptr+1),*(vptr+2),false); - break; + if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),false); + else this->operator()(*(vptr),*(vptr+1),*(vptr+2),false); } - case(GL_TRIANGLE_STRIP): { - const Vec3* vptr = &_vertexArrayPtr[first]; - for(GLsizei i=2;ioperator()(*(vptr),*(vptr+2),*(vptr+1),false); - else this->operator()(*(vptr),*(vptr+1),*(vptr+2),false); - } - break; - } - case(GL_QUADS): { - const Vec3* vptr = &_vertexArrayPtr[first]; - for(GLsizei i=3;ioperator()(*(vptr),*(vptr+1),*(vptr+2),*(vptr+3),false); - } - break; - } - case(GL_QUAD_STRIP): { - const Vec3* vptr = &_vertexArrayPtr[first]; - for(GLsizei i=3;ioperator()(*(vptr),*(vptr+1),*(vptr+3),*(vptr+2),false); - } - break; - } - case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN - case(GL_TRIANGLE_FAN): { - const Vec3* vfirst = &_vertexArrayPtr[first]; - const Vec3* vptr = vfirst+1; - for(GLsizei i=2;ioperator()(*(vfirst),*(vptr),*(vptr+1),false); - } - break; - } - case(GL_POINTS): { - const Vec3* vlast = &_vertexArrayPtr[first+count]; - for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),false); - break; - } - case(GL_LINES): { - const Vec3* vlast = &_vertexArrayPtr[first+count-1]; - for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); - break; - } - case(GL_LINE_STRIP): { - const Vec3* vlast = &_vertexArrayPtr[first+count-1]; - for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); - break; - } - case(GL_LINE_STRIP_ADJACENCY): { - const Vec3* vlast = &_vertexArrayPtr[first+count-2]; - for(const Vec3* vptr=&_vertexArrayPtr[first+1];vptroperator()(*(vptr),*(vptr+1),false); - break; - } - case(GL_LINE_LOOP): { - const Vec3* vlast = &_vertexArrayPtr[first+count-1]; - for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); - this->operator()(*(vlast),_vertexArrayPtr[first],false); - break; - } - default: - break; - } - } - - template - void drawElementsTemplate(GLenum mode,GLsizei count,const IndexType* indices) - { - if (indices==0 || count==0) return; - - typedef const IndexType* IndexPointer; - - switch(mode) + break; + } + case(GL_QUADS): { + const Vec3* vptr = &_vertexArrayPtr[first]; + for(GLsizei i=3;ioperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false); - break; + this->operator()(*(vptr),*(vptr+1),*(vptr+2),*(vptr+3),false); } - case(GL_TRIANGLE_STRIP): { - IndexPointer iptr = indices; - for(GLsizei i=2;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)], - _vertexArrayPtr[*(iptr+1)],false); - else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], - _vertexArrayPtr[*(iptr+2)],false); - } - break; + break; + } + case(GL_QUAD_STRIP): { + const Vec3* vptr = &_vertexArrayPtr[first]; + for(GLsizei i=3;ioperator()(*(vptr),*(vptr+1),*(vptr+3),*(vptr+2),false); } - case(GL_QUADS): { - IndexPointer iptr = indices; - for(GLsizei i=3;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], - _vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)], - false); - } - break; + break; + } + case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN + case(GL_TRIANGLE_FAN): { + const Vec3* vfirst = &_vertexArrayPtr[first]; + const Vec3* vptr = vfirst+1; + for(GLsizei i=2;ioperator()(*(vfirst),*(vptr),*(vptr+1),false); } - case(GL_QUAD_STRIP): { - IndexPointer iptr = indices; - for(GLsizei i=3;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], - _vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)], - false); - } - break; + break; + } + case(GL_POINTS): { + const Vec3* vlast = &_vertexArrayPtr[first+count]; + for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),false); + break; + } + case(GL_LINES): { + const Vec3* vlast = &_vertexArrayPtr[first+count-1]; + for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); + break; + } + case(GL_LINE_STRIP): { + const Vec3* vlast = &_vertexArrayPtr[first+count-1]; + for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); + break; + } + case(GL_LINE_STRIP_ADJACENCY): { + const Vec3* vlast = &_vertexArrayPtr[first+count-2]; + for(const Vec3* vptr=&_vertexArrayPtr[first+1];vptroperator()(*(vptr),*(vptr+1),false); + break; + } + case(GL_LINE_LOOP): { + const Vec3* vlast = &_vertexArrayPtr[first+count-1]; + for(const Vec3* vptr=&_vertexArrayPtr[first];vptroperator()(*(vptr),*(vptr+1),false); + this->operator()(*(vlast),_vertexArrayPtr[first],false); + break; + } + default: + break; + } + } + + template + void drawElementsTemplate(GLenum mode,GLsizei count,const IndexType* indices) + { + if (indices==0 || count==0) return; + + typedef const IndexType* IndexPointer; + + switch(mode) + { + case(GL_TRIANGLES): { + IndexPointer ilast = &indices[count]; + for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false); + break; + } + case(GL_TRIANGLE_STRIP): { + IndexPointer iptr = indices; + for(GLsizei i=2;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)], + _vertexArrayPtr[*(iptr+1)],false); + else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], + _vertexArrayPtr[*(iptr+2)],false); } - case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN - case(GL_TRIANGLE_FAN): { - IndexPointer iptr = indices; - const Vec3& vfirst = _vertexArrayPtr[*iptr]; - ++iptr; - for(GLsizei i=2;ioperator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], - false); - } - break; + break; + } + case(GL_QUADS): { + IndexPointer iptr = indices; + for(GLsizei i=3;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], + _vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)], + false); } - case(GL_POINTS): { - IndexPointer ilast = &indices[count]; - for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],false); - break; + break; + } + case(GL_QUAD_STRIP): { + IndexPointer iptr = indices; + for(GLsizei i=3;ioperator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], + _vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)], + false); } - case(GL_LINES): { - IndexPointer ilast = &indices[count-1]; - for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], - false); - break; + break; + } + case(GL_POLYGON): // treat polygons as GL_TRIANGLE_FAN + case(GL_TRIANGLE_FAN): { + IndexPointer iptr = indices; + const Vec3& vfirst = _vertexArrayPtr[*iptr]; + ++iptr; + for(GLsizei i=2;ioperator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], + false); } - case(GL_LINE_STRIP): { - IndexPointer ilast = &indices[count-1]; - for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], - false); - break; - } - case(GL_LINE_STRIP_ADJACENCY): { - IndexPointer ilast = &indices[count-2]; - for(IndexPointer iptr=&indices[1];iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], - false); - break; - } - case(GL_LINE_LOOP): { - IndexPointer ilast = &indices[count-1]; - for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], - false); - this->operator()(_vertexArrayPtr[*(ilast)],_vertexArrayPtr[indices[0]], - false); - break; - } - default: - break; - } - } + break; + } + case(GL_POINTS): { + IndexPointer ilast = &indices[count]; + for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],false); + break; + } + case(GL_LINES): { + IndexPointer ilast = &indices[count-1]; + for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], + false); + break; + } + case(GL_LINE_STRIP): { + IndexPointer ilast = &indices[count-1]; + for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], + false); + break; + } + case(GL_LINE_STRIP_ADJACENCY): { + IndexPointer ilast = &indices[count-2]; + for(IndexPointer iptr=&indices[1];iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], + false); + break; + } + case(GL_LINE_LOOP): { + IndexPointer ilast = &indices[count-1]; + for(IndexPointer iptr=indices;iptroperator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], + false); + this->operator()(_vertexArrayPtr[*(ilast)],_vertexArrayPtr[indices[0]], + false); + break; + } + default: + break; + } + } - virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) - { - drawElementsTemplate(mode, count, indices); - } + virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) + { + drawElementsTemplate(mode, count, indices); + } - virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) - { - drawElementsTemplate(mode, count, indices); - } + virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) + { + drawElementsTemplate(mode, count, indices); + } - virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) - { - drawElementsTemplate(mode, count, indices); - } + virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) + { + drawElementsTemplate(mode, count, indices); + } - protected: +protected: - unsigned int _vertexArraySize; - const Vec3* _vertexArrayPtr; - }; + unsigned int _vertexArraySize; + const Vec3* _vertexArrayPtr; +}; } diff --git a/include/osg/TriangleIndexFunctor b/include/osg/TriangleIndexFunctor index bb4b2fb2c..2be753740 100644 --- a/include/osg/TriangleIndexFunctor +++ b/include/osg/TriangleIndexFunctor @@ -24,30 +24,12 @@ class TriangleIndexFunctor : public PrimitiveIndexFunctor, public T { public: - - virtual void setVertexArray(unsigned int,const Vec2*) - { - } - - virtual void setVertexArray(unsigned int ,const Vec3* ) - { - } - - virtual void setVertexArray(unsigned int,const Vec4* ) - { - } - - virtual void setVertexArray(unsigned int,const Vec2d*) - { - } - - virtual void setVertexArray(unsigned int ,const Vec3d* ) - { - } - - virtual void setVertexArray(unsigned int,const Vec4d* ) - { - } + virtual void setVertexArray(unsigned int,const Vec2*) {} + virtual void setVertexArray(unsigned int ,const Vec3*) {} + virtual void setVertexArray(unsigned int,const Vec4*) {} + virtual void setVertexArray(unsigned int,const Vec2d*) {} + virtual void setVertexArray(unsigned int ,const Vec3d*) {} + virtual void setVertexArray(unsigned int,const Vec4d*) {} virtual void drawArrays(GLenum mode,GLint first,GLsizei count) {