2023-10-25 01:51:01 +00:00
|
|
|
#[derive(Clone)]
|
2023-10-25 03:22:30 +00:00
|
|
|
pub enum Instruction{
|
|
|
|
Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2),
|
2023-10-25 01:51:01 +00:00
|
|
|
//UpdateModel(crate::graphics::ModelUpdate),
|
2023-10-25 03:46:07 +00:00
|
|
|
Resize(winit::dpi::PhysicalSize<u32>,crate::settings::UserSettings),
|
2023-10-25 01:51:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//Ideally the graphics thread worker description is:
|
|
|
|
/*
|
|
|
|
WorkerDescription{
|
|
|
|
input:Immediate,
|
|
|
|
output:Realtime(PoolOrdering::Ordered(3)),
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
//up to three frames in flight, dropping new frame requests when all three are busy, and dropping output frames when one renders out of order
|
|
|
|
|
2023-10-25 03:46:07 +00:00
|
|
|
pub fn new<'a>(
|
2023-10-25 03:22:30 +00:00
|
|
|
mut graphics:crate::graphics::GraphicsState,
|
|
|
|
mut config:wgpu::SurfaceConfiguration,
|
|
|
|
surface:wgpu::Surface,
|
2023-10-25 03:46:07 +00:00
|
|
|
device:wgpu::Device,
|
|
|
|
queue:wgpu::Queue,
|
|
|
|
)->crate::compat_worker::INWorker<'a,Instruction>{
|
2023-10-25 03:22:30 +00:00
|
|
|
crate::compat_worker::INWorker::new(move |ins:Instruction|{
|
2023-10-25 01:51:01 +00:00
|
|
|
match ins{
|
2023-10-25 03:46:07 +00:00
|
|
|
Instruction::Resize(size,user_settings)=>{
|
2023-10-25 03:22:30 +00:00
|
|
|
config.width=size.width.max(1);
|
|
|
|
config.height=size.height.max(1);
|
2023-10-25 03:46:07 +00:00
|
|
|
surface.configure(&device,&config);
|
|
|
|
graphics.resize(&device,&config,&user_settings);
|
2023-10-25 03:22:30 +00:00
|
|
|
}
|
|
|
|
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
|
2023-10-25 01:51:01 +00:00
|
|
|
//this has to go deeper somehow
|
|
|
|
let frame=match surface.get_current_texture(){
|
|
|
|
Ok(frame)=>frame,
|
|
|
|
Err(_)=>{
|
2023-10-25 03:46:07 +00:00
|
|
|
surface.configure(&device,&config);
|
2023-10-25 01:51:01 +00:00
|
|
|
surface
|
|
|
|
.get_current_texture()
|
|
|
|
.expect("Failed to acquire next surface texture!")
|
|
|
|
}
|
|
|
|
};
|
|
|
|
let view=frame.texture.create_view(&wgpu::TextureViewDescriptor{
|
|
|
|
format:Some(config.view_formats[0]),
|
|
|
|
..wgpu::TextureViewDescriptor::default()
|
|
|
|
});
|
|
|
|
|
2023-10-25 03:46:07 +00:00
|
|
|
graphics.render(&view,&device,&queue,physics_output,predicted_time,mouse_pos);
|
2023-10-25 01:51:01 +00:00
|
|
|
|
|
|
|
frame.present();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|