macro_rules! vertex_struct {
{ $struct:ident [
$( $num:tt $field:ident => $attr:ident ),* $(,)?
] } => { ... };
{ $struct:ident step $step:ident [
$( $num:tt $field:ident => $attr:ident ),* $(,)?
] } => { ... };
}Expand description
Declare a vertex struct (to use in a vertex buffer).
vertex_struct! { $NAME $STEP [
0 $FIELD => $TYPE,
1 $FIELD => $TYPE,
2 $FIELD => $TYPE,
...
] }$NAMEis the name of your struct.$STEPis either omitted or the word “step” followed by “Vertex” or “Instance” to set theVertexBufferLayoutstep_modeattribute.$FIELDis the struct’s public field name.$TYPEis the field’sVertexFormat.
Note that fields must be numbered correctly, starting from 0. This is because I don’t know how to teach macros how to count.
Also, the fields are not rearranged to be optimized to their alignment rules, though they should be padded correctly.