witchcraft_renderer/types/
model.rs1pub trait Vertex {
2 fn desc<'a>() -> wgpu::VertexBufferLayout<'a>;
3}
4
5#[repr(C)]
6#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
7pub struct ModelVertex {
8 position: [f32; 3],
9 tex_coords: [f32; 3],
10 normal: [f32; 3],
11}
12impl Vertex for ModelVertex {
13 fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
14 wgpu::VertexBufferLayout {
15 array_stride: std::mem::size_of::<ModelVertex>() as wgpu::BufferAddress,
16 step_mode: wgpu::VertexStepMode::Vertex,
17 attributes: &[
18 wgpu::VertexAttribute {
19 offset: 0,
20 shader_location: 0,
21 format: wgpu::VertexFormat::Float32x3,
22 },
23 wgpu::VertexAttribute {
24 offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
25 shader_location: 1,
26 format: wgpu::VertexFormat::Float32x3,
27 },
28 wgpu::VertexAttribute {
29 offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
30 shader_location: 2,
31 format: wgpu::VertexFormat::Float32x3,
32 },
33 ],
34 }
35 }
36}