c++ - 警告 : Variable cannot be bound (it either doesn't exist or has been optimized away)

标签 c++ opengl glsl fragment-shader opengl-4

我正在尝试传递一个变量 timeVar(一个最初设置为 0.0 的 float ),它在我的 display() 方法中用以下行进行更改

timeVar = time(0);

到我的片段着色器。然后我这样做

safe_glUniform1f(h_uTime, timeVar); 

像这样把它传递给我的着色器程序

h_uTime = safe_glGetAttribLocation(h_program, "uTime");

但是我一直收到这个错误。请帮忙!

WARN: uTime cannot be bound (it either doesn't exist or has been optimized 
away). safe_glAttrib calls will silently ignore it.

最佳答案

因为 uTime 是统一的而不是属性,使用 glGetAttribLocation 总是会导致错误。必须改用 glGetUniformLocation

关于c++ - 警告 : Variable cannot be bound (it either doesn't exist or has been optimized away),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32750181/

相关文章:

c++ - 如何在 C++ 中查找 hash_map?

opengl - 如何将GPU全局内存中的像素阵列直接显示到屏幕上?

opengl - 如何求 3D 平面的斜率

C++ GLSL 数据对齐/填充

python - python 和 c++ 之间的流式传输值的通信

c++ - 为什么调用 std::async 后时间成本是 0 秒?

c++ - 制作网页小程序的工具

c++ - 旋转时立方体未按预期呈现

opengl-es - OpenGL GLSL 精度是否影响性能

c++ - GLSL 330 矩阵计算错误{无编译错误}