This commit is contained in:
2019-08-01 17:21:37 +02:00
parent cbf26b3045
commit c582af5138
2 changed files with 7 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ impl TestGame {
fn update(self: &mut Self, renderer: &mut VulkanRenderer) {
self.input.frame_start();
let new_time = renderer.game_data.start_time.elapsed().unwrap().as_millis() as f32 / 1000.0;
let new_time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32;
let frame_time = new_time - renderer.game_data.push_constants.time;
renderer.game_data.push_constants.time = new_time;
@@ -49,7 +49,7 @@ impl TestGame {
renderer.game_data.recreate_pipeline = true;
}
if self.input.button_just_pressed("print_framerate") {
if self.input.button_down("print_framerate") {
println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time);
}

View File

@@ -314,7 +314,10 @@ impl VulkanRenderer {
Ok(r) => r,
// This error tends to happen when the user is manually resizing the window.
// Simply restarting the loop is the easiest way to fix this issue.
Err(SwapchainCreationError::UnsupportedDimensions) => return RenderLoopResult::Reload,
Err(SwapchainCreationError::UnsupportedDimensions) => {
println!("Swapchain rejected: UnsupportedDimensions");
return RenderLoopResult::Reload;
}
Err(err) => panic!("{:?}", err),
};
@@ -353,13 +356,8 @@ impl VulkanRenderer {
};
let mut cbb = AutoCommandBufferBuilder::primary_one_time_submit(self.device.clone(), self.queue.family()).unwrap()
// Before we can draw, we have to *enter a render pass*. There are two methods to do
// this: `draw_inline` and `draw_secondary`. The latter is a bit more advanced and is
// not covered here.
.begin_render_pass(self.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
for i in 0..self.game_data.game_objects.len() {
let game_object = &self.game_data.game_objects[i];
let mesh = &self.game_data.meshes[game_object.mesh_index];
@@ -371,10 +369,6 @@ impl VulkanRenderer {
}
cbb = cbb.draw(self.line_pipeline.clone(), &self.dynamic_state, vec![self.line_vertex_buffer.clone()], (), self.game_data.line_push_constants.clone()).unwrap()
// We leave the render pass by calling `draw_end`. Note that if we had multiple
// subpasses we could have called `next_inline` (or `next_secondary`) to jump to the
// next subpass.
.end_render_pass().unwrap();
let command_buffer = cbb.build().unwrap();
@@ -389,6 +383,7 @@ impl VulkanRenderer {
self.previous_frame_end = Some(Box::new(future) as Box<_>);
},
Err(FlushError::OutOfDate) => {
println!("Swapchain out of date!");
self.recreate_swapchain = true;
self.previous_frame_end = Some(Box::new(sync::now(self.device.clone())) as Box<_>);
}