moved mesh buffers into data object
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -72,6 +72,8 @@ pub struct GameData {
|
||||
pub recreate_pipeline: bool,
|
||||
pub dimensions: [u32; 2],
|
||||
pub shutdown: bool,
|
||||
mesh_vertex_buffer: Option<Arc<CpuAccessibleBuffer<[Vertex]>>>,
|
||||
mesh_index_buffer: Option<Arc<CpuAccessibleBuffer<[u32]>>>,
|
||||
}
|
||||
|
||||
pub fn init(mesh_path: &str, line_vertices: Vec<LinePoint>, game: &mut dyn Game) {
|
||||
@@ -92,7 +94,9 @@ pub fn init(mesh_path: &str, line_vertices: Vec<LinePoint>, 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<LinePoint>, 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<LinePoint>, 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
|
||||
|
||||
Reference in New Issue
Block a user