Crate glsl_layout[][src]

This crates provides data types to build structures ready to upload into UBO. Data layout will match one for uniform blocks declared with layout(std140). See specs for alignment rules.

Examples

#[derive(Debug, Default, Clone, Copy, Uniform)]
struct Foo {
    x: int,
    y: vec3,
    z: float,
    w: mat4x4,
    a: [f32; 3],
    b: f32,
}

type UFoo = <Foo as Uniform>::Std140;

assert_eq!(
    offset_of!(UFoo: y),
    round_up_to(size_of::<int>(), 16), // `vec3` has alignment of size `vec4`
    "Offset of field `y` must be equal of size of `x` rounded up to the alignment",
);

assert_eq!(
    offset_of!(UFoo: z),
    round_up_to(offset_of!(UFoo: y) + size_of::<vec3>(), 4),
    "Field `z` must follow `y`. `y` should not have padding at the end",
);

assert_eq!(
    offset_of!(UFoo: b),
    offset_of!(UFoo: a) + size_of::<[[f32; 4]; 3]>(),
    "Field `b` must follow `a`. But `a` has padding at the end.",
);
let foo_uniform = Foo {
    x: 2,
    y: [0.0; 3].into(),
    z: 0.0,
    w: [[0.0; 4]; 4].into(),
    a: [0.0; 3].into(),
    b: 0.0,
}.std140();

Structs

Array

Array of Elements. This type implements useful traits for converting from unwrapped types.

ArrayIter

Array ref iterator Iterate over references to inner values.

Element

Aligning wrapper. Elements for array are aligned to 16 bytes (size of vec4) at least.

boolean

Boolean value.

bvec2

Vector of 2 boolean values. foo: bvec2 is equivalent to glsl's bvec2 foo;

bvec3

Vector of 3 boolean values. foo: bvec3 is equivalent to glsl's bvec3 foo;

bvec4

Vector of 4 boolean values. foo: bvec4 is equivalent to glsl's bvec4 foo;

dvec2

Vector of 2 double value. foo: dvec2 is equivalent to glsl's dvec2 foo;

dvec3

Vector of 3 double value. foo: dvec3 is equivalent to glsl's dvec3 foo;

dvec4

Vector of 4 double value. foo: dvec4 is equivalent to glsl's dvec4 foo;

ivec2

Vector of 2 int values. foo: ivec2 is equivalent to glsl's ivec2 foo;

ivec3

Vector of 3 int values. foo: ivec3 is equivalent to glsl's ivec3 foo;

ivec4

Vector of 4 int values. foo: ivec4 is equivalent to glsl's ivec4 foo;

uvec2

Vector of 2 uint values. foo: uvec2 is equivalent to glsl's uvec2 foo;

uvec3

Vector of 3 uint values. foo: uvec3 is equivalent to glsl's uvec3 foo;

uvec4

Vector of 4 uint values. foo: uvec4 is equivalent to glsl's uvec4 foo;

vec2

Vector of 2 float values. foo: vec2 is equivalent to glsl's vec2 foo;

vec3

Vector of 3 float values. foo: vec3 is equivalent to glsl's vec3 foo;

vec4

Vector of 4 float values. foo: vec4 is equivalent to glsl's vec4 foo;

Traits

Std140

Special marker trait implemented only for std140 types.

Uniform

Structure to transform data from rust's structure to the raw data ready to upload to UBO. Users should prepfer to use derive(Uniform) instead of implementing this manually.

Type Definitions

bmat2

Matrix of 2 x 2 boolean values.

bmat3

Matrix of 3 x 3 boolean values.

bmat4

Matrix of 4 x 4 boolean values.

bmat2x2

Matrix of 2 x 2 boolean values.

bmat2x3

Matrix of 2 x 3 boolean values.

bmat2x4

Matrix of 2 x 4 boolean values.

bmat3x2

Matrix of 3 x 2 boolean values.

bmat3x3

Matrix of 3 x 3 boolean values.

bmat3x4

Matrix of 3 x 4 boolean values.

bmat4x2

Matrix of 4 x 2 boolean values.

bmat4x3

Matrix of 4 x 3 boolean values.

bmat4x4

Matrix of 4 x 4 boolean values.

dmat2

Matrix of 2 x 2 double-precision floating-point values.

dmat3

Matrix of 3 x 3 double-precision floating-point values.

dmat4

Matrix of 4 x 4 double-precision floating-point values.

dmat2x2

Matrix of 2 x 2 double-precision floating-point values.

dmat2x3

Matrix of 2 x 3 double-precision floating-point values.

dmat2x4

Matrix of 2 x 4 double-precision floating-point values.

dmat3x2

Matrix of 3 x 2 double-precision floating-point values.

dmat3x3

Matrix of 3 x 3 double-precision floating-point values.

dmat3x4

Matrix of 3 x 4 double-precision floating-point values.

dmat4x2

Matrix of 4 x 2 double-precision floating-point values.

dmat4x3

Matrix of 4 x 3 double-precision floating-point values.

dmat4x4

Matrix of 4 x 4 double-precision floating-point values.

double

Double-precision floating-point value.

float

floating-point value.

imat2

Matrix of 2 x 2 signed integer values.

imat3

Matrix of 3 x 3 signed integer values.

imat4

Matrix of 4 x 4 signed integer values.

imat2x2

Matrix of 2 x 2 signed integer values.

imat2x3

Matrix of 2 x 3 signed integer values.

imat2x4

Matrix of 2 x 4 signed integer values.

imat3x2

Matrix of 3 x 2 signed integer values.

imat3x3

Matrix of 3 x 3 signed integer values.

imat3x4

Matrix of 3 x 4 signed integer values.

imat4x2

Matrix of 4 x 2 signed integer values.

imat4x3

Matrix of 4 x 3 signed integer values.

imat4x4

Matrix of 4 x 4 signed integer values.

int

Signed integer value.

mat2

Matrix of 2 x 2 floating-point values.

mat3

Matrix of 3 x 3 floating-point values.

mat4

Matrix of 4 x 4 floating-point values.

mat2x2

Matrix of 2 x 2 floating-point values.

mat2x3

Matrix of 2 x 3 floating-point values.

mat2x4

Matrix of 2 x 4 floating-point values.

mat3x2

Matrix of 3 x 2 floating-point values.

mat3x3

Matrix of 3 x 3 floating-point values.

mat3x4

Matrix of 3 x 4 floating-point values.

mat4x2

Matrix of 4 x 2 floating-point values.

mat4x3

Matrix of 4 x 3 floating-point values.

mat4x4

Matrix of 4 x 4 floating-point values.

uint

Unsigned integer value.

umat2

Matrix of 2 x 2 unsiged integer values.

umat3

Matrix of 3 x 3 unsiged integer values.

umat4

Matrix of 4 x 4 unsiged integer values.

umat2x2

Matrix of 2 x 2 unsiged integer values.

umat2x3

Matrix of 2 x 3 unsiged integer values.

umat2x4

Matrix of 2 x 4 unsiged integer values.

umat3x2

Matrix of 3 x 2 unsiged integer values.

umat3x3

Matrix of 3 x 3 unsiged integer values.

umat3x4

Matrix of 3 x 4 unsiged integer values.

umat4x2

Matrix of 4 x 2 unsiged integer values.

umat4x3

Matrix of 4 x 3 unsiged integer values.

umat4x4

Matrix of 4 x 4 unsiged integer values.