I've come up against something that's confused me, and I can't find the answer to it. When I write shader like this:
layout (location = 0) in vec3 inPosition;
layout (location = 1) in vec3 inNormal;
layout (location = 2) in vec2 inTexCoords;
I know that the vec3's aren't 16 byte aligned as many vec4's are, or SIMD compatible data types. I know this (I think), because my data in my C++ code is:
struct Vertex
{
vec3 position;
vec3 normal;
vec2 texCoords;
};
Each vector sits snugly with each other, with no padding, the size being 8 * sizeof(float), 32 bytes. I pass it to the uniform and the shader reads it fine, so I know they are both aligned.
But when it comes to uniform blocks in GLSL, with for example the std140 standard a vec3 must be padded with an extra four bytes before adding another vec3 or vec4:
- If the member is a three-component vector with components consuming N basic machine units, the base alignment is 4N
However you can also store a four-byte int or four-byte bool in between the vec3 and the next vec3 to compact the size. So does this mean that the attrib pointer values for the vertex layout doesn't follow std140 layout? Also if for example I use SIMD 16-byte aligned vectors in my C++ code does this mean I'll no longer be able to set the attrib pointer values as vec3, vec3, vec2, but rather have all vec4's?
Also I saw the following warning on the documentation:
Warning: Implementations sometimes get the std140 layout wrong for vec3 components. You are advised to manually pad your structures/arrays out and avoid using vec3 at all.
Here it's saying to avoid using vec3 at all, but I thought it was a smart space-saving technique to pack a four byte int or bool after a vec3.