From ae298d8ca23649095864b1c52cf9964556490c59 Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Fri, 20 Oct 2023 11:04:59 +0100 Subject: [PATCH] Give render context ownership of the window --- src/core/app.rs | 10 ++++------ src/gfx/context.rs | 4 +++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/app.rs b/src/core/app.rs index 2f8b029..82cfeda 100644 --- a/src/core/app.rs +++ b/src/core/app.rs @@ -13,7 +13,6 @@ use crate::{ pub struct App { title: String, - window: winit::window::Window, event_loop: EventLoop<()>, render_ctx: gfx::Context, } @@ -30,7 +29,7 @@ impl App { .unwrap(); let render_ctx = gfx::Context::new( - &window, + window, wgpu::Limits { max_storage_buffer_binding_size: 1 << 30, max_buffer_size: 1 << 30, @@ -41,7 +40,6 @@ impl App { Self { title: title.to_owned(), - window, event_loop, render_ctx, } @@ -91,14 +89,14 @@ impl App { Event::WindowEvent { ref event, window_id, - } if window_id == self.window.id() => match event { + } if window_id == self.render_ctx.window.id() => match event { WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, _ => { camera_controller.process_events(event); } }, Event::MainEventsCleared => { - self.window.request_redraw(); + self.render_ctx.window.request_redraw(); } Event::RedrawRequested(_) => { let now = Instant::now(); @@ -111,7 +109,7 @@ impl App { renderer.update_brickmap(&self.render_ctx, &mut world); // Simple framerate tracking - self.window.set_title(&format!( + self.render_ctx.window.set_title(&format!( "{}: {} fps", self.title, (1.0 / dt.as_secs_f32()).floor() diff --git a/src/gfx/context.rs b/src/gfx/context.rs index 67d94c0..f10d8cc 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,