Reputation: 632
I've been trying to use the following code to do a global list of bindless texture handles, sent to the GPU using a UBO.
struct Material
{
sampler2D diff;
sampler2D spec;
sampler2D norm;
};
layout(std140, binding = 2) uniform Materials
{
Material materials[64];
};
However, I think I am filling in the buffer wrong in c++, not taking into account the correct offsets etc. I can't seem to find anything on how the std140 layout handles sampler2D. How should I be doing this? What offsets do I need to take into account?
Upvotes: 1
Views: 555
Reputation: 473397
There's nothing special about handles in this regard. The standard says:
If the member is a scalar consuming N basic machine units, the base align- ment is N.
Samplers are effectively 64-bit integers as far as being "scalars" are concerned. So the base alignment of those members is 64-bit integers. But that's not really relevant, because in std140
, the alignment of a struct is always rounded up to the size of a vec4. So that struct will take up 32 bytes.
Upvotes: 3