Removed old style OpenGL methods from PrimitiveFunctor classes/templates as these are no longer used or required.

This commit is contained in:
Robert Osfield 2017-04-27 15:04:44 +01:00
parent e7e372bad2
commit 48a3fc30f3
4 changed files with 56 additions and 195 deletions

View File

@ -97,38 +97,6 @@ public:
/// Mimics the OpenGL \c glDrawElements() function. /// Mimics the OpenGL \c glDrawElements() function.
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0; 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;
void useVertexCacheAsVertexArray()
{
setVertexArray(_vertexCache.size(),&_vertexCache.front());
}
std::vector<Vec3> _vertexCache;
bool _treatVertexDataAsTemporary;
}; };
class PrimitiveIndexFunctor class PrimitiveIndexFunctor
@ -149,18 +117,6 @@ public:
virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0; virtual void drawElements(GLenum mode,GLsizei count,const GLubyte* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0; virtual void drawElements(GLenum mode,GLsizei count,const GLushort* indices) = 0;
virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0; virtual void drawElements(GLenum mode,GLsizei count,const GLuint* indices) = 0;
virtual void begin(GLenum mode) = 0;
virtual void vertex(unsigned int pos) = 0;
virtual void end() = 0;
void useVertexCacheAsVertexArray()
{
setVertexArray(_vertexCache.size(),&_vertexCache.front());
}
std::vector<Vec3> _vertexCache;
bool _treatVertexDataAsTemporary;
}; };
class DrawElements; class DrawElements;

View File

