As per the specification Variables declared inside a Uniform Buffer must be properly aligned.
I have the following GLM variables in my structure:
struct UniformBufferObject_PointLights {
glm::f32 constant[64]{};
glm::f32 linear[64]{};
glm::f32 quadratic[64]{};
glm::vec3 position[64]{};
glm::vec3 ambient[64]{};
glm::vec3 diffuse[64]{};
glm::int32 count{};
};
- Attempting to access any of the variables from within the shader acts
as if their values are all 0. The issue is centered around the
glm::f32
andglm::uint32
declarations.
The glm::vec3
's are all accessible by simply declaring them above the glm::f32
's and glm::uint32
, however, the glm::uint32
and glm::f32
's are still inaccessible. At this point I figure it must be an alignment issue.
// After rearrangement.
struct UniformBufferObject_PointLights {
glm::vec3 position[64]{};
glm::vec3 ambient[64]{};
glm::vec3 diffuse[64]{};
glm::f32 constant[64]{};
glm::f32 linear[64]{};
glm::f32 quadratic[64]{};
glm::uint32 count{};
};
position
,ambient
, anddiffuse
are all accessible after moving them to the top of the struct.
I have set #define GLM_FORCE_DEFAULT_ALIGNED_GENTYPES
but it doesn't appear to work for glm::f32
and glm::uint32
and probably others. What do I need to do to get these variables working in my uniform buffer? I've tried placing alignas(4)
,alignas(8)
,alignas(16)
, and alignas(32)
before their declarations but no combination works.