繁体   English   中英

glGetUniformLocation返回-1 OpenGL ES(iPhone)

[英]glGetUniformLocation return -1 OpenGL ES (iPhone)

我有一个片段着色器,具有以下属性:

varying highp vec2 coordinate;
precision mediump float;

uniform sampler2D videoframe;
uniform sampler2D videosprite;
uniform vec4 mask;
uniform float threshold;

我正在获取他们的位置,然后设置它们:

_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);

但是,日志显示: 0 2 1 -1

从文档中,我看到-1(阈值均匀)意味着它失败了。 它为什么失败? 谢谢

GLSL编译器可以(通常会)优化着色器中未使用的任何制服和属性。 您只能查询活动制服的位置,即在着色器的至少一个分支中使用的位置。

所以我猜你的着色器代码中的任何地方都没有使用threshold变量。 但是在这种情况下,无论如何你都不需要它的值,为位置-1设置一个统一的值就不会做任何事情。 所以你实际上不必担心这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM