Add context surface resizing

This commit is contained in:
Jarrod Doyle 2023-10-14 09:56:55 +01:00
parent ba301451af
commit 1a92b52630
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
2 changed files with 16 additions and 1 deletions

View File

@ -66,4 +66,13 @@ impl Context {
queue,
}
}
pub fn resize(&mut self, new_size: PhysicalSize<u32>) {
if new_size.width > 0 && new_size.height > 0 {
self.size = new_size;
self.surface_config.width = new_size.width;
self.surface_config.height = new_size.height;
self.surface.configure(&self.device, &self.surface_config);
}
}
}

View File

@ -15,7 +15,7 @@ pub async fn run() {
.build(&event_loop)
.unwrap();
let render_ctx = gfx::Context::new(&window, wgpu::Limits::default()).await;
let mut render_ctx = gfx::Context::new(&window, wgpu::Limits::default()).await;
event_loop.run(move |event, _, control_flow| match event {
Event::WindowEvent {
@ -32,6 +32,12 @@ pub async fn run() {
},
..
} => *control_flow = ControlFlow::Exit,
WindowEvent::Resized(physical_size) => {
render_ctx.resize(*physical_size);
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
render_ctx.resize(**new_inner_size);
}
_ => {}
},
_ => {}