我在尝试使用opengl获取统一位置时遇到问题。当调用glGetUniformLocation时,它为着色器中的所有制服返回-1。
以下是一些顶点着色器代码:
#version 330
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 uv;
layout (location = 2) in vec3 normal;
uniform mat4 viewMatrix;
uniform mat4 worldMatrix;
uniform mat4 projectionMatrix;
out vec2 o_UV;
out vec4 o_color;
void main() {
vec3 lightPos = vec3(0, 0, 0);
vec3 mvVertex = vec3(projectionMatrix * worldMatrix * vec4(position, 1.0));
vec3 mvNormal = vec3(projectionMatrix * worldMatrix * vec4(normal, 0.0));
... o_UV and o_color are also set, didn't want to take up loads of space
gl_Position = projectionMatrix * worldMatrix * viewMatrix * vec4(position, 1.0);
}
着色器编译得很好,但我不明白为什么统一位置为-1。我不认为它会从优化中删除,因为我正在使用变量。我错过了什么想法或者什么?感谢
答案 0 :(得分:1)
事实证明片段着色器正在优化制服,这使得它抛出错误,我的错误。