in GLSL spec section about Standard Uniform Block Layout, rule (4) says:

If the member is an array of scalars or vectors, the base alignment and array stride are set to match the base alignment of a single array element, according to rules (1), (2), and (3), and rounded up to the base alignment of a vec4.

I am not sure about the rounding of array stride to the base alignment of a vec4?

What does it mean the array element stride would be for a Uniform member looking like that:

struct MyStruct
   float myArray[7];

uniform MyStruct myStruct;

1 Answer 1


It does mean exactly that. Whenever you have an array, it's treated as an array of vec4s with regards to the memory layout. So in your float array you actually have 28 floats with each of the 7 values followed by 3 values of (basically unnecessary) padding to round each array element's alignment up to 16 byte (the size of a vec4). And yes, that's why std140 layout plain sucks! ;-)

However, do keep in mind that this only applies to uniform blocks, i.e. uniform data sourced from buffers. Your example actually isn't that. You merely declared a non-block uniform that happens to be a structure/array. This doesn't adhere to the same layout rules as an actual uniform block (and you don't really know/care how it's laid out), as there is no need to synchronize the layout of an arbitrary memory chunk between the GL and youself. Good old glUniform explicitly knows what data it gets.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.