14 #ifndef OSG_TRIANGLEINDEXFUNCTOR
15 #define OSG_TRIANGLEINDEXFUNCTOR 1
17 #include <osg/PrimitiveSet>
58 virtual void vertex(
unsigned int vert)
71 virtual void drawArrays(GLenum mode,GLint first,GLsizei count)
77 unsigned int pos=first;
78 for(GLsizei i=2;i<count;i+=3,pos+=3)
80 this->operator()(pos,pos+1,pos+2);
84 case(GL_TRIANGLE_STRIP):
86 unsigned int pos=first;
87 for(GLsizei i=2;i<count;++i,++pos)
89 if ((i%2)) this->operator()(pos,pos+2,pos+1);
90 else this->operator()(pos,pos+1,pos+2);
96 unsigned int pos=first;
97 for(GLsizei i=3;i<count;i+=4,pos+=4)
99 this->operator()(pos,pos+1,pos+2);
100 this->operator()(pos,pos+2,pos+3);
106 unsigned int pos=first;
107 for(GLsizei i=3;i<count;i+=2,pos+=2)
109 this->operator()(pos,pos+1,pos+2);
110 this->operator()(pos+1,pos+3,pos+2);
115 case(GL_TRIANGLE_FAN):
117 unsigned int pos=first+1;
118 for(GLsizei i=2;i<count;++i,++pos)
120 this->operator()(first,pos,pos+1);
134 virtual void drawElements(GLenum mode,GLsizei count,
const GLubyte* indices)
136 if (indices==0 || count==0)
return;
138 typedef GLubyte Index;
139 typedef const Index* IndexPointer;
145 IndexPointer ilast = &indices[count];
146 for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
147 this->
operator()(*iptr,*(iptr+1),*(iptr+2));
150 case(GL_TRIANGLE_STRIP):
152 IndexPointer iptr = indices;
153 for(GLsizei i=2;i<count;++i,++iptr)
155 if ((i%2)) this->
operator()(*(iptr),*(iptr+2),*(iptr+1));
156 else this->operator()(*(iptr),*(iptr+1),*(iptr+2));
162 IndexPointer iptr = indices;
163 for(GLsizei i=3;i<count;i+=4,iptr+=4)
165 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
166 this->operator()(*(iptr),*(iptr+2),*(iptr+3));
172 IndexPointer iptr = indices;
173 for(GLsizei i=3;i<count;i+=2,iptr+=2)
175 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
176 this->operator()(*(iptr+1),*(iptr+3),*(iptr+2));
181 case(GL_TRIANGLE_FAN):
183 IndexPointer iptr = indices;
186 for(GLsizei i=2;i<count;++i,++iptr)
188 this->operator()(first,*(iptr),*(iptr+1));
202 virtual void drawElements(GLenum mode,GLsizei count,
const GLushort* indices)
204 if (indices==0 || count==0)
return;
206 typedef GLushort Index;
207 typedef const Index* IndexPointer;
213 IndexPointer ilast = &indices[count];
214 for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
215 this->
operator()(*iptr,*(iptr+1),*(iptr+2));
218 case(GL_TRIANGLE_STRIP):
220 IndexPointer iptr = indices;
221 for(GLsizei i=2;i<count;++i,++iptr)
223 if ((i%2)) this->
operator()(*(iptr),*(iptr+2),*(iptr+1));
224 else this->operator()(*(iptr),*(iptr+1),*(iptr+2));
230 IndexPointer iptr = indices;
231 for(GLsizei i=3;i<count;i+=4,iptr+=4)
233 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
234 this->operator()(*(iptr),*(iptr+2),*(iptr+3));
240 IndexPointer iptr = indices;
241 for(GLsizei i=3;i<count;i+=2,iptr+=2)
243 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
244 this->operator()(*(iptr+1),*(iptr+3),*(iptr+2));
249 case(GL_TRIANGLE_FAN):
251 IndexPointer iptr = indices;
254 for(GLsizei i=2;i<count;++i,++iptr)
256 this->operator()(first,*(iptr),*(iptr+1));
270 virtual void drawElements(GLenum mode,GLsizei count,
const GLuint* indices)
272 if (indices==0 || count==0)
return;
274 typedef GLuint Index;
275 typedef const Index* IndexPointer;
281 IndexPointer ilast = &indices[count];
282 for(IndexPointer iptr=indices;iptr<ilast;iptr+=3)
283 this->
operator()(*iptr,*(iptr+1),*(iptr+2));
286 case(GL_TRIANGLE_STRIP):
288 IndexPointer iptr = indices;
289 for(GLsizei i=2;i<count;++i,++iptr)
291 if ((i%2)) this->
operator()(*(iptr),*(iptr+2),*(iptr+1));
292 else this->operator()(*(iptr),*(iptr+1),*(iptr+2));
298 IndexPointer iptr = indices;
299 for(GLsizei i=3;i<count;i+=4,iptr+=4)
301 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
302 this->operator()(*(iptr),*(iptr+2),*(iptr+3));
308 IndexPointer iptr = indices;
309 for(GLsizei i=3;i<count;i+=2,iptr+=2)
311 this->operator()(*(iptr),*(iptr+1),*(iptr+2));
312 this->operator()(*(iptr+1),*(iptr+3),*(iptr+2));
317 case(GL_TRIANGLE_FAN):
319 IndexPointer iptr = indices;
322 for(GLsizei i=2;i<count;++i,++iptr)
324 this->operator()(first,*(iptr),*(iptr+1));
virtual void setVertexArray(unsigned int, const Vec3d *)
virtual void setVertexArray(unsigned int, const Vec3 *)
std::vector< GLuint > _indexCache
virtual void setVertexArray(unsigned int, const Vec2 *)
virtual void setVertexArray(unsigned int, const Vec4 *)
virtual void drawElements(GLenum mode, GLsizei count, const GLushort *indices)
virtual void setVertexArray(unsigned int, const Vec4d *)
virtual void drawElements(GLenum mode, GLsizei count, const GLubyte *indices)
virtual void setVertexArray(unsigned int, const Vec2d *)
virtual void vertex(unsigned int vert)
virtual void drawArrays(GLenum mode, GLint first, GLsizei count)
virtual void drawElements(GLenum mode, GLsizei count, const GLuint *indices)
virtual void begin(GLenum mode)