programming hints
OpenGL performance hints
Chapter 5 55
... many more vertices...
glEnd();
than this:
glBegin(GL_TRIANGLES);
glColor3f(1,2,3);
glVertex3f(...);
... many more vertices...
glEnd();
For performance efficiency avoid glMaterial state changes, especially
within a glBegin/glEnd pair.
regular primitive data
If the vertex data that you give to a display list is regular (that is, every
vertex has the same data associated with it), it is possible for the display
list to optimize the primitive much more effectively than if the data is not
regular.
For example if you wanted to give only a single normal for each face in a
GL_TRIANGLES primitive, the most intuitive way to get the best
performance would look like this:
glBegin(GL_TRIANGLES);
glNormal3fv(&v1);
glVertex3fv(&p1); glVertex3fv(&p2); glVertex3fv(&p3);
glNormal3fv(&v2);
glVertex3fv(&p4); glVertex3fv(&p5); glVertex3fv(&p6);
...
glEnd();
In immediate mode, this would give you the best performance. However,
if you are putting these calls into a display list, you will get much better
performance by duplicating the normal for each vertex, thereby giving
regular data to the display list:
glBegin(GL_TRIANGLES);
glNormal3fv(&v1); glVertex3fv(&p1);
glNormal3fv(&v1); glVertex3fv(&p2);
glNormal3fv(&v1); glVertex3fv(&p3);
glNormal3fv(&v2); glVertex3fv(&p4);
OGLImp.book Page 55 Tuesday, February 14, 2006 9:15 AM