I start by attaching to my program both shaders and then call glGetUniformBlockIndex
to bind the uniform buffers. I would expect a glBindShader
function to let me specify which shader I want to parse to find the uniform, but there is no such thing.
How can I tell OpenGL which shader it should look into?
glLinkProgram
is carried out between the shaders’ compilation and calling glGetUniformBlockIndex
. And it succeeds - qdii 2012-04-04 23:52
Assuming the program has been fully linked, it doesn't matter. Here are the possibilities for glGetUniformBlockIndex
and their consequences:
GL_INVALID_INDEX
.glUniformBlockBinding
.glUniformBlockBinding
.The last part is key. If you specify a uniform block in two shaders, with the same name, then GLSL requires that the definitions of those uniform blocks be the same. If they aren't, then you get an error in glLinkProgram
. Since they are the same (otherwise you wouldn't have gotten here), GLSL considers them to be the same uniform block.
Even if they're in two shader stages, they're still the same uniform block. So you can share uniform blocks between stages, all with one block binding. As long as it truly is the same uniform block.