glDrawElements /Arrays with linked lists
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?
What kind of speed gains might I get by switching to arrays? Is there some way I can do it with linked lists still?
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:
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.
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:
Code:
1 2
+--+
| /|
|/ |
+--+
3 4You 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.
Have a look at this thread...
http://www.idevgames.com/forum/showthrea...awelements
There is a really good app that shows the performance differences between the different rendering methods
http://www.idevgames.com/forum/showthrea...awelements
There is a really good app that shows the performance differences between the different rendering methods
Quote: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.
"He who breaks a thing to find out what it is, has left the path of wisdom."
- Gandalf the Gray-Hat
Bring Alistair Cooke's America to DVD!
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| glDrawElements and Face indices | Ashford | 8 | 7,972 |
Nov 11, 2009 03:03 PM Last Post: Ashford |
|
| Display Lists and Obj. File Loader Problems | merrill541 | 0 | 1,655 |
Oct 17, 2008 06:42 PM Last Post: merrill541 |
|
| Agh! glDrawElements kills my artwork | ferum | 2 | 2,979 |
Nov 23, 2006 09:05 AM Last Post: ferum |
|
| glDrawElements question | Falcor | 20 | 10,034 |
Feb 2, 2006 02:50 PM Last Post: akb825 |
|
| Display Lists or Vertex Arrays with texturing | seven | 6 | 3,316 |
Oct 17, 2005 09:24 AM Last Post: seven |
|

