Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL 3.0/3.1 glXxxPointer

Started by Lord_Evil Mar 25, 2009 at 10:52 AM 4 replies 3.1k views
Original Post
Lord_Evil
Lord_Evil
Hi, I was just reading in the spec that glXxxxPointer functions (except glVertexAttribPointer) have been deprecated in 3.0 and removed in 3.1 (not using the compatibility api). Until now I was using those functions to bind individual components of my vertex buffer, e.g. for a depth-only/shadow map pass I bound coords and maye texcoords, etc. Since they now are deprecated I figure I should use glVertexAttribPointer instead. However, I wasn't able to find any information on how they are bound to named attributes like position. I'm using CG so I'm not that familiar with GLSL but the spec says that gl_position isn't a varying, so it has to be bound to a fixed attribute index (like 0), right? Additionally, IIRC the bulk work was done by the driver when glVertexPointer was called. When does that happen now? Thanks in advance for your replies. Thomas
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
gardin
gardin
Yes glVertexAttribPointer with 0 as the attribute is the same as glVertexPointer, you don't need and can't bind it.

The work is done by the calls like glDrawElement, there is no work done by glVertexPointer, maybe you're thinking about glVertex in glBegin/glEnd?

You can't use glVertexAttribPointer with any fixed attributes like gl_Normal, you have to define your own attribute like:

attribute vec3 Normal;

And use that one with glVertexAttribPointer

//Johan
Lord_Evil
Lord_Evil
AFAIK, glVertexPointer had to be called last because that was an indication to the driver to actually bind the arrays (and do validations etc.). At least that was my experience.

What do you mean with "you can't bind it"? If that means you can't bind a custom attribute to it, well, that's OK and not surprising. But I'd still have to call glVertexAttribPointer(0, ...) in order to tell the driver where to find the coords, right?

If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!
HuntsMan
HuntsMan
Notice that generic attribute zero (0) isn't bound to the vertex position in OpenGL 3.1, you need to use whatever generic attribute you want to provide position using a attribute variable.

This is documented in the page 45 of the PDF file of the GL 3.1 spec with ARB_compatibility extension (Marked in distinct color).
gardin
gardin
Oh sorry, then obviously you can bind a vertex attribute too :P

I've never heard of glVertexPointer having to be last, but in glBegin/glEnd glVertex must be the finishing call. Since glVertexPointer is only used when glEnableClientState (GL_VERTEX_ARRAY) has been called, that would be a bit weird.
Lord_Evil
Lord_Evil
I didn't find relevant information on page 45 in any of the 3.1 specs but the GLSL 1.40 spec states that writing to gl_position isn't required anymore. So I assume it was only meant to pass the position from the vertex to geometry/fragment shaders.

That would mean, I now just bind as many generic vertex attributes as I want (up to the driver's max) and define the meaning through binding them in the shader, right?

Thus I'd gain flexibility (position not even required to be present) at the expense of ensuring that my shaders use the attributes in the same order that I put them into the VBO (e.g. if I specify attribute 0 to be the normal and attribute 1 to be the position, that would have to be true in the shader as well).
If I was helpful, feel free to rate me up ;)If I wasn't and you feel to rate me down, please let me know why!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.