Are shader varying and uniform variables unique across separate applications?
I have a situation where I need to have several processes (separate programs actually) that use shader code with the same variable names with the exception of one uniform. Each process needs to have its shader be independent of the others. When I call glCreateProgram() and glCreateShader() I get the same id numbers for the programs and shaders in each process so it would seem that process 'a' doesn't know anything about process 'b'. However, if the unique uniform in process 'b' is used the image does not display correctly in process 'b'. If the shader code in process 'a' contains the uniform that is used in process 'b' everything works OK. Why would changing something in process 'a' affect process 'b'?
We want to have the same shader source for all of the processes except for the use of the one uniform which is not in the first process but will need to be an all others.
In all of the applications:
first call to glCreateShader() returns 1
second call to glCreateShader() returns 2
first call to glCreateProgram() returns 3
and so on.
In the shader code for process 'a':
uniform vec2 first;
uniform vec4 second;
uniform vec4 third;
varying float forth;
...
main()
{
gl_Position = second * third;
forth = somecalculation; // used in fragment shader
}
In the shader code for other processes:
uniform vec2 first;
uniform vec4 second;
uniform vec4 third;
varying float forth;
uniform vec2 unique;
...
main()
{
gl_Position = second * third;
gl_position.x += unique.x;
gl_position.y += unique.y;
forth = somecalculation; // used in fragment shader
}
The above method produces an invalid view, the colors are wrong. If the code in application 'a' includes the unique uniform and the uniform values are set to 0.0f then there is no problem. So if the shader code for all the processes looks like:
uniform vec2 first;
uniform vec4 second;
uniform vec4 third;
varying float forth;
uniform vec2 unique;
...
main()
{
gl_Position = second * third;
gl_position.x += unique.x;
gl_position.y += unique.y;
forth = somecalculation; // used in fragment shader
}
and application 'a' on the CPU does:
GLfloat unique[2];
GLint location = glGetUniformLocation(program, "unique");
unique[0] = 0.0f;
unique[1] = 0.0f;
glUniform2fv(location, 1, unique);
all views are correct. What am I missing?
Sorry for the long post but I had a hard time coming up with an adequate description of the problem.