Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

glGetUniformLocation return -1 OpenGL ES (iPhone)

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

like image 891
0xSina Avatar asked Mar 22 '12 18:03

0xSina


1 Answers

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.

like image 178
Christian Rau Avatar answered Oct 25 '22 08:10

Christian Rau