# OpenGL Trying to pick up speed with glInterleavedArrays

This topic is 3338 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

In my current implementation I've got vector for vertices, a vector for normals and a indice vector. Currently my drawing looks like this:
glVertexPointer( 3, GL_FLOAT, 0, &V[0] );
glNormalPointer( GL_FLOAT, 0, &N[0] );
glDrawElements ( GL_TRIANGLES, I.size(), GL_UNSIGNED_INT, &I[0] );

I = incides, V = vertices and N = normals in case someone didn't figure it out. Works fine, nothing wrong there. But I keep on hearing that I could actually pick up more speed by using glInterleavedArrays and started to read on it. Unfortunately there wasn't that much information on the magical inverwebs on it or my google-fu is just not strong enough. Naturally I stumbled on this: http://www.opengl.org/sdk/docs/man/xhtml/glInterleavedArrays.xml But thats about all there is to it. With using my current structuring of the world I can easily just do:
glInterleavedArrays( GL_V3F, 0, &V[0] );
glDrawElements( GL_TRIANGLES, I.size(), GL_UNSIGNED_INT, &I[0] );

and voila, I've got my scene showing up again. The problem of course is that I don't have correct normals anymore. For glInterleavedArrays I have to have all my normals and vertices in same array if I use the format
GL_N3F_V3F
In what "order" do the normals and vertices have to be in the vector? NormalX, NormalY, NormalZ, VerticeX, VerticeY, VerticeZ? Or NormalX, VerticeX, NormalY, VerticeY .. etc. ? And after I've got my normals and vertices in same array, can I still blaze through them with the glDrawElements and everything works? Could I just do this?
glInterleavedArrays( GL_N3F_V3F, 0, &V[0] );
glDrawElements( GL_TRIANGLES, I.size(), GL_UNSIGNED_INT, &I[0] );

Of course I would have to generate my indice array so that it again contains the correct indices for the new vertice indexes. Just wondering since I don't feel like going major restructuring of things and loading of data before I'm sure how it works so I can design the best way to implement it :) Thanks.

##### Share on other sites
glInterleavedArrays is actually an unnecessary command. You can get the same results with a sequence of glWhateverPointer calls, passing the address of the first component of each for the pointer, and the total length of a vertex as the stride.

Anyways, to answer your question, fir GL_V3F_N3F, you'd have vertex X,Y,Z, followed by normal X,Y,Z. But you wouldn't interleave the actual components.

##### Share on other sites
Thanks for answers Sneftel. So what is the "fastest" way to draw indexed vertex data with openGL anyway? Am I already "there" or is there some sort of extra magic to it?

And is there faster way to draw my indexed vertex data than with the glDrawElements? Also can I create a display list from indexed vertex data, if I can, do I win anything with that? OR should I start turning things into VBO's?

Majorly confused with these different functions and calls.. >:&

##### Share on other sites
VBOs can be faster than index arrays. Beyond that, the only major improvement would be optimizing vertex ordering to maximize vertex cache coherency. NVTriStrip is useful for that.

##### Share on other sites
Quote:
 glInterleavedArrays is actually an unnecessary command.

Testing this is to be coming up in my project soon but most people are storing all their objects into one VBO. If you throw all vertices in first and then normals, you also have a huge jump in the cache for this models data. I've never tried it, but I think that is a good assumption that you want vtx,norm,tex interleaved? Yes/No?

##### Share on other sites
Can indexed vertex data be turned into display lists? Is there any reason to do? I've got thousands and thousands of static meshes I need to just render as fast as possible (of course I've implemented different culling methods) but when it comes down to raw rendering I need to do it as quickly as possible.

So would it be any good to turn the static geometry (indexed vertex data) into display lists? IF that can be done. I'm assuming DL's are faster than indexed vertex data with glDrawElements, am I correct?

##### Share on other sites
Of course you can "turn into display list". What makes you think you can't?
It will be faster if the driver can optimize it. If your VBO code is optimal, then it will be the same speed.

##### Share on other sites
What made me think this way? Because I was stupid enough to try and do glDrawElements in the display list creation :P Gave no errors and didn't render a thing, silly me.

So basically I should create display list with the basic glBegin(); and glEnd(); "mumbojambo" and the gfx driver will optimize it if possible?

##### Share on other sites
Quote:
Quote:
 glInterleavedArrays is actually an unnecessary command.

Testing this is to be coming up in my project soon but most people are storing all their objects into one VBO. If you throw all vertices in first and then normals, you also have a huge jump in the cache for this models data. I've never tried it, but I think that is a good assumption that you want vtx,norm,tex interleaved? Yes/No?
I don't think you quite understand. My point is that you don't need glInterleavedArrays in order to have interleaved arrays. glInterleavedArrays gives you a small selection of interleaving formats, and if one of those happens to be the one you want then awesome, but simply calling the *Pointer commands directly will give you more flexibility over how exactly your arrays are interleaved.

##### Share on other sites
Quote:
 Original post by SkyyWhat made me think this way? Because I was stupid enough to try and do glDrawElements in the display list creation :P Gave no errors and didn't render a thing, silly me. So basically I should create display list with the basic glBegin(); and glEnd(); "mumbojambo" and the gfx driver will optimize it if possible?

I've had not had problems with putting glDrawElements in a display list. The OpenGL specification isn't against it.
There is no sense of using glBegin when glDrawElements and glDrawRangeElements exist but if you are more comfortable with glBegin, then use it.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631434
• Total Posts
3000051
×