Specifying Uniform Blocks in Shaders

To access a collection of uniform variables using routines such as glMapBuffer() (see Chapter 3, “Drawing with OpenGL” for more details), you need to slightly modify their declaration in your shader. Instead of declaring each uniform variable individually, you group them, just as you would do in a structure, in a uniform block. A uniform block is specified using the uniform keyword. You then enclose all the variables you want in that block within a pair of braces, as demonstrated in Example 2.3.

Example 2.3. Declaring a Uniform Block

uniform Matrices {    mat4 ModelView;    mat4 Projection;    mat4 Color;};

Recall types are divided into two categories: opaque and transparent; where the opaque types include ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.