# 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 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.

##### 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 on other sites
VBO and triangle strips are very fast.

##### 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627665
• Total Posts
2978531
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 10
• 12
• 22
• 13