How can I figure out whether a uniform belongs to a vertex or fragment shader?

Hello everybody,

To be more precise: I have a compiled GLSL program consisting of both a vertex and a fragment shader. I am able to get the total number of uniforms using glGetObjectParameterivARB() in conjunction with GL_OBJECT_ACTIVE_UNIFORMS_ARB. The glGetActiveUniformARB() returns the name of each uniform. But it seems to me that there is no API to determine, whether a uniform belongs to the fragment or the vertex shader. Do I really have to parse the shader sources by myself?

Any ideas or suggestions?

In general, the idea is that you shouldn’t care whether it is a vertex or fragment shader uniform. Indeed, you can share a uniform between the two, if I recall correctly. Considering that you already know the name of the uniform already (or, at least, you should), I’m not sure why you need to know whether it belongs to the vertex shader or fragment shader.

Originally posted by Korval:
In general, the idea is that you shouldn’t care whether it is a vertex or fragment shader uniform. Indeed, you can share a uniform between the two, if I recall correctly.

OK. I didn’t know that. But it makes sense…

Considering that you already know the name of the uniform already (or, at least, you should),
I’m not sure why you need to know whether it belongs to the vertex shader or fragment shader.

I wrote a Cg and GLSL support for OpenInventor, where I provide a GUI for manipulating the uniforms. For some reasons (i.e. I have the same GUI for Cg and GLSL) I decided to devide between vertex and fragment shaders. I probably have to redesign this a little bit.

If a uniform is used in multiple shader objects that are attached to the same program object then yes the uniform is the same across all objects that use it. Even if the shader objects are vertex and fragment types, it makes no difference. This way you only have to deal with one uniform and set one value.

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