Hello,
I’m in a desperate situation, please help me.
The past two weeks I’ve had difficulty using uniform variables in my shader programs. The problem arises as the glGetUniformLocation() function call returns the value -1.
I’ve done plenty of research recently on the topic myself and I think I have the right function calls at the right places. I’m also aware that the glsl driver optimizes out certain variables that it sees not affecting the output of the program, but I do not understand why the heck it would do that in my case. The variables for I’m calling the glGetUniformLocation() are put in a good use calculating the result values in my shaders. What is even more incomprehensible to me is the haphazard results I get after I run my program. Same binary, different runtime results each time. It sometimes works perfectly as intended, sometimes it fails getting the uniform locations. I’ve extracted the problem to a simplified build and loaded it to a github repository. It can be found here https://github.com/Motonen/Uniform. Here is the vertex shader
#version 330 core
layout (location = 0) in vec4 vPosition;
uniform mat4 projMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
void main()
{
vec4 m = modelMatrix * vPosition;
vec4 mv = viewMatrix * m;
vec4 mvp = projMatrix * mv;
gl_Position = mvp;
}
The glsl driver in this case shouldn’t optimize out any of those uniform matrices right? It does it nevertheless sometimes.
Enlighten me about my situation. Thank you guys in advance.