Is the order of glGetActiveAttrib indices defined anywhere?

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?

It isn’t.

Unspecified order.

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.

A useful section in the OpenGL wiki on this:

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:

    GLint numInputs = 0;
    glGetProgramInterfaceiv( handle, GL_PROGRAM_INPUT, GL_ACTIVE_RESOURCES, &numInputs );
    assert( numInputs <= MAX_INPUTS );

    const GLenum inputProps[]  = { GL_LOCATION, GL_TYPE, GL_ARRAY_SIZE };
    const int    numInputProps = 3;

    struct AttrInfo
    {
        GLint  location;             // Ex: binding location 0
        GLenum type;                 // Ex: GL_FLOAT_VEC4
        GLint  size;                 // Ex: 1
    } attrInfo[ MAX_INPUTS ];

    for ( GLint i = 0; i < numInputs; i++ )
    {
        glGetProgramResourceiv( handle, GL_PROGRAM_INPUT, i,
                                numInputProps, inputProps,
                                numInputProps, NULL, (GLint *) &attrInfo[i] );
    }

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.

1 Like

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.