From 0dd7bbd37efe6d400caadba05973e8eed7926366 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sat, 14 Oct 2023 10:00:56 +0100 Subject: [PATCH] Give render context ownership of window --- src/gfx/context.rs | 4 +++- src/main.rs | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/gfx/context.rs b/src/gfx/context.rs index 817a01e..3e8b6c6 100644 --- a/src/gfx/context.rs +++ b/src/gfx/context.rs @@ -1,6 +1,7 @@ use winit::{dpi::PhysicalSize, window::Window}; pub struct Context { + pub window: Window, pub instance: wgpu::Instance, pub size: PhysicalSize, pub surface: wgpu::Surface, @@ -11,7 +12,7 @@ pub struct Context { } impl Context { - pub async fn new(window: &Window, limits: wgpu::Limits) -> Self { + pub async fn new(window: Window, limits: wgpu::Limits) -> Self { log::info!("Initialising WGPU context..."); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: wgpu::Backends::VULKAN, @@ -57,6 +58,7 @@ impl Context { surface.configure(&device, &surface_config); Self { + window, instance, size, surface, diff --git a/src/main.rs b/src/main.rs index d6e1d1a..e042f1f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,13 +15,13 @@ pub async fn run() { .build(&event_loop) .unwrap(); - let mut 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 { ref event, window_id, - } if window_id == window.id() => match event { + } if window_id == render_ctx.window.id() => match event { WindowEvent::CloseRequested | WindowEvent::KeyboardInput { input: