Using Standard Layout Qualifiers

When you group a number of variables in a uniform buffer or shader storage buffer, and want to read or write their values outside a shader, you need to know the offset of each one. You can query these offsets, but for large collections of uniforms this process requires many queries and is cumbersome. As an alternative, the standard layout qualifiers request that the GLSL shader compiler organize the variables according to a set of rules, where you can predictably compute the offset of any member in the block.

In order to qualify a block to use the std140 layout, you need to add a layout directive to its declaration, as demonstrated below:

layout (std140) uniform UniformBlock {    // ...

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.