I want to detach then reattach a different shader object to a program object.
I create three empty shader objects with glCreateShader.
Provide source code for these shaders with glShaderSource.
Compile each of the shaders with glCompileShader.
Create a program object with glCreateProgram.
Attach all the shader objects to the program object with glAttachShader.
Link the program object with glLinkProgram.
Install the executable program as part of OpenGL’s current state with glUseProgram.
Set the uniform variables by querying the locations of these variables with glGetUniformLocation and then set their values with glUniform.
This works great but now I want to simply use a different fragment shader within the program.
I detach the old fragment shader using glDetachShader.
Recompile the new source using glShaderSource and glCompileShader.
Reattach it to the program object with glAttachShader
Then the only way I can get it to work is to re-link the program using glLinkProgram.
The problem I have is that the uniform variables seem to have gone in the other shader objects which the new shader needs.
Any ideas what I am doing wrong?
Thanks again.
Edit: What it seems that I have to do is just create another program with the different fragment shader in it. Then I should be able to switch between the two. Does this mean that glDetachShader can only be called before glLinkProgram?