Reputation: 325
I've been using OpenGL in simple immediate mode for a while, and am trying to pass on to retained mode with display lists (which I sadly learned has been deprecated a while). What I would like to know, is when I type:
glNewList(list, GL_COMPILE);
glBegin(GL_TRIANGLE_FAN);
glVertex2f(0.0f, 0.0f);
for (int i = 0; i < 10; i++)
{
glVertex2f(radius * cos(i * 2.0f * PI / 9.0f), radius * sin(i * 2.0f * PI / 9.0f));
}
glEnd();
glEndList();
does OpenGL precalculate all the 10 vertices in for loop and send them to graphics card baked, like:
glVertex2f(0.5f, 0.0f);
glVertex2f(0.499f, 0.0055f);
//so and so forth 10 times...
or does it try to do the for loop (and many sin / cos operations) all over for each frame? In other words, is it reasonable to store such a round shape in display lists (and do the rest with glTranslatef, glRotatef, etc...) to avoid trigonometric operations in each frame update, or is there no performance gain at all?
Edit: To avoid a confusion, I intend to create this display list once using the for loop, and then call it by glCallList(list) in each frame update (i.e. glutDisplayFunc()). I do not create a list for each and every frame.
Upvotes: 1
Views: 295
Reputation: 52084
Only the GL command sequence and parameters are "baked" into the display list. Otherwise OpenGL would have to use some sort of terrifying longjmp()
monstrosity to re-execute (along with the complete process state at that point!) the code between glNewList()
/glEndList()
.
Upvotes: 3
Reputation: 48216
Display lists (and the immediate mode rendering it is provided for) are ancient deprecated functionality and the underlying mechanics were up to the driver, some may back it into a draw arrays call while others would just replay the calls with the parameters it got, non of your code is actually re-executed.
Instead you should do the baking explicitly by putting the data into a VBO and use glDrawArrays
.
Upvotes: 5