View Full Version : glDrawElements /Arrays with linked lists
Nickolei
2002.08.20, 01:48 AM
i currently store model verticies/normals in linked lists and draw the objects "normally" (ie without using glDrawArrays or anything of the sort).
What kind of speed gains might I get by switching to arrays? Is there some way I can do it with linked lists still?
Jeff Binder
2002.08.20, 02:19 PM
It depends on your situation, but chances are, it would speed things up a lot. You've got a lot going on for each vertex, and it's best to let that hardware take care of all of it.
If the vertices in the linked list are all stored consecutively in memory, you may be able to use them with glInterleavedArrays(), but this probably isn't the case.
You may want to consider storing the vertices, texcoords, normals, and colors in separate arrays (of floats), and sending each to GL with gl*Pointer(). This way you could turn off one of the arrays if you don't want it.
The best way to draw these arrays is to store the indices separately from the vertices. That is, to draw this shape:
1 2
+--+
| /|
|/ |
+--+
3 4
You can send GL the four numbered vertices, then draw them in the order 1 2 3 3 2 4. Vertices 2 and 3 are each used twice, but you only need to send each of them to GL once, saving time. You can use glDrawElements() to do this. Obviously, a linked list is not what you want if you're going to do it this way.
henryj
2002.08.20, 09:06 PM
Have a look at this thread...
http://www.idevgames.com/forum/showthread.php?s=&threadid=422&highlight=drawelements
There is a really good app that shows the performance differences between the different rendering methods
Originally posted by henryj
There is a really good app that shows the performance differences between the different rendering methods
I would hardly call that app "really good". But to make a long story short: using individual calls for each vertex is the SLOWEST POSSIBLE way to draw your geometry. glDrawElements with standard arrays, configured as I show, is near-optimal. Sorting into tri-strips is important on newer cards (rage128 and up) but detremental on Rage Pros.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.