Give render context ownership of window
This commit is contained in:
parent
1a92b52630
commit
0dd7bbd37e
|
@ -1,6 +1,7 @@
|
||||||
use winit::{dpi::PhysicalSize, window::Window};
|
use winit::{dpi::PhysicalSize, window::Window};
|
||||||
|
|
||||||
pub struct Context {
|
pub struct Context {
|
||||||
|
pub window: Window,
|
||||||
pub instance: wgpu::Instance,
|
pub instance: wgpu::Instance,
|
||||||
pub size: PhysicalSize<u32>,
|
pub size: PhysicalSize<u32>,
|
||||||
pub surface: wgpu::Surface,
|
pub surface: wgpu::Surface,
|
||||||
|
@ -11,7 +12,7 @@ pub struct Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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...");
|
log::info!("Initialising WGPU context...");
|
||||||
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
|
||||||
backends: wgpu::Backends::VULKAN,
|
backends: wgpu::Backends::VULKAN,
|
||||||
|
@ -57,6 +58,7 @@ impl Context {
|
||||||
surface.configure(&device, &surface_config);
|
surface.configure(&device, &surface_config);
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
window,
|
||||||
instance,
|
instance,
|
||||||
size,
|
size,
|
||||||
surface,
|
surface,
|
||||||
|
|
|
@ -15,13 +15,13 @@ pub async fn run() {
|
||||||
.build(&event_loop)
|
.build(&event_loop)
|
||||||
.unwrap();
|
.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_loop.run(move |event, _, control_flow| match event {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
ref event,
|
ref event,
|
||||||
window_id,
|
window_id,
|
||||||
} if window_id == window.id() => match event {
|
} if window_id == render_ctx.window.id() => match event {
|
||||||
WindowEvent::CloseRequested
|
WindowEvent::CloseRequested
|
||||||
| WindowEvent::KeyboardInput {
|
| WindowEvent::KeyboardInput {
|
||||||
input:
|
input:
|
||||||
|
|
Loading…
Reference in New Issue