diff --git a/src/gfx/context.rs b/src/gfx/context.rs index 2b67363..63ecb51 100644 --- a/src/gfx/context.rs +++ b/src/gfx/context.rs @@ -1,21 +1,24 @@ +use std::sync::Arc; + use anyhow::Result; + use winit::{ dpi::PhysicalSize, event::WindowEvent, event_loop::EventLoopWindowTarget, window::Window, }; -pub struct Context<'w> { - pub window: &'w Window, +pub struct Context<'window> { + pub window: Arc, pub instance: wgpu::Instance, pub size: PhysicalSize, - pub surface: wgpu::Surface<'w>, + pub surface: wgpu::Surface<'window>, pub surface_config: wgpu::SurfaceConfiguration, pub adapter: wgpu::Adapter, pub device: wgpu::Device, pub queue: wgpu::Queue, } -impl<'w> Context<'w> { - pub async fn new(window: &'w Window, limits: wgpu::Limits) -> Result { +impl<'window> Context<'window> { + pub async fn new(window: Arc, limits: wgpu::Limits) -> Result { log::info!("Initialising WGPU context..."); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends: wgpu::Backends::VULKAN, @@ -28,7 +31,7 @@ impl<'w> Context<'w> { // - A GPU device to draw to the surface // - A draw command queue log::info!("Initialising window surface..."); - let surface = instance.create_surface(window)?; + let surface = instance.create_surface(window.clone())?; log::info!("Requesting GPU adapter..."); let adapter = instance diff --git a/src/main.rs b/src/main.rs index ce00b33..262ab75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,8 @@ mod gfx; mod input; mod scripting; +use std::sync::Arc; + use anyhow::Result; use gfx::Context; use input::Input; @@ -18,7 +20,7 @@ pub fn main() -> Result<()> { env_logger::init(); let (event_loop, window) = make_window()?; - let context = pollster::block_on(Context::new(&window, Limits::default()))?; + let context = pollster::block_on(Context::new(Arc::new(window), Limits::default()))?; run(event_loop, context)?; Ok(())