How to get the data type of a single variable

I am trying to get the type of a single variable defined in a fragment shader:

uniform vec3 color; uniform float zoom; uniform int max; void main() { ... } 

glGetActiveUniformARB (program, index, maxLength, * length, * size, * type, * name) seems to be a right API function, but I don't know how to determine the index from a variable name. glGetUniformLocationARB returns the location of a single variable, which does not seem to match the index.

+6
opengl glsl
source share
2 answers

Well, the API type assumes that if you know the name of the uniform, you also know the type (these two things are written next to each other in the code), so it does not allow you to easily access the type by name.

However, you can iterate over all active forms with glGetActiveUniformARB to find the one that interests you. Also note that this will only return valid data if the uniform is actually active (i.e., the GLSL compiler considers it useful for final calculations).

(Typically, the expected use is to iterate over all uniforms, retrieve the name and type, and then get their location on behalf of in order to know how to update them at runtime. Not vice versa).

+3
source share

On the glGetActiveUniform man page:

 The number of active uniform variables can be obtained by calling glGetProgram with the value GL_ACTIVE_UNIFORMS. A value of 0 for index selects the first active uniform variable. Permissible values for index range from 0 to the number of active uniform variables minus 1. 
+2
source share

All Articles