Macro vertex_struct

Source
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,
    ...
] }
  • $NAME is the name of your struct.
  • $STEP is either omitted or the word “step” followed by “Vertex” or “Instance” to set the VertexBufferLayout step_mode attribute.
  • $FIELD is the struct’s public field name.
  • $TYPE is the field’s VertexFormat.

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.