Give render context ownership of window

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

View File

@ -1,6 +1,7 @@
use winit::{dpi::PhysicalSize, window::Window};
pub struct Context {
pub window: Window,
pub instance: wgpu::Instance,
pub size: PhysicalSize<u32>,
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,

View File

@ -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: