Data Types

Extensions add float16_t, int8_t, int16_t, int64_t, uint64_t (GL_EXT_shader_explicit_arithmetic_types).

6.1 Scalars

32-bit signed integer (GLSL ≥ 1.30 has full integer ops) 32-bit unsigned integer (5u) 32-bit IEEE float

64-bit float (GLSL 4.00+, desktop only; slow on consumer GPUs) no return value

Extensions add float16_t, int8_t, int16_t, int64_t, uint64_t (GL_EXT_shader_explicit_arithmetic_types).

6.3 Matrices (column-major, float or double)

mat2, mat3, mat4 (square), mat2x3, mat3x4, ... (matCxR: C columns, R rows), dmat4, etc.

6.4 Opaque types (samplers, images, atomic counters)

sampler1D, sampler2D, sampler3D, samplerCube sampler2DArray, samplerCubeArray, sampler2DMS, samplerBuffer, sampler2DRect arrays, multisample, buffer textures

sampler2DShadow, samplerCubeShadow, sampler2DArrayShadow depth comparison (shadow maps) isampler2D, usampler2D,...

image2D, uimage2D, iimage3D, ...

read/write images (load/store) Vulkan: texture2D, sampler (separate), subpassInput separate images/samplers, input attachments

Opaque types can only be declared as uniform (or function parameters) and can't be assigned.

6.5 Arrays

Array sizes must be compile-time constants (except unsized last members of SSBOs).

float weights[5] = float[](0.227, 0.194, 0.121, 0.054, 0.016);
vec3 lights[4];
int n = weights.length();          // .length() method
float grid[3][3];                  // arrays of arrays (GLSL 4.30+, ES 3.10+)
uniform vec4 colors[8];

6.6 Structures

struct Light {
    vec3 position;
    vec3 color;
    float intensity;
};
uniform Light uLights[4];

Light l = Light(vec3(0.0, 5.0, 0.0), vec3(1.0), 2.0);   // constructor
float i = l.intensity;

6.7 Type conversion & constructors

GLSL has very limited implicit conversion (int → float and to uint in some contexts in desktop GLSL ≥ 4.00; none in GLSL ES). Use constructors:

⚠️ float x = 1; is an error in GLSL ES — write 1.0.

float f = float(3);          // int → float
int i = int(2.7);            // 2 (truncation)
uint u = uint(5);
bool b = bool(1);
vec3 v = vec3(1.0);          // (1, 1, 1)
vec4 p = vec4(v, 1.0);       // combine
vec2 xy = vec2(p);           // truncation: first two components
mat3 m3 = mat3(m4);          // upper-left 3×3 of a mat4
mat4 id = mat4(1.0);         // identity matrix
ivec2 ip = ivec2(gl_FragCoord.xy);
float bits = intBitsToFloat(0x3f800000);   // reinterpret bits → 1.0