macro_rules! vertex_attr_array {
($($location:expr => $format:ident),* $(,)?) => { ... };
}
Expand description
Macro to produce an array of VertexAttribute
.
The input is a sequence of pairs of shader locations (expression of type u32
) and
variant names of VertexFormat
.
The return value has type [VertexAttribute; N]
, where N
is the number of inputs.
Offsets are calculated automatically, using the assumption that there is no padding or other data between attributes.
§Example
// Suppose that this is our vertex format:
#[repr(C, packed)]
struct Vertex {
foo: [f32; 2],
bar: f32,
baz: [u16; 4],
}
// Then these attributes match it:
let attrs = wgpu::vertex_attr_array![
0 => Float32x2,
1 => Float32,
2 => Uint16x4,
];
// Here's the full data structure the macro produced:
use wgpu::{VertexAttribute as A, VertexFormat as F};
assert_eq!(attrs, [
A { format: F::Float32x2, offset: 0, shader_location: 0, },
A { format: F::Float32, offset: 8, shader_location: 1, },
A { format: F::Uint16x4, offset: 12, shader_location: 2, },
]);
See VertexBufferLayout
for an example building on this one.