PDA

View Full Version : Display lists vs. Vertex Arrays



09-20-2003, 07:55 AM
I need to render a height field, consisting of filled triangles with normals, but no texture.
The easiest way would be to render the whole thing with GL_TRIANGLES and compile it into a display list.
If I put some work into it, I could optimize the order of the points in the height field and use a vertex array and GL_TRIANGLE_STRIP.
So now I wonder, is it worth the extra effort or will OpenGL optimize my code so much that the display list will be as fast as the vertex array?

Orzech
09-20-2003, 11:55 AM
You see - display lists are something completly different from vertex arrays. You can use DL to optimize your rendering and calculations but you aren't guaranteed that it's going to be any faster - at least it won't be worse. It depends on particular OpenGL implementation really. In some cases, like lighting calculations, display lists can give a really big increase of the performance.

Vertex arrays are used to store a static data in video memory. Thus, time to acces the data stored there is shortest. That's for sure. It works always the same and display lists do not.

Having on mind that it isn't really hard to use vertex arrays I think you should try it. All you have to do is to pass a pointer to the data and then call the drawing function. Try google...

09-20-2003, 11:16 PM
But say I have a function called DrawScene, which draws all the triangles and calculates the normals for all the faces, then if I compile this function into a display list, wouldn't OpenGL store the calculated normals so that I don't have to recalculate them, thus speeding the program up?
The hard thing with a vertex array would be to figure out in what order I need to have my points for GL_TRIANGLE_STRIP to interpret it correctly. How would I make a height map for use with GL_TRIANGLE_STRIP with each point stored only once?

Bob
09-20-2003, 11:47 PM
But say I have a function called DrawScene, which draws all the triangles and calculates the normals for all the faces, then if I compile this function into a display list, wouldn't OpenGL store the calculated normals so that I don't have to recalculate them, thus speeding the program up?

If OpenGL can store precomputed normals, then so can you. Why are you recalculating them every time?


The hard thing with a vertex array would be to figure out in what order I need to have my points for GL_TRIANGLE_STRIP to interpret it correctly. How would I make a height map for use with GL_TRIANGLE_STRIP with each point stored only once?
You'll be surprised how far you can get with a pen and a paper. Draw all points in the heightmap from above. Then build the surface using triangle strips. You will see a pattern in how you access the vertices.

[This message has been edited by Bob (edited 09-21-2003).]

Orzech
09-21-2003, 02:02 AM
Originally posted by Hannes:
The hard thing with a vertex array would be to figure out in what order I need to have my points for GL_TRIANGLE_STRIP to interpret it correctly. How would I make a height map for use with GL_TRIANGLE_STRIP with each point stored only once?

I agree with Bob. It isn't anything hard. http://www.opengl.org/discussion_boards/ubb/smile.gif

09-21-2003, 08:31 AM
If OpenGL can store precomputed normals, then so can you. Why are you recalculating them every time?Yeah, sure I can. It's simply more comfortable to have OpenGL do it. And I was wondering whether it will do any more optimizing while compiling the display list. But I guess it's up to the implementation?


You'll be surprised how far you can get with a pen and a paper. Draw all points in the heightmap from above. Then build the surface using triangle strips. You will see a pattern in how you access the vertices.I did try the pen and paper method, but since each vertex is used in several triangles it seemed like I needed to store the same vertex several times. Perhaps I was just too tired, I will have a try at it again.

zeckensack
09-21-2003, 09:38 AM
Hannes,
you can use indices to avoid duplicating vertices. You'll end up duplicating indices, but they are only four bytes each (or two, if you use GL_UNSIGNED_SHORT).

DrawElements is the function you should look up in the spec http://www.opengl.org/discussion_boards/ubb/smile.gif