I refer here(https://www.khronos.org/registry/OpenGL/extensions/ARB/ARB_uniform_buffer_object.txt) for the std140 layout.
I have questions of reading about std140 layout rules, especially the phrase “rounded up to vec4”
(4) 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. The array may have padding at the
end; the base offset of the member following the array is rounded up
to the next multiple of the base alignment.
(9) If the member is a structure, the base alignment of the structure is
<N>, where <N> is the largest base alignment value of any of its
members, and rounded up to the base alignment of a vec4. The
individual members of this sub-structure are then assigned offsets
by applying this set of rules recursively, where the base offset of
the first member of the sub-structure is equal to the aligned offset
of the structure. The structure may have padding at the end; the
base offset of the member following the sub-structure is rounded up
to the next multiple of the base alignment of the structure.
The Number 4 rule is saying that 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. the point that makes me confused is that the rule mentions the base alignment of a single array element according to rules(1), (2), and (3), and then, rounded up to the base alignment of a vec4. When I read the first part of the rule, I think If I use arrays of scalar and vectors, the base alignment will be the value according to rules (1), (2), and (3). For example, If I use float foo[4]
in uniform buffer block, then I think its base alignment would be 4. But, The second part of the rule, rounded up to the base alignment of a vec4, changes the whole rule. I mean the second part just makes the base alignment of arrays be the base alignment of vec4, which is 16.
So I wonder why the specification mentions the rules (1), (2), and (3), and then the base alignment will be anyway 16? I think It would be more clear that the base alignment of array is the base alignment of vec4.
My question applies to the number 9 rules in the same way.
If I’m wrong, I think my interpretation is bad. Please correct me.