I am reading about std140 and std430 layouts in GLSL.
Consider, in C++:
struct Foo
{
glm::vec4 alpha;
float beta;
float gamma;
glm::vec4 delta;
float epsilon;
};
In GLSL:
uniform (layout=std140) MyUniformBlock
{
vec4 alpha;
float beta;
float gamma;
vec4 delta;
float epsilon;
};
If I'm reading the documentation correctly, the offsets in MyUniformBlock
will be 0, 16, 32, 48, 64, bytes: all multiples of sizeof(vec4)==16
. Right?
However, in C/C++, it is permitted for gamma
to have an offset of 20 bytes, right?
So under what conditions will the C/C++ struct and the GLSL interface block have the same layout?
If I use layout=packed
and give the struct __attribute__ ((packed))
or equivalent, is that guaranteed to match?
Also, consider
Foo array [N];
If C/C++ permits sizeof(Foo)
to be not a multiple of sizeof(vec4)
because there is no padding after the last element, does that cause problems if I try to send the whole of array
to the buffer with glBufferData
?