fix many red underline

This commit is contained in:
Quaternions 2023-10-20 17:05:25 -07:00
parent 2e13d9b74e
commit d27187aa53

View File

@ -117,10 +117,10 @@ impl GraphicsContextPartial3{
let required_features=required_features(); let required_features=required_features();
// Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface. // Make sure we use the texture resolution limits from the adapter, so we can support images the size of the surface.
let needed_limits = required_limits().using_resolution(self.adapter.limits()); let needed_limits=required_limits().using_resolution(self.adapter.limits());
let trace_dir = std::env::var("WGPU_TRACE"); let trace_dir=std::env::var("WGPU_TRACE");
let (device, queue) = pollster::block_on(self.adapter let (device, queue)=pollster::block_on(self.adapter
.request_device( .request_device(
&wgpu::DeviceDescriptor { &wgpu::DeviceDescriptor {
label: None, label: None,
@ -149,10 +149,10 @@ struct GraphicsContextPartial4{
} }
impl GraphicsContextPartial4{ impl GraphicsContextPartial4{
fn configure_surface(self,size:&winit::dpi::PhysicalSize<u32>)->GraphicsContext{ fn configure_surface(self,size:&winit::dpi::PhysicalSize<u32>)->GraphicsContext{
let mut config = self.surface let mut config=self.surface
.get_default_config(&self.adapter, size.width, size.height) .get_default_config(&self.adapter, size.width, size.height)
.expect("Surface isn't supported by the adapter."); .expect("Surface isn't supported by the adapter.");
let surface_view_format = config.format.add_srgb_suffix(); let surface_view_format=config.format.add_srgb_suffix();
config.view_formats.push(surface_view_format); config.view_formats.push(surface_view_format);
self.surface.configure(&self.device, &config); self.surface.configure(&self.device, &config);
@ -198,37 +198,41 @@ pub fn setup(title:&str)->GraphicsContextSetup{
} }
struct GraphicsContextSetup{ struct GraphicsContextSetup{
window: winit::window::Window, window:winit::window::Window,
event_loop:winit::event_loop::EventLoop<()>, event_loop:winit::event_loop::EventLoop<()>,
partial_graphics_context:crate::graphics_context::GraphicsContextPartial4, partial_graphics_context:GraphicsContextPartial4,
} }
impl GraphicsContextSetup{ impl GraphicsContextSetup{
pub fn start(self){ fn into_split(self)->(winit::window::Window,winit::event_loop::EventLoop<()>,GraphicsContext){
let size = self.window.inner_size(); let size=self.window.inner_size();
//Steal values and drop self
let graphics_context=self.partial_graphics_context.configure_surface(&size); (
self.window,
println!("Initializing global state..."); self.event_loop,
let mut example=GlobalState::init(); self.partial_graphics_context.configure_surface(&size),
)
}
pub fn start(self,mut global_state:crate::GlobalState){
let (window,event_loop,graphics_context)=self.into_split();
println!("Entering render loop..."); println!("Entering render loop...");
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event,_,control_flow|{
let _ = (&instance, &adapter); // force ownership by the closure //let _=(&instance, &adapter); // force ownership by the closure
*control_flow = if cfg!(feature = "metal-auto-capture") { *control_flow=if cfg!(feature="metal-auto-capture"){
ControlFlow::Exit winit::event_loop::ControlFlow::Exit
} else { }else{
ControlFlow::Poll winit::event_loop::ControlFlow::Poll
}; };
match event { match event{
event::Event::RedrawEventsCleared => { winit::event::Event::RedrawEventsCleared=>{
window.request_redraw(); window.request_redraw();
} }
event::Event::WindowEvent { winit::event::Event::WindowEvent {
event: event:
WindowEvent::Resized(size) winit::event::WindowEvent::Resized(size)
| WindowEvent::ScaleFactorChanged { | winit::event::WindowEvent::ScaleFactorChanged {
new_inner_size: &mut size, new_inner_size:&mut size,
.. ..
}, },
.. ..
@ -236,76 +240,75 @@ impl GraphicsContextSetup{
// Once winit is fixed, the detection conditions here can be removed. // Once winit is fixed, the detection conditions here can be removed.
// https://github.com/rust-windowing/winit/issues/2876 // https://github.com/rust-windowing/winit/issues/2876
// this has been fixed if I update winit (remove the if statement and only use the else case) // this has been fixed if I update winit (remove the if statement and only use the else case)
let max_dimension = adapter.limits().max_texture_dimension_2d; let max_dimension=graphics_context.adapter.limits().max_texture_dimension_2d;
if size.width > max_dimension || size.height > max_dimension { if max_dimension<size.width||max_dimension<size.height{
println!( println!(
"The resizing size {:?} exceeds the limit of {}.", "The resizing size {:?} exceeds the limit of {}.",
size, size,
max_dimension max_dimension
); );
} else { }else{
println!("Resizing to {:?}", size); println!("Resizing to {:?}",size);
config.width = size.width.max(1); graphics_context.config.width=size.width.max(1);
config.height = size.height.max(1); graphics_context.config.height=size.height.max(1);
example.resize(&config, &device, &queue); example.resize(&graphics_context.config, &graphics_context.device,&graphics_context.queue);
surface.configure(&device, &config); graphics_context.surface.configure(&graphics_context.device,&graphics_context.config);
} }
} }
event::Event::WindowEvent { event, .. } => match event { winit::event::Event::WindowEvent{event,..}=>match event{
WindowEvent::KeyboardInput { winit::event::WindowEvent::KeyboardInput{
input: input:
event::KeyboardInput { winit::event::KeyboardInput{
virtual_keycode: Some(event::VirtualKeyCode::Escape), virtual_keycode:Some(winit::event::VirtualKeyCode::Escape),
state: event::ElementState::Pressed, state: winit::event::ElementState::Pressed,
.. ..
}, },
.. ..
} }
| WindowEvent::CloseRequested => { |winit::event::WindowEvent::CloseRequested=>{
*control_flow = ControlFlow::Exit; *control_flow=winit::event_loop::ControlFlow::Exit;
} }
WindowEvent::KeyboardInput { winit::event::WindowEvent::KeyboardInput{
input: input:
event::KeyboardInput { winit::event::KeyboardInput{
virtual_keycode: Some(event::VirtualKeyCode::Scroll), virtual_keycode:Some(winit::event::VirtualKeyCode::Scroll),
state: event::ElementState::Pressed, state: winit::event::ElementState::Pressed,
.. ..
}, },
.. ..
} => { }=>{
println!("{:#?}", instance.generate_report()); println!("{:#?}",graphics_context.instance.generate_report());
} }
_ => { _=>{
example.update(&window,&device,&queue,event); example.update(&window,&graphics_context.device,&graphics_context.queue,event);
} }
}, },
event::Event::DeviceEvent { winit::event::Event::DeviceEvent{
event, event,
.. ..
} => { } => {
example.device_event(&window,event); example.device_event(&window,event);
}, },
event::Event::RedrawRequested(_) => { winit::event::Event::RedrawRequested(_)=>{
let frame=match graphics_context.surface.get_current_texture(){
let frame = match surface.get_current_texture() { Ok(frame)=>frame,
Ok(frame) => frame, Err(_)=>{
Err(_) => { graphics_context.surface.configure(&graphics_context.device,&graphics_context.config);
surface.configure(&device, &config); graphics_context.surface
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(surface_view_format), format:Some(graphics_context.config.view_formats[0]),
..wgpu::TextureViewDescriptor::default() ..wgpu::TextureViewDescriptor::default()
}); });
example.render(&view, &device, &queue); example.render(&view,&graphics_context.device,&graphics_context.queue);
frame.present(); frame.present();
} }
_ => {} _=>{}
} }
}); });
} }