glDrawElements /Arrays with linked lists

Posts: 33
Joined: 2002.04
Post: #1
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?
Quote this message in a reply
Jeff Binder
Post: #2
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.
Quote this message in a reply
Post: #3
Have a look at this thread...

There is a really good app that shows the performance differences between the different rendering methods
Quote this message in a reply
Posts: 145
Joined: 2002.06
Post: #4
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!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  glDrawElements and Face indices Ashford 8 19,859 Nov 11, 2009 03:03 PM
Last Post: Ashford
  Display Lists and Obj. File Loader Problems merrill541 0 2,825 Oct 17, 2008 06:42 PM
Last Post: merrill541
  Agh! glDrawElements kills my artwork ferum 2 5,588 Nov 23, 2006 09:05 AM
Last Post: ferum
  glDrawElements question Falcor 20 19,090 Feb 2, 2006 02:50 PM
Last Post: akb825
  Display Lists or Vertex Arrays with texturing seven 6 5,751 Oct 17, 2005 09:24 AM
Last Post: seven