View Full Version : generic vertex attrib
V-man
04-13-2004, 09:53 AM
From what I understood from ARB_vertex_shader there is nothing special we have to do to use generic vertex attributes.
In GLSL, if someone uses gl_Vertex and gl_Normal (which is what I'm doing) and the code we use
glEnableVertexAttribArrayARB
glDisableVertexAttribArrayARB
glVertexAttribPointerARB
is it suppose to work without having to do anything else?
It seems gl_Vertex contains valid values, but gl_Normal has a constant (wrong!) normal.
If I use glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer
it works as expected.
Can someone explain?
Corrail
04-13-2004, 01:27 PM
Do you pass the normal to vertex index number 2 or do you fetch the vertex location with glGetAttribLocationARB("gl_Normal") and then pass the normal to that location?
Axel Mamode
04-13-2004, 02:37 PM
Originally posted by V-man:
From what I understood from ARB_vertex_shader there is nothing special we have to do to use generic vertex attributes.
In GLSL, if someone uses gl_Vertex and gl_Normal (which is what I'm doing) and the code we use
glEnableVertexAttribArrayARB
glDisableVertexAttribArrayARB
glVertexAttribPointerARB
is it suppose to work without having to do anything else?
It seems gl_Vertex contains valid values, but gl_Normal has a constant (wrong!) normal.
If I use glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer
it works as expected.
Can someone explain?There is no aliasing between generic vertex attributes and fixed function attributes, except for gl_Vertex and generic attrib 0.
So using gl_Normal while enabling a vertex attrib is not a proper usage.
This is true for ARB_vertex_program as well, where aliasing is unspeficied.
If you want to use generic attributes, you will have to use a generic attribute in your shader, and get (or set) the attribute location in your C code.
Note as well that getting the location of gl_Normal should return -1, as it is a built in attribute, that you cannot load through generic attribute API.
so instead of using gl_Normal, use
attribute vec4 mynormal;
and then, do a
glGetAttribLocationARB(prog, "mynormal");
Then you can enable/setup that vertex attribute.
V-man
04-14-2004, 07:43 AM
so instead of using gl_Normal, use
attribute vec4 mynormal;
and then, do a
glGetAttribLocationARB(prog, "mynormal");The problem with this is you have to know ahead of time the name "mynormal".
Besides, I though the standard attributes occupied specific slots, like for normal it is slot 2.
There is no aliasing between generic vertex attributes and fixed function attributes, except for gl_Vertex and generic attrib 0.From my understanding, they had to do this because vertex or attrib0 is used for signaling, but I don't see an explanation why gl_Normal and attrib2 can't be the same?
glGetAttribLocationARB(handle, "gl_Normal") is defined to return -1 for some unexplained reason.
Yes, I know about ARB_vertex_program.
It too defined normals as beeing mapped to attrib2 but there is no aliasing ... weird
Axel Mamode
04-14-2004, 09:35 AM
Originally posted by V-man:
[QB]The problem with this is you have to know ahead of time the name "mynormal".
Besides, I though the standard attributes occupied specific slots, like for normal it is slot 2.
This is not the case. That is what I mean when I say there is no aliasing. the way the spec is written, slot 2 is a generic slot number 2, normal is a built-in slot. They do not end up being the same. In ARB_vertex_shader, you will see no table saying 2 is normal.
Originally posted by V-man:
[QB]
From my understanding, they had to do this because vertex or attrib0 is used for signaling, but I don't see an explanation why gl_Normal and attrib2 can't be the same?
Well, the spec says they are not.
From the spec:
There is no aliasing among generic attributes and conventional attributes. In other
words, an application can set all MAX_VERTEX_ATTRIBS_ARB generic attributes and all
conventional attributes without fear of one particular attribute overwriting the value
of another attribute.
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.