strafe-client-jed/src/graphics_worker.rs

53 lines
1.5 KiB
Rust
Raw Normal View History

#[derive(Clone)]
2023-10-25 03:22:30 +00:00
pub enum Instruction{
Render(crate::physics::PhysicsOutputState,crate::integer::Time,glam::IVec2),
//UpdateModel(crate::graphics::ModelUpdate),
2023-10-25 03:22:30 +00:00
Resize(winit::dpi::PhysicalSize<u32>),
}
//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
pub fn new(
2023-10-25 03:22:30 +00:00
mut graphics:crate::graphics::GraphicsState,
mut config:wgpu::SurfaceConfiguration,
surface:wgpu::Surface,
device:&wgpu::Device,
queue:&wgpu::Queue,
2023-10-25 03:22:30 +00:00
)->crate::compat_worker::INWorker<Instruction>{
crate::compat_worker::INWorker::new(move |ins:Instruction|{
match ins{
2023-10-25 03:22:30 +00:00
Instruction::Resize(size)=>{
config.width=size.width.max(1);
config.height=size.height.max(1);
surface.configure(device,&config);
}
Instruction::Render(physics_output,predicted_time,mouse_pos)=>{
//this has to go deeper somehow
let frame=match surface.get_current_texture(){
Ok(frame)=>frame,
Err(_)=>{
2023-10-25 03:22:30 +00:00
surface.configure(device,&config);
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:22:30 +00:00
graphics.render(&view,device,queue,physics_output,predicted_time,mouse_pos);
frame.present();
}
}
})
}