@ -46,15 +46,10 @@ namespace osg {
{ {
_vertexArraySize=0; _vertexArraySize=0;
_vertexArrayPtr=0; _vertexArrayPtr=0;
_modeCache=0;
_treatVertexDataAsTemporary=false;
} }
virtual ~TemplatePrimitiveFunctor() {} virtual ~TemplatePrimitiveFunctor() {}
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"<<std::endl; notify(WARN)<<"Triangle Functor does not support Vec2* vertex arrays"<<std::endl;
@ -96,15 +91,15 @@ namespace osg {
case(GL_TRIANGLES): { case(GL_TRIANGLES): {
const Vec3* vlast = &_vertexArrayPtr[first+count]; const Vec3* vlast = &_vertexArrayPtr[first+count];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
break; break;
} }
case(GL_TRIANGLE_STRIP): { case(GL_TRIANGLE_STRIP): {
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=2;i<count;++i,++vptr) for(GLsizei i=2;i<count;++i,++vptr)
{ {
if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),_treatVertexDataAsTemporary); if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),false);
else this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); else this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
} }
break; break;
} }
@ -112,7 +107,7 @@ namespace osg {
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=4,vptr+=4) for(GLsizei i=3;i<count;i+=4,vptr+=4)
{ {
this->operator()(*(vptr),*(vptr+1),*(vptr+2),*(vptr+3),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+2),*(vptr+3),false);
} }
break; break;
} }
@ -120,7 +115,7 @@ namespace osg {
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=2,vptr+=2) for(GLsizei i=3;i<count;i+=2,vptr+=2)
{ {
this->operator()(*(vptr),*(vptr+1),*(vptr+3),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+3),*(vptr+2),false);
} }
break; break;
} }
@ -130,39 +125,39 @@ namespace osg {
const Vec3* vptr = vfirst+1; const Vec3* vptr = vfirst+1;
for(GLsizei i=2;i<count;++i,++vptr) for(GLsizei i=2;i<count;++i,++vptr)
{ {
this->operator()(*(vfirst),*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vfirst),*(vptr),*(vptr+1),false);
} }
break; break;
} }
case(GL_POINTS): { case(GL_POINTS): {
const Vec3* vlast = &_vertexArrayPtr[first+count]; const Vec3* vlast = &_vertexArrayPtr[first+count];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1)
this->operator()(*(vptr),_treatVertexDataAsTemporary); this->operator()(*(vptr),false);
break; break;
} }
case(GL_LINES): { case(GL_LINES): {
const Vec3* vlast = &_vertexArrayPtr[first+count-1]; const Vec3* vlast = &_vertexArrayPtr[first+count-1];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=2) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=2)
this->operator()(*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),false);
break; break;
} }
case(GL_LINE_STRIP): { case(GL_LINE_STRIP): {
const Vec3* vlast = &_vertexArrayPtr[first+count-1]; const Vec3* vlast = &_vertexArrayPtr[first+count-1];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1)
this->operator()(*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),false);
break; break;
} }
case(GL_LINE_STRIP_ADJACENCY): { case(GL_LINE_STRIP_ADJACENCY): {
const Vec3* vlast = &_vertexArrayPtr[first+count-2]; const Vec3* vlast = &_vertexArrayPtr[first+count-2];
for(const Vec3* vptr=&_vertexArrayPtr[first+1];vptr<vlast;vptr+=1) for(const Vec3* vptr=&_vertexArrayPtr[first+1];vptr<vlast;vptr+=1)
this->operator()(*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),false);
break; break;
} }
case(GL_LINE_LOOP): { case(GL_LINE_LOOP): {
const Vec3* vlast = &_vertexArrayPtr[first+count-1]; const Vec3* vlast = &_vertexArrayPtr[first+count-1];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=1)
this->operator()(*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),false);
this->operator()(*(vlast),_vertexArrayPtr[first],_treatVertexDataAsTemporary); this->operator()(*(vlast),_vertexArrayPtr[first],false);
break; break;
} }
default: default:
@ -182,7 +177,7 @@ namespace osg {
case(GL_TRIANGLES): { case(GL_TRIANGLES): {
IndexPointer ilast = &indices[count]; IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3) for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
break; break;
} }
case(GL_TRIANGLE_STRIP): { case(GL_TRIANGLE_STRIP): {
@ -190,9 +185,9 @@ namespace osg {
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)], if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],
_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); _vertexArrayPtr[*(iptr+1)],false);
else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],
_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); _vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -202,7 +197,7 @@ namespace osg {
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],
_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)], _vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],
_treatVertexDataAsTemporary); false);
} }
break; break;
} }
@ -212,7 +207,7 @@ namespace osg {
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],
_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)], _vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],
_treatVertexDataAsTemporary); false);
} }
break; break;
} }
@ -224,44 +219,44 @@ namespace osg {
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)], this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],
_treatVertexDataAsTemporary); false);
} }
break; break;
} }
case(GL_POINTS): { case(GL_POINTS): {
IndexPointer ilast = &indices[count]; IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=1) for(IndexPointer iptr=indices;iptr<ilast;iptr+=1)
this->operator()(_vertexArrayPtr[*iptr],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*iptr],false);
break; break;
} }
case(GL_LINES): { case(GL_LINES): {
IndexPointer ilast = &indices[count-1]; IndexPointer ilast = &indices[count-1];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=2) for(IndexPointer iptr=indices;iptr<ilast;iptr+=2)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],
_treatVertexDataAsTemporary); false);
break; break;
} }
case(GL_LINE_STRIP): { case(GL_LINE_STRIP): {
IndexPointer ilast = &indices[count-1]; IndexPointer ilast = &indices[count-1];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=1) for(IndexPointer iptr=indices;iptr<ilast;iptr+=1)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],
_treatVertexDataAsTemporary); false);
break; break;
} }
case(GL_LINE_STRIP_ADJACENCY): { case(GL_LINE_STRIP_ADJACENCY): {
IndexPointer ilast = &indices[count-2]; IndexPointer ilast = &indices[count-2];
for(IndexPointer iptr=&indices[1];iptr<ilast;iptr+=1) for(IndexPointer iptr=&indices[1];iptr<ilast;iptr+=1)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],
_treatVertexDataAsTemporary); false);
break; break;
} }
case(GL_LINE_LOOP): { case(GL_LINE_LOOP): {
IndexPointer ilast = &indices[count-1]; IndexPointer ilast = &indices[count-1];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=1) for(IndexPointer iptr=indices;iptr<ilast;iptr+=1)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)], this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],
_treatVertexDataAsTemporary); false);
this->operator()(_vertexArrayPtr[*(ilast)],_vertexArrayPtr[indices[0]], this->operator()(_vertexArrayPtr[*(ilast)],_vertexArrayPtr[indices[0]],
_treatVertexDataAsTemporary); false);
break; break;
} }
default: default:
@ -285,41 +280,10 @@ namespace osg {
drawElementsTemplate(mode, count, indices); drawElementsTemplate(mode, count, indices);
} }
/** Note:
* begin(..),vertex(..) & end() are convenience methods for adapting
* non vertex array primitives to vertex array based primitives.
* This is done to simplify the implementation of primitive functor
* subclasses - users only need override drawArray and drawElements.
*/
virtual void begin(GLenum mode)
{
_modeCache = mode;
_vertexCache.clear();
}
virtual void vertex(const Vec2& vert) { _vertexCache.push_back(osg::Vec3(vert[0],vert[1],0.0f)); }
virtual void vertex(const Vec3& vert) { _vertexCache.push_back(vert); }
virtual void vertex(const Vec4& vert) { _vertexCache.push_back(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); }
virtual void vertex(float x,float y) { _vertexCache.push_back(osg::Vec3(x,y,0.0f)); }
virtual void vertex(float x,float y,float z) { _vertexCache.push_back(osg::Vec3(x,y,z)); }
virtual void vertex(float x,float y,float z,float w) { _vertexCache.push_back(osg::Vec3(x,y,z)/w); }
virtual void end()
{
if (!_vertexCache.empty())
{
setVertexArray(_vertexCache.size(),&_vertexCache.front());
_treatVertexDataAsTemporary = true;
drawArrays(_modeCache,0,_vertexCache.size());
}
}
protected: protected:
unsigned int _vertexArraySize; unsigned int _vertexArraySize;
const Vec3* _vertexArrayPtr; const Vec3* _vertexArrayPtr;
GLenum _modeCache;
}; };

