Give render context ownership of the window
This commit is contained in:
parent
08e819a938
commit
ae298d8ca2
|
@ -13,7 +13,6 @@ use crate::{
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
title: String,
|
title: String,
|
||||||
window: winit::window::Window,
|
|
||||||
event_loop: EventLoop<()>,
|
event_loop: EventLoop<()>,
|
||||||
render_ctx: gfx::Context,
|
render_ctx: gfx::Context,
|
||||||
}
|
}
|
||||||
|
@ -30,7 +29,7 @@ impl App {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let render_ctx = gfx::Context::new(
|
let render_ctx = gfx::Context::new(
|
||||||
&window,
|
window,
|
||||||
wgpu::Limits {
|
wgpu::Limits {
|
||||||
max_storage_buffer_binding_size: 1 << 30,
|
max_storage_buffer_binding_size: 1 << 30,
|
||||||
max_buffer_size: 1 << 30,
|
max_buffer_size: 1 << 30,
|
||||||
|
@ -41,7 +40,6 @@ impl App {
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
title: title.to_owned(),
|
title: title.to_owned(),
|
||||||
window,
|
|
||||||
event_loop,
|
event_loop,
|
||||||
render_ctx,
|
render_ctx,
|
||||||
}
|
}
|
||||||
|
@ -91,14 +89,14 @@ impl App {
|
||||||
Event::WindowEvent {
|
Event::WindowEvent {
|
||||||
ref event,
|
ref event,
|
||||||
window_id,
|
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,
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
||||||
_ => {
|
_ => {
|
||||||
camera_controller.process_events(event);
|
camera_controller.process_events(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Event::MainEventsCleared => {
|
Event::MainEventsCleared => {
|
||||||
self.window.request_redraw();
|
self.render_ctx.window.request_redraw();
|
||||||
}
|
}
|
||||||
Event::RedrawRequested(_) => {
|
Event::RedrawRequested(_) => {
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
|
@ -111,7 +109,7 @@ impl App {
|
||||||
renderer.update_brickmap(&self.render_ctx, &mut world);
|
renderer.update_brickmap(&self.render_ctx, &mut world);
|
||||||
|
|
||||||
// Simple framerate tracking
|
// Simple framerate tracking
|
||||||
self.window.set_title(&format!(
|
self.render_ctx.window.set_title(&format!(
|
||||||
"{}: {} fps",
|
"{}: {} fps",
|
||||||
self.title,
|
self.title,
|
||||||
(1.0 / dt.as_secs_f32()).floor()
|
(1.0 / dt.as_secs_f32()).floor()
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue