1

According to OpenGL specs 4.5, bool in std140 layout block reserve 1 byte (sizeof(GLboolean) == 1). But when I get the offset of b, it is 4. Where is the misunderstanding?

layout (std140) uniform Uniforms
{
    bool a;
    bool b;
};

The following structure expands 4 bytes to 64. Why engineers created a so super resource-wasted standard?

layout (std140) uniform Uniforms
{
    bool a[4];
};
Chameleon
  • 1,584
  • 1
  • 11
  • 16

1 Answers1

3

GLboolean is an altogether different type from bool in GLSL.

The smallest scalar data type in GLSL is 32-bit, so everything is aligned to some multiple of 4-bytes. For anything smaller than 32-bit you generally want to pack and unpack an integer or floating-point value yourself, so I would consider using a uint instead.

You can store 32 bool values in one uint if you do the packing yourself.

Andon M. Coleman
  • 41,103
  • 2
  • 75
  • 104