I have a fragment shader with the following attributes:
varying highp vec2 coordinate;
precision mediump float;
uniform sampler2D videoframe;
uniform sampler2D videosprite;
uniform vec4 mask;
uniform float threshold;
I am getting their locations and later setting them:
_frame = glGetUniformLocation(_program, "videoframe");
_sprite = glGetUniformLocation(_program, "videosprite");
_mask = glGetUniformLocation(_program, "mask");
_threshold = glGetUniformLocation(_program, "threshold");
NSLog(@"%i %i %i %i", _frame, _sprite, _mask, _threshold);
However, the log reveals: 0 2 1 -1
From documentation, i see that -1 (the threshold uniform) means it failed. Why is it failing? Thanks
The GLSL compiler can (and usually will) optimize away any uniforms and attributes that are not used in the shader. You can only query the locations of active uniforms, being the ones that are used in at least one branch of your shader.
So I guess the threshold
variable isn't used anywhere in your shader code. But in this case you don't need it's value anyway, and setting a uniform value for location -1
will just do nothing. So you actually don't have to worry about this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With