Can someone tell me about the seemingly needlessly complicated Uniform Buffers? I’ve read the section in OpenGL Superbible 5, I’ve looked at some examples on blogs and I’ve read the official spec, and I still don’t get it.
Specifically, all examples seem to require a shader program to begin with in order to setup the uniform buffer initially with glGetActiveUniformsiv. I don’t understand this. Why doesn’t the interface allow you to define the structure without referring to a shader program, validating the buffer/s formats against the program at link time? Surely if a buffer is supposed to be shared amongst programs, it’s a bit of an imposition to have to validate and construct it based on any one program (perhaps the first program that would make use of it). Or have I missed something here?
Secondly, if I get the structure layout from one program, assuming the structure layout is the same for all programs that use the set of uniforms, is the structure guaranteed to have the same offsets, data sizes and so on? I would assume so.
Thirdly, I don’t understand binding points. I have to call glBindBufferBase with an index, and then call glUniformBlockBinding with a block index and the index I passed into glBindBufferBase. I’m having trouble visualising exactly what’s going on here, which index refers to what and why (!). Most examples I’ve seen feature one program and one buffer. It’s hard for me to see how this works with multiple programs and multiple buffers, which is what I need to do in order to define the (abstract) interfaces my code will use to support them.
Thanks for any assistance you can give.