don't forget config is transient

This commit is contained in:
Quaternions 2023-10-23 19:01:45 -07:00
parent 099915c980
commit 44831bd14b
2 changed files with 22 additions and 18 deletions

View File

@ -527,11 +527,10 @@ impl GraphicsState{
println!("Graphics Instances: {}",instance_count); println!("Graphics Instances: {}",instance_count);
} }
pub fn new( pub fn init(
config: &wgpu::SurfaceConfiguration, device:&wgpu::Device,
_adapter: &wgpu::Adapter, queue:&wgpu::Queue,
device: &wgpu::Device, config:&wgpu::SurfaceConfiguration,
queue: &wgpu::Queue,
)->Self{ )->Self{
let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor { let camera_bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: None, label: None,
@ -876,10 +875,12 @@ impl GraphicsState{
} }
pub fn resize( pub fn resize(
&mut self, &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.depth_view = Self::create_depth_texture(config,device);
self.camera.screen_size=glam::uvec2(context.config.width, context.config.height); self.camera.screen_size=glam::uvec2(config.width, config.height);
self.load_user_settings(&self.user_settings); self.load_user_settings(&self.user_settings);
} }
pub fn render( pub fn render(

View File

@ -192,7 +192,10 @@ impl RunState {
} }
} }
pub fn into_worker(self,mut graphics_context:crate::graphics_context::GraphicsContext)->crate::worker::QNWorker<TimedInstruction<RunInstruction>>{ pub fn into_worker(self,mut setup_context:crate::setup_context::SetupContext)->crate::worker::QNWorker<TimedInstruction<RunInstruction>>{
//create child context
let physics_context=PhysicsContext::new(());
//
crate::worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{ crate::worker::QNWorker::new(move |ins:TimedInstruction<RunInstruction>|{
match ins.instruction{ match ins.instruction{
RunInstruction::WindowEvent(window_event)=>{ RunInstruction::WindowEvent(window_event)=>{
@ -202,27 +205,27 @@ impl RunState {
self.device_event(ins.time,device_event); self.device_event(ins.time,device_event);
}, },
RunInstruction::Resize(size)=>{ RunInstruction::Resize(size)=>{
graphics_context.config.width=size.width.max(1); setup_context.config.width=size.width.max(1);
graphics_context.config.height=size.height.max(1); setup_context.config.height=size.height.max(1);
self.graphics.resize(&graphics_context.device,&graphics_context.config); self.graphics.resize(&setup_context.device,&setup_context.config);
graphics_context.surface.configure(&graphics_context.device,&graphics_context.config); setup_context.surface.configure(&setup_context.device,&setup_context.config);
} }
RunInstruction::Render=>{ RunInstruction::Render=>{
let frame=match graphics_context.surface.get_current_texture(){ let frame=match setup_context.surface.get_current_texture(){
Ok(frame)=>frame, Ok(frame)=>frame,
Err(_)=>{ Err(_)=>{
graphics_context.surface.configure(&graphics_context.device,&graphics_context.config); setup_context.surface.configure(&setup_context.device,&setup_context.config);
graphics_context.surface setup_context.surface
.get_current_texture() .get_current_texture()
.expect("Failed to acquire next surface texture!") .expect("Failed to acquire next surface texture!")
} }
}; };
let view=frame.texture.create_view(&wgpu::TextureViewDescriptor{ 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() ..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(); frame.present();
} }