Hello Guest

glGetUniformLocation(.) returns -1

  • 0 Replies
  • 1523 Views
*

Offline Adro

  • *
  • 10
glGetUniformLocation(.) returns -1
« on: January 05, 2022, 11:24:35 »
Update : I solved it. Even knowing my uniform is active (calling glGetProgrami(.)), the struct it references has some attributes that weren't initialized as uniforms, so the output was null or something.

Hi!

I know this is an old one. I'm doing basic fragment shader programming. I have a problem when attempting to create a uniform for material structure of a mesh. Calling glGetUniformLocation() after the initialization of my shader program returns -1. However, the program is linked and validated correctly (no exceptions thrown). The uniform I'm trying to set is only in the fragment shader, so I attach the (short) piece of code:

#version 330

in vec2 text;
out vec4 fragColor;

struct Material
{
    vec4 modelC;
};

vec4 col;
uniform sampler2D textSampler;
uniform Material material;

void setupColour(Material material)
{
    col = material.modelC;
}

void main()
{
    setupColour(material);
    fragColor = texture(textSampler, text) + col;
}


I saw some posts on this. They say that the compiler assigns -1 value if the variable is useless. But I think the code actually uses the uniform! Any advice?

« Last Edit: January 05, 2022, 12:23:43 by Adro »