James
James

Reputation: 41

OpenGL shader uniform not found however used in shader code

I am having issues trying to get uniform locations with opengl. When calling glGetUniformLocation it returns -1 for all uniforms in the shader.

Here is some of the vertex shader code:

#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);
}

The shader compiles fine but I don't understand why the uniform locations are -1. I don't think it would be removed from optimization as i am using the variables. Any ideas or something I have missed? Thanks

Upvotes: 0

Views: 2091

Answers (1)

James
James

Reputation: 41

It turns out the fragment shader was optimizing out a uniform which made it throw an error, my mistake.

Upvotes: 3

Related Questions