From ef1dab01155f40e5c8499e63f8fff20c5f0d182f Mon Sep 17 00:00:00 2001 From: Till Date: Sun, 28 Jul 2019 23:27:25 +0200 Subject: [PATCH] moved mesh buffers into data object --- config/input.toml | 5 ++++- src/main.rs | 2 +- src/vulkan.rs | 12 ++++++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/config/input.toml b/config/input.toml index f541a2a..e9cff7b 100644 --- a/config/input.toml +++ b/config/input.toml @@ -10,7 +10,6 @@ ctrl = true [[button]] name = "print_framerate" scan_code = 33 -crtl = true [[button]] name = "w" @@ -33,6 +32,10 @@ name = "move_forward" positive_button = "w" negative_button = "s" +[[axis]] +name = "move_forward" +mouse_axis = "wheel" + [[axis]] name = "move_sideways" positive_button = "d" diff --git a/src/main.rs b/src/main.rs index 9c784fd..009e8c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ impl Game for TestGame<'_> { game_data.recreate_pipeline = true; } - if self.input.button_down("print_framerate") { + if self.input.button_just_pressed("print_framerate") { println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time); } diff --git a/src/vulkan.rs b/src/vulkan.rs index 6906f38..9d14d00 100644 --- a/src/vulkan.rs +++ b/src/vulkan.rs @@ -72,6 +72,8 @@ pub struct GameData { pub recreate_pipeline: bool, pub dimensions: [u32; 2], pub shutdown: bool, + mesh_vertex_buffer: Option>>, + mesh_index_buffer: Option>>, } pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) { @@ -92,7 +94,9 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) recreate_pipeline: false, shutdown: false, line_vertices, - dimensions: [0, 0] + dimensions: [0, 0], + mesh_vertex_buffer: None, + mesh_index_buffer: None, }; if game.validation_layers_enabled() { @@ -206,8 +210,8 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) }; let (mesh_vertices, mesh_indices) = load_mesh(mesh_path); - let mesh_vertex_buffer = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::vertex_buffer(), mesh_vertices.into_iter()).unwrap(); - let mesh_index_buffer = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::index_buffer(), mesh_indices.into_iter()).unwrap(); + data.mesh_vertex_buffer = Some(CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::vertex_buffer(), mesh_vertices.into_iter()).unwrap()); + data.mesh_index_buffer = Some(CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::index_buffer(), mesh_indices.into_iter()).unwrap()); let line_vertex_buffer = CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::vertex_buffer(), data.line_vertices.iter().cloned()).unwrap(); let render_pass = Arc::new(vulkano::single_pass_renderpass!( @@ -324,7 +328,7 @@ pub fn init(mesh_path: &str, line_vertices: Vec, game: &mut dyn Game) .begin_render_pass(framebuffers[image_num].clone(), false, vec![[0.0, 0.0, 0.0, 1.0].into(), ClearValue::Depth(1.0)]).unwrap() // We are now inside the first subpass of the render pass. We add a draw command. - .draw_indexed(pipeline.clone(), &dynamic_state, mesh_vertex_buffer.clone(), mesh_index_buffer.clone(), (), data.push_constants.clone()).unwrap() + .draw_indexed(pipeline.clone(), &dynamic_state, data.mesh_vertex_buffer.clone().unwrap(), data.mesh_index_buffer.clone().unwrap(), (), data.push_constants.clone()).unwrap() .draw(line_pipeline.clone(), &dynamic_state, line_vertex_buffer.clone(), (), data.line_push_constants.clone()).unwrap() // We leave the render pass by calling `draw_end`. Note that if we had multiple