开发者

How to get the data type of an uniform variable

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

 uniform vec3 color;
 uniform float zoom;
 uniform int max;
 void 开发者_如何转开发main() {
    ...
 }

The glGetActiveUniformARB(program, index, maxLength, *length, *size, *type, *name) seems to be the right API function to use but I don't know how to determinate index from a variable name. glGetUniformLocationARB returns the location of an uniform variable, that seems not to be the same as the index.


Well, the API kind-of assumes that if you know the name of the uniform, you also know the type (those 2 things are written next to each other in the code) so it does not allow a simple access to the type by name.

That said, you can iterate over all the active uniforms with glGetActiveUniformARB to find the one that interests you. Note also that this will only return valid data if the uniform is actually active (i.e. the GLSL compiler thought it was useful for the final computations).

(Typically, the expected usage is to iterate over all the uniforms, extract name and type, and then get their location from name to know how to update them at run-time. Not the other way around).


From 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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