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
- Array of
Elements. This type implements useful traits for converting from unwrapped types. - Array
Iter - 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
booleanvalues.foo: bvec2is equivalent to glsl’sbvec2 foo; - bvec3
- Vector of 3
booleanvalues.foo: bvec3is equivalent to glsl’sbvec3 foo; - bvec4
- Vector of 4
booleanvalues.foo: bvec4is equivalent to glsl’sbvec4 foo; - dvec2
- Vector of 2
doublevalue.foo: dvec2is equivalent to glsl’sdvec2 foo; - dvec3
- Vector of 3
doublevalue.foo: dvec3is equivalent to glsl’sdvec3 foo; - dvec4
- Vector of 4
doublevalue.foo: dvec4is equivalent to glsl’sdvec4 foo; - ivec2
- Vector of 2
intvalues.foo: ivec2is equivalent to glsl’sivec2 foo; - ivec3
- Vector of 3
intvalues.foo: ivec3is equivalent to glsl’sivec3 foo; - ivec4
- Vector of 4
intvalues.foo: ivec4is equivalent to glsl’sivec4 foo; - uvec2
- Vector of 2
uintvalues.foo: uvec2is equivalent to glsl’suvec2 foo; - uvec3
- Vector of 3
uintvalues.foo: uvec3is equivalent to glsl’suvec3 foo; - uvec4
- Vector of 4
uintvalues.foo: uvec4is equivalent to glsl’suvec4 foo; - vec2
- Vector of 2
floatvalues.foo: vec2is equivalent to glsl’svec2 foo; - vec3
- Vector of 3
floatvalues.foo: vec3is equivalent to glsl’svec3 foo; - vec4
- Vector of 4
floatvalues.foo: vec4is equivalent to glsl’svec4 foo;
Traits§
- Std140
- Special marker trait implemented only for
std140types. - Uniform
- 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 Aliases§
- 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.