diff --git a/src/main.rs b/src/main.rs index c89c044..d4d4982 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,10 @@ use winit::{ }; mod camera; +mod mesh; use camera::*; +use mesh::*; struct Renderer { pub device: wgpu::Device, @@ -20,6 +22,7 @@ struct Renderer { config: wgpu::SurfaceConfiguration, camera_uniform: CameraUniform, camera_buffer: wgpu::Buffer, + camera_bind_group: wgpu::BindGroup, meshes_buffer: wgpu::Buffer, meshes_bind_group: wgpu::BindGroup, @@ -233,6 +236,7 @@ impl Renderer { transform_ranges.push((*group_id, start_idx..end_idx)); } + // TODO persistent staging buffer (write_buffer creates a new one per call) self.queue.write_buffer( &self.meshes_buffer, 0, @@ -354,33 +358,6 @@ impl CameraUniform { } } -#[repr(C)] -#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] -struct Vertex { - position: [f32; 3], -} - -impl Vertex { - pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { - wgpu::VertexBufferLayout { - array_stride: std::mem::size_of::() as wgpu::BufferAddress, - step_mode: wgpu::VertexStepMode::Vertex, - attributes: &[wgpu::VertexAttribute { - offset: 0, - shader_location: 0, - format: wgpu::VertexFormat::Float32x3, - }], - } - } -} - -type Index = u32; - -struct MeshData { - vertices: Vec, - indices: Vec, -} - #[repr(C)] #[derive(Copy, Clone, Eq, Hash, PartialEq)] struct MeshHandle { @@ -400,8 +377,8 @@ type MeshCommands = Vec; fn load_model() -> MeshData { use tobj::*; - let mut model_data = include_bytes!("viking_room.obj").to_vec(); - let mut model_data = &mut model_data.as_slice(); + let model_data = include_bytes!("viking_room.obj").to_vec(); + let model_data = &mut model_data.as_slice(); let load_options = LoadOptions { triangulate: true, diff --git a/src/mesh.rs b/src/mesh.rs new file mode 100644 index 0000000..b3f91e6 --- /dev/null +++ b/src/mesh.rs @@ -0,0 +1,26 @@ +#[repr(C)] +#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)] +pub struct Vertex { + pub position: [f32; 3], +} + +impl Vertex { + pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> { + wgpu::VertexBufferLayout { + array_stride: std::mem::size_of::() as wgpu::BufferAddress, + step_mode: wgpu::VertexStepMode::Vertex, + attributes: &[wgpu::VertexAttribute { + offset: 0, + shader_location: 0, + format: wgpu::VertexFormat::Float32x3, + }], + } + } +} + +pub type Index = u32; + +pub struct MeshData { + pub vertices: Vec, + pub indices: Vec, +}