Don't draw when window size is minimized

This commit is contained in:
João Capucho 2021-06-04 22:05:47 +01:00
parent 36c28af46d
commit b647cd35f1
No known key found for this signature in database
GPG Key ID: 1AD5CE7CCAEBDA21

View File

@ -135,6 +135,10 @@ pub struct Renderer {
profiler: wgpu_profiler::GpuProfiler,
profile_times: Vec<wgpu_profiler::GpuTimerScopeResult>,
profiler_features_enabled: bool,
// This checks is added because windows resizes the window to 0,0 when
// minimizing and this causes a bunch of validation errors
is_minimized: bool,
}
impl Renderer {
@ -391,6 +395,8 @@ impl Renderer {
profiler,
profile_times: Vec::new(),
profiler_features_enabled,
is_minimized: false,
})
}
@ -481,6 +487,7 @@ impl Renderer {
pub fn on_resize(&mut self, dims: Vec2<u32>) -> Result<(), RenderError> {
// Avoid panics when creating texture with w,h of 0,0.
if dims.x != 0 && dims.y != 0 {
self.is_minimized = false;
// Resize swap chain
self.resolution = dims;
self.sc_desc.width = dims.x;
@ -547,6 +554,8 @@ impl Renderer {
},
}
}
} else {
self.is_minimized = true;
}
Ok(())
@ -723,6 +732,10 @@ impl Renderer {
"Renderer::start_recording_frame"
);
if self.is_minimized {
return Ok(None);
}
// Try to get the latest profiling results
if self.mode.profiler_enabled {
// Note: this lags a few frames behind