PDA

View Full Version : Why get the error attribute info?



Flying_sands
10-20-2005, 06:17 AM
in order to get the attribute infomation, app contains such code:
index = glGetAttribLocationARB(glGetHandleARB(GL_PROGRAM_O BJECT_ARB), "inputColor");
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJ ECT_ARB), index, 100, NULL, &asize, &type, str);

I think str should be "inputColor", but in fact it is "gl_Normal". Why?

jra101
10-20-2005, 07:30 AM
Is glGetAttribLocationARB returning an index in the [0..GL_OBJECT_ACTIVE_ATTRIBUTES_ARB-1] range?

Flying_sands
10-20-2005, 07:54 AM
Yes, the index is 1 and active attribute is 3

sqrt[-1]
10-20-2005, 11:28 PM
Originally posted by Flying_sands:
in order to get the attribute infomation, app contains such code:
index = glGetAttribLocationARB(glGetHandleARB(GL_PROGRAM_O BJECT_ARB), "inputColor");
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJ ECT_ARB), index, 100, NULL, &asize, &type, str);

I think str should be "inputColor", but in fact it is "gl_Normal". Why?You are using glGetActiveArribute incorrectly.

From the GL 2.0 spec:
"If index is greater than or equal to
ACTIVE ATTRIBUTES, the error INVALID VALUE is generated. Note that index
simply identifies a member in a list of active attributes, and has no relation to the
generic attribute that the corresponding variable is bound to."

So you CANNOT use the value returned by glGetAttribLocationARB as input to glGetActiveAttribARB. If you want to find specific info on a known named attribute, you have to iterate over all the attributes and compare the returned strings.

psudeo code:

for(int i=0; i (less than) maxNumAttributes; i++)
{
glGetActiveAttribARB(glGetHandleARB(GL_PROGRAM_OBJ ECT_ARB), i, 100, NULL, &asize, &type, str)

if(str == "myattribute")
{
break; // If was found!
}

}

Flying_sands
10-21-2005, 12:27 AM
Yes, thanks.
Another question, can glGetAttributeLocation get the right index? I find that the function before and after the glBegin return different value.

Relic
10-21-2005, 02:01 AM
What do you mean with "after the glBegin"? Inside glBegin-glEnd commands?
glGet is not allowed there. Add glGetError calls (outside the glBegin-glEnd) and you should see a GL_INVALID_OPERATION.

Flying_sands
10-21-2005, 02:38 AM
o, I see. thanks.