#[derive(Desc)]
{
// Attributes available to this derive:
#[u8x2]
#[u8x4]
#[s8x2]
#[s8x4]
#[un8x2]
#[un8x4]
#[sn8x2]
#[sn8x4]
#[u16x2]
#[u16x4]
#[s16x2]
#[s16x4]
#[un16x2]
#[un16x4]
#[sn16x2]
#[sn16x4]
#[f16x2]
#[f16x4]
#[f32]
#[f32x2]
#[f32x3]
#[f32x4]
#[u32]
#[u32x2]
#[u32x3]
#[u32x4]
#[s32]
#[s32x2]
#[s32x3]
#[s32x4]
#[f64]
#[f64x2]
#[f64x3]
#[f64x4]
#[mat2x2]
#[mat2x3]
#[mat2x4]
#[mat3x2]
#[mat3x3]
#[mat3x4]
#[mat4x2]
#[mat4x3]
#[mat4x4]
}
Expand description
Desc is a proc derive macro that allow you to describe a structure as a description to pass to a renderpipeline.
§Example
use wrld::Desc;
#[repr(C)]
#[derive(Desc)]
struct Test {
#[f32x3(0)] position: Vector3
#[f32x4(1)] color: Vector4
}into
impl Test {
pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
// let size_f32 = size_of::<f32>() = 4
// let f32x3 = size_f32 * 3 = 12;
// let f32x4 = size_f32 * 4 = 16;
// let array_stride = 12 + 16 = 28;
wgpu::VertexBufferLayout {
array_stride: 28 as wgpu::BufferAddress // array_stride variable,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
wgpu::VertexAttribute {
offset: 0u64,
format: wgpu::VertexFormat::Float32x3,
shader_location: 0u32,
},
wgpu::VertexAttribute {
offset: 12u64,
format: wgpu::VertexFormat::Float32x4,
shader_location: 1u32,
},
],
}
}
}§Matrice attributes
Matrices attributes are kind of special, because matrices are the only attributes that can take multiple location.
Matrices need two argument :
- The type of the matrice (u8, f32, f64, ect…)
- And the starting location
Matrices dimension start from 2x2 to 4x4
§Example
#[repr(C)]
#[derive(wrld::Desc)]
struct Actor {
#[mat4x2(u8, 0)] transform: [[f32; 4]; 4]
}Will result to
impl Actor {
pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
wgpu::VertexBufferLayout {
array_stride: 8u64 as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Instance,
attributes: &[
wgpu::VertexAttribute {
offset: 0u64,
format: wgpu::VertexFormat::Uint8x2,
shader_location: 0u32,
},
wgpu::VertexAttribute {
offset: 2u64,
format: wgpu::VertexFormat::Uint8x2,
shader_location: 1u32,
},
wgpu::VertexAttribute {
offset: 4u64,
format: wgpu::VertexFormat::Uint8x2,
shader_location: 2u32,
},
wgpu::VertexAttribute {
offset: 6u64,
format: wgpu::VertexFormat::Uint8x2,
shader_location: 3u32,
},
],
}
}
}So take care while using it.
Also matrix type handle only wgpu VertexFormat type for row. That does mean that matrix like that.
#[repr(C)]
#[derive(wrld::DescInstance)]
struct Vertex {
#[mat4x3(u8, 0)] transform: [[f32; 4]; 4]
}Will throw an error :
“Matrix mat4x3 cannot be use with u8 ! Available matrix are mat4x2 or mat4x4 for u8”
§Thing to know
- Desc will not handle data transformation
- Desc does not handle chaotic structure