HP j6700 OpenGL Implementation Guide for HP-UX 11.x - Page 57

GL_TRIANGLES, glNormal3fv&v2

Page 57 highlights

Chapter 5 programming hints OpenGL performance hints ... 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); 55

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62

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);