diff --git a/src/gfx/context.rs b/src/gfx/context.rs index 67d94c0..817a01e 100644 --- a/src/gfx/context.rs +++ b/src/gfx/context.rs @@ -66,4 +66,13 @@ impl Context { queue, } } + + pub fn resize(&mut self, new_size: PhysicalSize) { + 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); + } + } } diff --git a/src/main.rs b/src/main.rs index f3c6417..d6e1d1a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); + } _ => {} }, _ => {}