#[derive(VertexLayout)]
{
// Attributes available to this derive:
#[layout]
}
Expand description
Allows for generation of a wgpu::VertexBufferLayout
, which can be accessed
by the LAYOUT
constant on the macro.
#[derive(VertexLayout)]
struct Vertex {
position: [f32; 3],
tex_coords: [f32; 2],
}
fn main() {
Vertex::LAYOUT; // use in a RenderPipelineDescriptor
}
§Changing step_mode
By default, the step_mode
is set to Vertex
.
To change the step_mode
for the VertexBufferLayout
, you can declare the
layout
attribute macro for the struct, and passing one of the variants
of wgpu::VertexStepMode
.
#[derive(VertexLayout)]
#[layout(Instance)]
struct Vertex {}
§Using norm
Variants
By specifying norm
the layout
attribute macro for the field you want,
it will use the norm
variant corresponding to the field value.
#[derive(VertexLayout)]
struct Vertex {
#[layout(norm)]
tex_coords: [u8; 2],
}
So Uint8x2
becomes Unorm8x2
.
§Overriding Generated VertexFormat
By specifying the wanted VertexFormat
in the layout
attribute macro for
the field you want, you can override the generated VertexFormat
.
#[derive(VertexLayout)]
struct Vertex {
#[layout(Uint16x4)]
tex_coords: [f32; 2],
}