View Full Version : UBO Best Practices

11-15-2009, 06:26 AM

Can anyone share any best practices they've found while converting existing GLSL shaders to use UBOs? Or just best practices with UBOs in general? I'm curious to know if it is worth making a uniform block even if it only contains a single field (e.g. the model-view-projection matrix) but the field is used across a large number of shaders. I'm under the impressive that this is worthwhile since you would only set this value once per frame with glBufferSubData, etc instead of using glUniformMatrix per shader.


11-15-2009, 07:27 AM
I'm leaning towards yes to using uniform blocks with a single field if it is used across several shaders based on the following from Appendix F (http://www.opengl-redbook.com/appendices/AppF.pdf) of the red book:

Using uniform buffer objects (in particular, the shader variety) will help significantly reduce the overhead of loading uniform variables when changing between shaders.

Alfonse Reinheart
11-15-2009, 10:10 AM
Just remember that you have a set limit to the number of uniform buffers that can be on a shader. Using one UBO for a single uniform is possible, but it does waste a UBO slot.