From 44831bd14ba30eb62bae3ca0e5bbc41e96a83c71 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Mon, 23 Oct 2023 19:01:45 -0700 Subject: [PATCH] don't forget config is transient --- src/graphics.rs | 17 +++++++++-------- src/run.rs | 23 +++++++++++++---------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/graphics.rs b/src/graphics.rs index 650bc31..b5abe05 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -527,11 +527,10 @@ impl GraphicsState{ println!("Graphics Instances: {}",instance_count); } - pub fn new( - config: &wgpu::SurfaceConfiguration, - _adapter: &wgpu::Adapter, - device: &wgpu::Device, - queue: &wgpu::Queue, + pub fn init( + device:&wgpu::Device, + queue:&wgpu::Queue, + config:&wgpu::SurfaceConfiguration, )->Self{ let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { label: None, @@ -876,10 +875,12 @@ impl GraphicsState{ } pub fn resize( &mut self, - context:&crate::graphics_context::GraphicsContext, + device:&wgpu::Device, + queue:&wgpu::Queue, + config:&wgpu::SurfaceConfiguration, ) { - self.depth_view = Self::create_depth_texture(&context.config,&context.device); - self.camera.screen_size=glam::uvec2(context.config.width, context.config.height); + self.depth_view = Self::create_depth_texture(config,device); + self.camera.screen_size=glam::uvec2(config.width, config.height); self.load_user_settings(&self.user_settings); } pub fn render( diff --git a/src/run.rs b/src/run.rs index 6c56ee3..c342b90 100644 --- a/src/run.rs +++ b/src/run.rs @@ -192,7 +192,10 @@ impl RunState { } } - pub fn into_worker(self,mut graphics_context:crate::graphics_context::GraphicsContext)->crate::worker::QNWorker>{ + pub fn into_worker(self,mut setup_context:crate::setup_context::SetupContext)->crate::worker::QNWorker>{ + //create child context + let physics_context=PhysicsContext::new(()); + // crate::worker::QNWorker::new(move |ins:TimedInstruction|{ match ins.instruction{ RunInstruction::WindowEvent(window_event)=>{ @@ -202,27 +205,27 @@ impl RunState { self.device_event(ins.time,device_event); }, RunInstruction::Resize(size)=>{ - graphics_context.config.width=size.width.max(1); - graphics_context.config.height=size.height.max(1); - self.graphics.resize(&graphics_context.device,&graphics_context.config); - graphics_context.surface.configure(&graphics_context.device,&graphics_context.config); + setup_context.config.width=size.width.max(1); + setup_context.config.height=size.height.max(1); + self.graphics.resize(&setup_context.device,&setup_context.config); + setup_context.surface.configure(&setup_context.device,&setup_context.config); } RunInstruction::Render=>{ - let frame=match graphics_context.surface.get_current_texture(){ + let frame=match setup_context.surface.get_current_texture(){ Ok(frame)=>frame, Err(_)=>{ - graphics_context.surface.configure(&graphics_context.device,&graphics_context.config); - graphics_context.surface + setup_context.surface.configure(&setup_context.device,&setup_context.config); + setup_context.surface .get_current_texture() .expect("Failed to acquire next surface texture!") } }; let view=frame.texture.create_view(&wgpu::TextureViewDescriptor{ - format:Some(graphics_context.config.view_formats[0]), + format:Some(setup_context.config.view_formats[0]), ..wgpu::TextureViewDescriptor::default() }); - self.graphics.render(&view,&graphics_context.device,&graphics_context.queue); + self.graphics.render(&view,&setup_context.device,&setup_context.queue); frame.present(); }