Sign in to follow this  
Skyy

OpenGL Trying to pick up speed with glInterleavedArrays

Recommended Posts

Skyy    139
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
Sneftel    1788
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
Skyy    139
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
Sneftel    1788
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
dpadam450    2357
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
Skyy    139
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
V-man    813
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
Skyy    139
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
Sneftel    1788
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
V-man    813
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
Skyy    139
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
Promit    13246
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  

  • Similar Content

    • By povilaslt2
      Hello. I'm Programmer who is in search of 2D game project who preferably uses OpenGL and C++. You can see my projects in GitHub. Project genre doesn't matter (except MMO's :D).
    • By ZeldaFan555
      Hello, My name is Matt. I am a programmer. I mostly use Java, but can use C++ and various other languages. I'm looking for someone to partner up with for random projects, preferably using OpenGL, though I'd be open to just about anything. If you're interested you can contact me on Skype or on here, thank you!
      Skype: Mangodoor408
    • By tyhender
      Hello, my name is Mark. I'm hobby programmer. 
      So recently,I thought that it's good idea to find people to create a full 3D engine. I'm looking for people experienced in scripting 3D shaders and implementing physics into engine(game)(we are going to use the React physics engine). 
      And,ye,no money =D I'm just looking for hobbyists that will be proud of their work. If engine(or game) will have financial succes,well,then maybe =D
      Sorry for late replies.
      I mostly give more information when people PM me,but this post is REALLY short,even for me =D
      So here's few more points:
      Engine will use openGL and SDL for graphics. It will use React3D physics library for physics simulation. Engine(most probably,atleast for the first part) won't have graphical fron-end,it will be a framework . I think final engine should be enough to set up an FPS in a couple of minutes. A bit about my self:
      I've been programming for 7 years total. I learned very slowly it as "secondary interesting thing" for like 3 years, but then began to script more seriously.  My primary language is C++,which we are going to use for the engine. Yes,I did 3D graphics with physics simulation before. No, my portfolio isn't very impressive. I'm working on that No,I wasn't employed officially. If anybody need to know more PM me. 
       
    • By Zaphyk
      I am developing my engine using the OpenGL 3.3 compatibility profile. It runs as expected on my NVIDIA card and on my Intel Card however when I tried it on an AMD setup it ran 3 times worse than on the other setups. Could this be a AMD driver thing or is this probably a problem with my OGL code? Could a different code standard create such bad performance?
    • By Kjell Andersson
      I'm trying to get some legacy OpenGL code to run with a shader pipeline,
      The legacy code uses glVertexPointer(), glColorPointer(), glNormalPointer() and glTexCoordPointer() to supply the vertex information.
      I know that it should be using setVertexAttribPointer() etc to clearly define the layout but that is not an option right now since the legacy code can't be modified to that extent.
      I've got a version 330 vertex shader to somewhat work:
      #version 330 uniform mat4 osg_ModelViewProjectionMatrix; uniform mat4 osg_ModelViewMatrix; layout(location = 0) in vec4 Vertex; layout(location = 2) in vec4 Normal; // Velocity layout(location = 3) in vec3 TexCoord; // TODO: is this the right layout location? out VertexData { vec4 color; vec3 velocity; float size; } VertexOut; void main(void) { vec4 p0 = Vertex; vec4 p1 = Vertex + vec4(Normal.x, Normal.y, Normal.z, 0.0f); vec3 velocity = (osg_ModelViewProjectionMatrix * p1 - osg_ModelViewProjectionMatrix * p0).xyz; VertexOut.velocity = velocity; VertexOut.size = TexCoord.y; gl_Position = osg_ModelViewMatrix * Vertex; } What works is the Vertex and Normal information that the legacy C++ OpenGL code seem to provide in layout location 0 and 2. This is fine.
      What I'm not getting to work is the TexCoord information that is supplied by a glTexCoordPointer() call in C++.
      Question:
      What layout location is the old standard pipeline using for glTexCoordPointer()? Or is this undefined?
       
      Side note: I'm trying to get an OpenSceneGraph 3.4.0 particle system to use custom vertex, geometry and fragment shaders for rendering the particles.
  • Popular Now