<p>It does mean exactly that. Whenever you have an array, it's <strong>treated as an array of <code>vec4</code>s with regards to the memory layout</strong>. So in your <code>float</code> array you actually have 28 <code>float</code>s with each of the 7 values followed by 3 values of (basically unnecessary) padding to <strong>round each array element's alignment up to 16 byte</strong> (the size of a <code>vec4</code>). And yes, that's why <code>std140</code> layout plain sucks! ;-)</p>
<p>However, do keep in mind that <strong>this only applies to uniform blocks, i.e. uniform data sourced from buffers</strong>. 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 <code>glUniform</code> explicitly knows what data it gets.</p>

CC BY-SA 4.0
2023-10-05T12:11:58.547Z
2023-10-05T12:11:58.547Z
Christian Rau
<p>in <a href="https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf" rel="nofollow noreferrer">GLSL spec</a> section 7.6.2.2 about Standard Uniform Block Layout, rule (4) says:</p>
<blockquote>
<p>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.</p>
</blockquote>
<p>I am not sure about the rounding of array stride to the base alignment of a vec4?</p>
<p>What does it mean the array element stride would be for a Uniform member looking like that:</p>
<pre><code>struct MyStruct
{
   float myArray[7];
}

uniform MyStruct myStruct;
</code></pre>

<glsl>
GLSL Uniform Layout Spec says member array stride alignment is rounded up to vec4?
wip
# GLSL Uniform Layout Spec says member array stride alignment is rounded up to vec4?

(Asked by: username_0 on 2023-10-03)

in [GLSL spec](https://registry.khronos.org/OpenGL/specs/gl/glspec46.core.pdf) section 7.6.2.2 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;

```

**Tags:** glsl


---

## 1 answers

### Answer by username_1 on 2023-10-05. Score: 1 | Accepted answer

It does mean exactly that. Whenever you have an array, it's **treated as an array of `vec4`s with regards to the memory layout**. So in your `float` array you actually have 28 `float`s 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.


---

