pub unsafe trait InterfaceBlock: StableRepr {
const MEMORY_UNITS: &'static [MemoryUnit];
}
pub unsafe trait InterfaceBlockComponent: StableRepr {
const MEMORY_UNITS: &'static [MemoryUnit];
}
unsafe impl<T> InterfaceBlockComponent for T
where
T: InterfaceBlock,
{
const MEMORY_UNITS: &'static [MemoryUnit] = T::MEMORY_UNITS;
}
pub unsafe trait StableRepr {}
#[derive(PartialEq, Clone, Copy, Debug)]
pub struct MemoryUnit {
pub offset: usize,
pub layout: UnitLayout,
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum MatrixOrder {
ColumnMajor,
RowMajor,
}
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum UnitLayout {
Float,
FloatArray {
stride: u8,
len: usize,
},
FloatVector2,
FloatVector2Array {
stride: u8,
len: usize,
},
FloatVector3,
FloatVector3Array {
stride: u8,
len: usize,
},
FloatVector4,
FloatVector4Array {
stride: u8,
len: usize,
},
Integer,
IntegerArray {
stride: u8,
len: usize,
},
IntegerVector2,
IntegerVector2Array {
stride: u8,
len: usize,
},
IntegerVector3,
IntegerVector3Array {
stride: u8,
len: usize,
},
IntegerVector4,
IntegerVector4Array {
stride: u8,
len: usize,
},
UnsignedInteger,
UnsignedIntegerArray {
stride: u8,
len: usize,
},
UnsignedIntegerVector2,
UnsignedIntegerVector2Array {
stride: u8,
len: usize,
},
UnsignedIntegerVector3,
UnsignedIntegerVector3Array {
stride: u8,
len: usize,
},
UnsignedIntegerVector4,
UnsignedIntegerVector4Array {
stride: u8,
len: usize,
},
Bool,
BoolArray {
stride: u8,
len: usize,
},
BoolVector2,
BoolVector2Array {
stride: u8,
len: usize,
},
BoolVector3,
BoolVector3Array {
stride: u8,
len: usize,
},
BoolVector4,
BoolVector4Array {
stride: u8,
len: usize,
},
Matrix2x2 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix2x2Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix2x3 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix2x3Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix2x4 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix2x4Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix3x2 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix3x2Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix3x3 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix3x3Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix3x4 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix3x4Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix4x2 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix4x2Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix4x3 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix4x3Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
Matrix4x4 {
order: MatrixOrder,
matrix_stride: u8,
},
Matrix4x4Array {
order: MatrixOrder,
matrix_stride: u8,
array_stride: u8,
len: usize,
},
}
unsafe impl<T> StableRepr for T where T: std140::ReprStd140 {}
macro_rules! impl_interface_block_component_std140 {
($T:ident, $layout:expr) => {
unsafe impl InterfaceBlockComponent for std140::$T {
const MEMORY_UNITS: &'static [MemoryUnit] = &[MemoryUnit {
offset: 0,
layout: $layout,
}];
}
};
}
impl_interface_block_component_std140!(float, UnitLayout::Float);
impl_interface_block_component_std140!(vec2, UnitLayout::FloatVector2);
impl_interface_block_component_std140!(vec3, UnitLayout::FloatVector3);
impl_interface_block_component_std140!(vec4, UnitLayout::FloatVector4);
impl_interface_block_component_std140!(int, UnitLayout::Integer);
impl_interface_block_component_std140!(ivec2, UnitLayout::IntegerVector2);
impl_interface_block_component_std140!(ivec3, UnitLayout::IntegerVector3);
impl_interface_block_component_std140!(ivec4, UnitLayout::IntegerVector4);
impl_interface_block_component_std140!(uint, UnitLayout::UnsignedInteger);
impl_interface_block_component_std140!(uvec2, UnitLayout::UnsignedIntegerVector2);
impl_interface_block_component_std140!(uvec3, UnitLayout::UnsignedIntegerVector3);
impl_interface_block_component_std140!(uvec4, UnitLayout::UnsignedIntegerVector4);
impl_interface_block_component_std140!(boolean, UnitLayout::Bool);
impl_interface_block_component_std140!(bvec2, UnitLayout::BoolVector2);
impl_interface_block_component_std140!(bvec3, UnitLayout::BoolVector3);
impl_interface_block_component_std140!(bvec4, UnitLayout::BoolVector4);
impl_interface_block_component_std140!(
mat2x2,
UnitLayout::Matrix2x2 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat2x3,
UnitLayout::Matrix2x3 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat2x4,
UnitLayout::Matrix2x4 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat3x2,
UnitLayout::Matrix3x2 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat3x3,
UnitLayout::Matrix3x3 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat3x4,
UnitLayout::Matrix3x4 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat4x2,
UnitLayout::Matrix4x2 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat4x3,
UnitLayout::Matrix4x3 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
impl_interface_block_component_std140!(
mat4x4,
UnitLayout::Matrix4x4 {
order: MatrixOrder::ColumnMajor,
matrix_stride: 16
}
);
macro_rules! impl_interface_block_component_std140_array {
($T:ident, $layout_ident:ident) => {
unsafe impl<const LEN: usize> InterfaceBlockComponent
for std140::array<std140::$T, { LEN }>
{
const MEMORY_UNITS: &'static [MemoryUnit] = &[MemoryUnit {
offset: 0,
layout: UnitLayout::$layout_ident {
stride: 16,
len: LEN,
},
}];
}
};
}
impl_interface_block_component_std140_array!(float, FloatArray);
impl_interface_block_component_std140_array!(vec2, FloatVector2Array);
impl_interface_block_component_std140_array!(vec3, FloatVector3Array);
impl_interface_block_component_std140_array!(vec4, FloatVector4Array);
impl_interface_block_component_std140_array!(int, IntegerArray);
impl_interface_block_component_std140_array!(ivec2, IntegerVector2Array);
impl_interface_block_component_std140_array!(ivec3, IntegerVector3Array);
impl_interface_block_component_std140_array!(ivec4, IntegerVector4Array);
impl_interface_block_component_std140_array!(uint, UnsignedIntegerArray);
impl_interface_block_component_std140_array!(uvec2, UnsignedIntegerVector2Array);
impl_interface_block_component_std140_array!(uvec3, UnsignedIntegerVector3Array);
impl_interface_block_component_std140_array!(uvec4, UnsignedIntegerVector4Array);
impl_interface_block_component_std140_array!(boolean, BoolArray);
impl_interface_block_component_std140_array!(bvec2, BoolVector2Array);
impl_interface_block_component_std140_array!(bvec3, BoolVector3Array);
impl_interface_block_component_std140_array!(bvec4, BoolVector4Array);
macro_rules! impl_interface_block_component_std140_matrix_array {
($T:ident, $layout_ident:ident) => {
unsafe impl<const LEN: usize> InterfaceBlockComponent
for std140::array<std140::$T, { LEN }>
{
const MEMORY_UNITS: &'static [MemoryUnit] = &[MemoryUnit {
offset: 0,
layout: UnitLayout::$layout_ident {
order: MatrixOrder::ColumnMajor,
array_stride: 16,
matrix_stride: 16,
len: LEN,
},
}];
}
};
}
impl_interface_block_component_std140_matrix_array!(mat2x2, Matrix2x2Array);
impl_interface_block_component_std140_matrix_array!(mat2x3, Matrix2x3Array);
impl_interface_block_component_std140_matrix_array!(mat2x4, Matrix2x4Array);
impl_interface_block_component_std140_matrix_array!(mat3x2, Matrix3x2Array);
impl_interface_block_component_std140_matrix_array!(mat3x3, Matrix3x3Array);
impl_interface_block_component_std140_matrix_array!(mat3x4, Matrix3x4Array);
impl_interface_block_component_std140_matrix_array!(mat4x2, Matrix4x2Array);
impl_interface_block_component_std140_matrix_array!(mat4x3, Matrix4x3Array);
impl_interface_block_component_std140_matrix_array!(mat4x4, Matrix4x4Array);