View File

@ -43,15 +43,10 @@ public:
{ {
_vertexArraySize=0; _vertexArraySize=0;
_vertexArrayPtr=0; _vertexArrayPtr=0;
_modeCache=0;
_treatVertexDataAsTemporary=false;
} }
virtual ~TriangleFunctor() {} 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"<<std::endl; notify(WARN)<<"Triangle Functor does not support Vec2* vertex arrays"<<std::endl;
@ -93,7 +88,7 @@ public:
{ {
const Vec3* vlast = &_vertexArrayPtr[first+count]; const Vec3* vlast = &_vertexArrayPtr[first+count];
for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3) for(const Vec3* vptr=&_vertexArrayPtr[first];vptr<vlast;vptr+=3)
this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
break; break;
} }
case(GL_TRIANGLE_STRIP): case(GL_TRIANGLE_STRIP):
@ -101,8 +96,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=2;i<count;++i,++vptr) for(GLsizei i=2;i<count;++i,++vptr)
{ {
if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),_treatVertexDataAsTemporary); if ((i%2)) this->operator()(*(vptr),*(vptr+2),*(vptr+1),false);
else this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); else this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
} }
break; break;
} }
@ -111,8 +106,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=4,vptr+=4) for(GLsizei i=3;i<count;i+=4,vptr+=4)
{ {
this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
this->operator()(*(vptr),*(vptr+2),*(vptr+3),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+2),*(vptr+3),false);
} }
break; break;
} }
@ -121,8 +116,8 @@ public:
const Vec3* vptr = &_vertexArrayPtr[first]; const Vec3* vptr = &_vertexArrayPtr[first];
for(GLsizei i=3;i<count;i+=2,vptr+=2) for(GLsizei i=3;i<count;i+=2,vptr+=2)
{ {
this->operator()(*(vptr),*(vptr+1),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr),*(vptr+1),*(vptr+2),false);
this->operator()(*(vptr+1),*(vptr+3),*(vptr+2),_treatVertexDataAsTemporary); this->operator()(*(vptr+1),*(vptr+3),*(vptr+2),false);
} }
break; break;
} }
@ -133,7 +128,7 @@ public:
const Vec3* vptr = vfirst+1; const Vec3* vptr = vfirst+1;
for(GLsizei i=2;i<count;++i,++vptr) for(GLsizei i=2;i<count;++i,++vptr)
{ {
this->operator()(*(vfirst),*(vptr),*(vptr+1),_treatVertexDataAsTemporary); this->operator()(*(vfirst),*(vptr),*(vptr+1),false);
} }
break; break;
} }
@ -159,7 +154,7 @@ public:
{ {
IndexPointer ilast = &indices[count]; IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3) for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
break; break;
} }
case(GL_TRIANGLE_STRIP): case(GL_TRIANGLE_STRIP):
@ -167,8 +162,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],false);
else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -177,8 +172,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4) for(GLsizei i=3;i<count;i+=4,iptr+=4)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],false);
} }
break; break;
} }
@ -187,8 +182,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2) for(GLsizei i=3;i<count;i+=2,iptr+=2)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -200,7 +195,7 @@ public:
++iptr; ++iptr;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],false);
} }
break; break;
} }
@ -227,7 +222,7 @@ public:
IndexPointer ilast = &indices[count]; IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3) for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
{ {
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -236,8 +231,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],false);
else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -246,8 +241,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4) for(GLsizei i=3;i<count;i+=4,iptr+=4)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],false);
} }
break; break;
} }
@ -256,8 +251,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2) for(GLsizei i=3;i<count;i+=2,iptr+=2)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -269,7 +264,7 @@ public:
++iptr; ++iptr;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],false);
} }
break; break;
} }
@ -295,7 +290,7 @@ public:
{ {
IndexPointer ilast = &indices[count]; IndexPointer ilast = &indices[count];
for(IndexPointer iptr=indices;iptr<ilast;iptr+=3) for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*iptr],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
break; break;
} }
case(GL_TRIANGLE_STRIP): case(GL_TRIANGLE_STRIP):
@ -303,8 +298,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); if ((i%2)) this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+1)],false);
else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); else this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -313,8 +308,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=4,iptr+=4) for(GLsizei i=3;i<count;i+=4,iptr+=4)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+2)],_vertexArrayPtr[*(iptr+3)],false);
} }
break; break;
} }
@ -323,8 +318,8 @@ public:
IndexPointer iptr = indices; IndexPointer iptr = indices;
for(GLsizei i=3;i<count;i+=2,iptr+=2) for(GLsizei i=3;i<count;i+=2,iptr+=2)
{ {
this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+2)],false);
this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],_treatVertexDataAsTemporary); this->operator()(_vertexArrayPtr[*(iptr+1)],_vertexArrayPtr[*(iptr+3)],_vertexArrayPtr[*(iptr+2)],false);
} }
break; break;
} }
@ -336,7 +331,7 @@ public:
++iptr; ++iptr;
for(GLsizei i=2;i<count;++i,++iptr) for(GLsizei i=2;i<count;++i,++iptr)
{ {
this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],_treatVertexDataAsTemporary); this->operator()(vfirst,_vertexArrayPtr[*(iptr)],_vertexArrayPtr[*(iptr+1)],false);
} }
break; break;
} }
@ -350,43 +345,11 @@ public:
} }
} }
/** Note:
* begin(..),vertex(..) & end() are convenience methods for adapting
* non vertex array primitives to vertex array based primitives.
* This is done to simplify the implementation of primitive functor
* subclasses - users only need override drawArray and drawElements.
*/
virtual void begin(GLenum mode)
{
_modeCache = mode;
_vertexCache.clear();
}
virtual void vertex(const Vec2& vert) { _vertexCache.push_back(osg::Vec3(vert[0],vert[1],0.0f)); }
virtual void vertex(const Vec3& vert) { _vertexCache.push_back(vert); }
virtual void vertex(const Vec4& vert) { _vertexCache.push_back(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); }
virtual void vertex(float x,float y) { _vertexCache.push_back(osg::Vec3(x,y,0.0f)); }
virtual void vertex(float x,float y,float z) { _vertexCache.push_back(osg::Vec3(x,y,z)); }
virtual void vertex(float x,float y,float z,float w) { _vertexCache.push_back(osg::Vec3(x,y,z)/w); }
virtual void end()
{
if (!_vertexCache.empty())
{
setVertexArray(_vertexCache.size(),&_vertexCache.front());
_treatVertexDataAsTemporary = true;
drawArrays(_modeCache,0,_vertexCache.size());
}
}
protected: protected:
unsigned int _vertexArraySize; unsigned int _vertexArraySize;
const Vec3* _vertexArrayPtr; const Vec3* _vertexArrayPtr;
GLenum _modeCache;
}; };

View File

@ -49,25 +49,6 @@ public:
{ {
} }
virtual void begin(GLenum mode)
{
_modeCache = mode;
_indexCache.clear();
}
virtual void vertex(unsigned int vert)
{
_indexCache.push_back(vert);
}
virtual void end()
{
if (!_indexCache.empty())
{
drawElements(_modeCache,_indexCache.size(),&_indexCache.front());
}
}
virtual void drawArrays(GLenum mode,GLint first,GLsizei count) virtual void drawArrays(GLenum mode,GLint first,GLsizei count)
{ {
switch(mode) switch(mode)
@ -334,9 +315,6 @@ public:
break; break;
} }
} }
GLenum _modeCache;
std::vector<GLuint> _indexCache;
}; };
} }