Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the size of GLSL boolean

There is a bool type for shader variables I'd like to use, but I couldn't find what size it have. This matters because when setting up vertex attribute pointer I specify the type of data which can be

GL_BYTE,
GL_UNSIGNED_BYTE,
GL_SHORT,
GL_UNSIGNED_SHORT,
GL_INT,
GL_UNSIGNED_INT,
GL_FLOAT, or
GL_DOUBLE

In c++ generally bool should have the same size as 4 byte int, but can I assume the same for GLSL or does it have only 1 byte?

like image 814
Raven Avatar asked Feb 23 '12 19:02

Raven


People also ask

How big is a Boolean?

Boolean variables are stored as 16-bit (2-byte) numbers, but they can only be True or False.

How big is a Boolean C#?

The actual size of a C# bool is one byte.

How much space does a bool take up?

bool The bool type takes one byte and stores a value of true (1) or false(0).

How many bytes is a vec4?

So, the alignment of a mat4 is like that of a vec4, which is 16 bytes. And the size of a mat4 is 4*sizeof(vec4) = 4*16 bytes.


1 Answers

This matters because when setting up vertex attribute pointer I specify the type of data which can be

It's irrelevant, since vertex attributes cannot be booleans. From the GLSL 3.30 specification:

Vertex shader inputs can only be float, floating-point vectors, matrices, signed and unsigned integers and integer vectors. Vertex shader inputs can also form arrays of these types, but not structures.

Booleans are not on that list.

However, if you want to know what the size of a GLSL bool is in terms of uniform blocks, it has the same size as uint: 32-bits.

like image 68
Nicol Bolas Avatar answered Sep 17 '22 01:09

Nicol Bolas