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);
}
pub fn new(
config: &wgpu::SurfaceConfiguration,
_adapter: &wgpu::Adapter,
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(

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>|{
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();
}