shader-types
Vector and Matrix types that are properly aligned for use in std140 uniforms.
All the types in this library have the same alignment and size as the equivilant glsl type in the default mode (std140).
This fixes the padding within members of structs but padding between members needs to be minded.
The types in padding
are there to make this easier.
Vectors are constructable to/from an array of their underlying type. Matrices are constructable
to/from both 1d and 2d arrays as well as an array of the underlying vector type. (eg. Mat2
can be
constructed from [Vec2; 2]
)
Example
For the following glsl:
layout(set = 0, binding = 0) uniform Block {
mat4 mvp;
vec3 position;
vec3 normal;
vec2 uv;
}
This struct is rife with padding. However it's now easy to mind the padding:
use ;
use Pad2Float;
// Definition
// #[derive(zerocopy::AsBytes)] // Supports zerocopy with the `zerocopy` feature
// Construction
let block = UniformBlock ;
// Supports bytemuck with the `bytemuck` feature
unsafe
// Safe to implement as there is no implicit padding
unsafe
let block_u8: & = cast_slice;
License: MIT OR Apache-2.0 OR Zlib