fix many red underline
This commit is contained in:
parent
2e13d9b74e
commit
d27187aa53
@ -200,34 +200,38 @@ 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,8 +240,8 @@ 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,
|
||||||
@ -245,63 +249,62 @@ impl GraphicsContextSetup{
|
|||||||
);
|
);
|
||||||
}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(_)=>{
|
||||||
surface.configure(&device, &config);
|
graphics_context.surface.configure(&graphics_context.device,&graphics_context.config);
|
||||||
surface
|
graphics_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(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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user