Sign in to follow this  
Skyy

OpenGL Trying to pick up speed with glInterleavedArrays

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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
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 this post


Link to post
Share on other sites
Quote:
Original post by Skyy
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?


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.

Share this post


Link to post
Share on other sites
That's strange, I tried just moving my render call gl*Pointers and glDrawElements inside the display list creation and nothing came up.

Hmm.. Should work. Oh well, double checking.

Share this post


Link to post
Share on other sites
Don't forget that the modern Vertex Array Object stuff allows you to combine all of the Pointer calls into a single block, which is supposedly more efficient.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this