Crate glsl_layout

source ·
Expand description

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 of Elements. This type implements useful traits for converting from unwrapped types.
Array ref iterator Iterate over references to inner values.
Aligning wrapper. Elements for array are aligned to 16 bytes (size of vec4) at least.
Boolean value.
Vector of 2 boolean values. foo: bvec2 is equivalent to glsl’s bvec2 foo;
Vector of 3 boolean values. foo: bvec3 is equivalent to glsl’s bvec3 foo;
Vector of 4 boolean values. foo: bvec4 is equivalent to glsl’s bvec4 foo;
Vector of 2 double value. foo: dvec2 is equivalent to glsl’s dvec2 foo;
Vector of 3 double value. foo: dvec3 is equivalent to glsl’s dvec3 foo;
Vector of 4 double value. foo: dvec4 is equivalent to glsl’s dvec4 foo;
Vector of 2 int values. foo: ivec2 is equivalent to glsl’s ivec2 foo;
Vector of 3 int values. foo: ivec3 is equivalent to glsl’s ivec3 foo;
Vector of 4 int values. foo: ivec4 is equivalent to glsl’s ivec4 foo;
Vector of 2 uint values. foo: uvec2 is equivalent to glsl’s uvec2 foo;
Vector of 3 uint values. foo: uvec3 is equivalent to glsl’s uvec3 foo;
Vector of 4 uint values. foo: uvec4 is equivalent to glsl’s uvec4 foo;
Vector of 2 float values. foo: vec2 is equivalent to glsl’s vec2 foo;
Vector of 3 float values. foo: vec3 is equivalent to glsl’s vec3 foo;
Vector of 4 float values. foo: vec4 is equivalent to glsl’s vec4 foo;

Traits

Special marker trait implemented only for std140 types.
Structure to transform data from rust’s structure to the raw data ready to upload to UBO. Users should prefer to use derive(Uniform) instead of implementing this manually.

Type Definitions

Matrix of 2 x 2 boolean values.
Matrix of 2 x 2 boolean values.
Matrix of 2 x 3 boolean values.
Matrix of 2 x 4 boolean values.
Matrix of 3 x 3 boolean values.
Matrix of 3 x 2 boolean values.
Matrix of 3 x 3 boolean values.
Matrix of 3 x 4 boolean values.
Matrix of 4 x 4 boolean values.
Matrix of 4 x 2 boolean values.
Matrix of 4 x 3 boolean values.
Matrix of 4 x 4 boolean values.
Matrix of 2 x 2 double-precision floating-point values.
Matrix of 2 x 2 double-precision floating-point values.
Matrix of 2 x 3 double-precision floating-point values.
Matrix of 2 x 4 double-precision floating-point values.
Matrix of 3 x 3 double-precision floating-point values.
Matrix of 3 x 2 double-precision floating-point values.
Matrix of 3 x 3 double-precision floating-point values.
Matrix of 3 x 4 double-precision floating-point values.
Matrix of 4 x 4 double-precision floating-point values.
Matrix of 4 x 2 double-precision floating-point values.
Matrix of 4 x 3 double-precision floating-point values.
Matrix of 4 x 4 double-precision floating-point values.
Double-precision floating-point value.
floating-point value.
Matrix of 2 x 2 signed integer values.
Matrix of 2 x 2 signed integer values.
Matrix of 2 x 3 signed integer values.
Matrix of 2 x 4 signed integer values.
Matrix of 3 x 3 signed integer values.
Matrix of 3 x 2 signed integer values.
Matrix of 3 x 3 signed integer values.
Matrix of 3 x 4 signed integer values.
Matrix of 4 x 4 signed integer values.
Matrix of 4 x 2 signed integer values.
Matrix of 4 x 3 signed integer values.
Matrix of 4 x 4 signed integer values.
Signed integer value.
Matrix of 2 x 2 floating-point values.
Matrix of 2 x 2 floating-point values.
Matrix of 2 x 3 floating-point values.
Matrix of 2 x 4 floating-point values.
Matrix of 3 x 3 floating-point values.
Matrix of 3 x 2 floating-point values.
Matrix of 3 x 3 floating-point values.
Matrix of 3 x 4 floating-point values.
Matrix of 4 x 4 floating-point values.
Matrix of 4 x 2 floating-point values.
Matrix of 4 x 3 floating-point values.
Matrix of 4 x 4 floating-point values.
Unsigned integer value.
Matrix of 2 x 2 unsiged integer values.
Matrix of 2 x 2 unsiged integer values.
Matrix of 2 x 3 unsiged integer values.
Matrix of 2 x 4 unsiged integer values.
Matrix of 3 x 3 unsiged integer values.
Matrix of 3 x 2 unsiged integer values.
Matrix of 3 x 3 unsiged integer values.
Matrix of 3 x 4 unsiged integer values.
Matrix of 4 x 4 unsiged integer values.
Matrix of 4 x 2 unsiged integer values.
Matrix of 4 x 3 unsiged integer values.
Matrix of 4 x 4 unsiged integer values.