I am looking at glGetActiveAttrib (2.11.3) and am wondering if the order of attribute indices is defined anywhere.
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.
Suggests that the index used for querying is separate from any binding index.
Will querying of index 0 provide the first active attribute and index n-1 give the last attribute in the order they were declared within the shader or in an unspecified order? For example, if position was listed before color then position can be queried using index i and color by i+1?
If you want to query the data by name without looping through all attributes, OpenGL 4.3 or the ARB_program_interface_query extension provides glGetProgramResourceIndex to get an index from a name.
To identify based on binding location, what you’re looking for is the GL_LOCATION property on GL_PROGRAM_INPUT resources. The wiki page has example code you can adapt. Or something like this should work:
In my experience, sometimes inactive attributes show up in this queried list of GL_PROGRAM_INPUT resources, but with a GL_LOCATION value of -1. Or they might not be in the list at all. Also, legacy fixed-function vertex attributes (e.g. gl_Color) don’t seem to show up in this list, even on drivers like NVIDIA’s that alias them on top of generic vertex attribute locations.