So that I can use glBufferData to upload the whole
stuff with a single API call? What about the byte alignment/
padding of the client struct. I guess there are some things
that could go wrong?
Or should I use separate uniform arrays for the light source
components and then call glUniformXfv for each array?
Your opinions are really welcome!
If you think UBOs can do this job maybe you could also
share some code snippets for the use with array (I already
know the code examples for uploading a single uniform block).
Uniform block arrays is an OpenGL 4.0 feature… I don’t see why it could not be a OpenGL 3.X feature but well… that’s how it is right now.
You need to query the index of each array element and then set each index to the buffer using glUniformBlockBinding… it’s quite cucumbersome but that’s how it is
… and then just upload the entire array as a single UBO bound to LightSourceBlock.
Keep in mind that you will probably need to pad the “Position” field of your C++ struct to 4 floats when using std140. Also keep in mind that your compiler is free to layout (and pad) the struct as it pleases, so be careful about just assuming the layout matches std140. It may not.
Have I missed something? Shader compiled, linked
and validated without errors. Just the index query failed.
I tried to query the index after activating the shader
via glUseProgram(m_handle) and also tried it directly
after linking. In both cases no luck =/
Ok the reason for GL_INVALID_INDEX was that LightSourceBlock
was not used in any operation in the sample shader thus the
uniform was removed during compilation/optimization.