PDA

View Full Version : glGetActiveAttrib - bug ?



cmk
10-27-2007, 02:05 PM
The system:
Win XP x64
nVidia 7800 GTX w/ Forceware 162.18 drivers

I was building a shader framework and found the following:

1.
If a vertex shader doesn't use gl_Vertex either directly, or indirectly via ftransform(), then the first user attribute will be bound to slot 0.

The result is that glGetAttribLocation(my_attrib) returns 0, and using 0 in glGetVertexAttrib*() or glVertexAttrib*() returns an error - GL_INVALID_VALUE.

This means i can't get/set the user attrib if it happens to be the one bound to 0.

Granted, there are few cases where gl_Vertex or ftransform() aren't used, but still.

Which is wrong, the linker auto-binding a user attribute to 0, or glGetVertexAttrib*()/glVertexAttrib*() returning an error when passed auto-bound location = 0. I believe the former.

2.
glGetActiveAttrib returns the vector type for matrix attributes.
e.g.
in shader have "attribute mat4 my_mat;"
glGetActiveAttrib("my_mat") returns:
type = GL_FLOAT_VEC4
size = 1
It does however reserve 4 index slots.
I was expecting type = GL_FLOAT_VEC4, size = 4, but would have settled for type = GL_FLOAT_MAT4, size = 1.

Can anyone verify this, or have i misunderstood something.

Trenki
10-29-2007, 11:22 AM
AFAIK on my old ATI X800 XT user attributes never were assigned the location 0 unless I explicitly specified this before linking. I think user attributes should not be auto-bound to 0 because 0 is special in that it has no current state. The index 0 is normally used for gl_Vertex. Also calls to glVertex or other draw calls will write to the attibute 0 since this is aliased to the glVertexPointer array.

glGetVertexAttrib/glVertexAttrib with index 0 worked fine for me and should not give any other errors as those listed in the OpenGL Reference Pages.

For point 2: It is correct that it returns a GL_FLOAT_VEC4 with size 1 and the matrix attribute occupies 4 index slots. This behaviour is defined this way in the specification.

[ www.trenki.net (http://www.trenki.net) | vector_math (3d math library) (http://www.trenki.net/content/view/16/36/) | software renderer (http://www.trenki.net/content/view/18/38/) ]

cmk
10-29-2007, 02:55 PM
For point 2: It is correct that it returns a GL_FLOAT_VEC4 with size 1 and the matrix attribute occupies 4 index slots. This behaviour is defined this way in the specification.
Are you sure ?

I'm going by http://www.opengl.org/sdk/docs/man/ glGetActiveAttrib
In particular:

The type argument will return a pointer to the attribute variable's data type. The symbolic constants GL_FLOAT, GL_FLOAT_VEC2, GL_FLOAT_VEC3, GL_FLOAT_VEC4, GL_FLOAT_MAT2, GL_FLOAT_MAT3, GL_FLOAT_MAT4, GL_FLOAT_MAT2x3, GL_FLOAT_MAT2x4, GL_FLOAT_MAT3x2, GL_FLOAT_MAT3x4, GL_FLOAT_MAT4x2, or GL_FLOAT_MAT4x3 may be returned. The size argument will return the size of the attribute, in units of the type returned in type.
To me this says that an "attribute mat4 my_attrib" should be reported by glGetActiveAttrib() as type = GL_FLOAT_MAT4, size = 1, or type = GL_FLOAT_VEC4, size = 4.

If not, then how can we determine, in C/C++, that my_attrib is a mat4 instead of a vec4 ?

Can you give me a reference to the spec that says it should return type = GL_FLOAT_VEC4, size = 1.