Uniform not "active" after explicit use

If I declare and use a uniform variable in a vertex shader, link it in a program with a geometry and fragment shader that do not have declarations of said variable, why does glGetUniformLocation return -1 for it?

The same thing happens if all 3 have the declaration, but only one or two use it for anything. In my case, all 3 must do something with the uniform in order for the compiler to consider it “active”.

Oddly though, if I don’t attach a geometry shader this problem does not occur.

The problem is: I’ve used the uniform and it therefore affects the output. However, I cannot obtain a location index for it. Why?

You might post your code. If that variable is used to determine the program output values, then it should be active.

Compiler can do some tricky things though to determine if it is really not used though even though you have used it in an expression.

Thank you for the reply.

I found the problem: I didn’t have any outputs connecting the vertex to the geometry shader, so clearly anything done in the vertex shader would not affect the output.

Note: The parts of the test below aren’t meant produce anything meaningful.

Vertex shader:


#version 400

uniform sampler2D s;

in vec4 p;

// no "out vec4 p_gs" or the like

void main()
{
    // geometry shader doesn't use gl_in[0].gl_Position
    gl_Position = p*dot(p,texture2D(s,vec2(0,0)); // baffling here, since "s" is clearly used
}


Geometry shader:


#version 400

// no need for "s" here

layout(points) in;
layout(points, max_vertices=1) out;

in vec4 p_gs[1]; // not connected...

void main()
{
    // blah...
}

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.