Determining Active Attributes/State

I’m trying to determine which vertex attributes are being used in a shader. My goal is to send the minimum amount of vertex data to the HW. To do this, I use:

glGetObjectParameterivARB(program, GL_OBJECT_ACTIVE_ATTRIBUTES_ARB);

to get the number of active attributes. I then use


to get information about each active attribute. In conjunction with an attribute naming scheme, this method helps me send the minimum amount of user defined vertex attribute data to the HW.

However, the above method does not help in determining if I need to send color, secondary color, and multitex coords vertex data. I’d like to be able to determine if built in state variables like gl_Color, gl_SecondaryColor, gl_MultiTexCoord0, etc. are being used in the shader. glGetObjectParameterivARB does not return information on the usage of any built-in GL state per-vertex attributes. Is there anyway to determine if any of the above built-in state vertex attributes are being using in a shader?

My current work around is to not use built-in vertex attributes in my shaders. Instead, I use my naming scheme and pass in the built-in vertex data as user defined vertex data.

For example, if I see the attribute my_Color, I know that the shader needs to be sent color information for each vertex. So, instead of calling glColor3f per vertex, I now call glVertexAttrib3 with the proper attribute location and vertex color.

Any help on determining if vertex attributes like gl_Color are used in a shader would be greatly appreciated.


You can’t do this. Driver will return -1 for all standard attributes. I use another approach. For each VS/FS I have C++ class that handle client states (enable or disable some of vertex attributes) for shader.


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