glGetActiveUniform "index" & glUniform "location"

I’ve made an object for my program that will load any aribitrary shaders, look up the uniforms, and then allow a user to input those values, but there are some shaders that don’t work (ie. don’t produce any output), so I’m trying to question all of my choices in the setup…

…basicly, I just want to be reassured that an “index” returned by glGetActiveUniform() can be used reliably as the “location” for glUniform*() calls: I’ve seen some code that uses glGetUniformLocation() paired with each glUniform*() call, which is something I don’t do currently…similarly, does a glUniform*() call need to be made each time the shader is used, even if the uniform value hasn’t changed?

The glGetActiveUniform() index is not the same as the location. You can’t pass it to glUniform(). You must find the location with glGetUniformLocation().

Uniform values are bound to the program object and stick even if you switch to another program and back again. So you may want to setup some uniforms at load time, like for instance the sampler indices.

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