[rs] Update to latest winit (0.20.0-alpha6)

- `RedrawRequested` is now used for rendering
- `EventsCleared` replaced by `MainEventsCleared` which requests redraw
- Removed capture from hello-triangle to simplify it slightly
This commit is contained in:
Joshua Groves
2020-01-04 18:33:33 -03:30
parent f8f3c8daa3
commit aa623f842b
3 changed files with 17 additions and 30 deletions

View File

@@ -48,7 +48,7 @@ env_logger = "0.7"
glsl-to-spirv = "0.1"
log = "0.4"
png = "0.15"
winit = "0.20.0-alpha4"
winit = "0.20.0-alpha6"
rand = "0.7.2"
zerocopy = "0.2"
futures = "0.3"

View File

@@ -63,7 +63,7 @@ pub fn run<E: Example>(title: &str) {
log::info!("Initializing the window...");
#[cfg(not(feature = "gl"))]
let (_window, hidpi_factor, size, surface) = {
let (window, hidpi_factor, size, surface) = {
let window = winit::window::Window::new(&event_loop).unwrap();
window.set_title(title);
let hidpi_factor = window.hidpi_factor();
@@ -73,7 +73,7 @@ pub fn run<E: Example>(title: &str) {
};
#[cfg(feature = "gl")]
let (_window, instance, hidpi_factor, size, surface) = {
let (window, instance, hidpi_factor, size, surface) = {
let wb = winit::WindowBuilder::new();
let cb = wgpu::glutin::ContextBuilder::new().with_vsync(true);
let context = cb.build_windowed(wb, &event_loop).unwrap();
@@ -132,6 +132,7 @@ pub fn run<E: Example>(title: &str) {
ControlFlow::Poll
};
match event {
event::Event::MainEventsCleared => window.request_redraw(),
event::Event::WindowEvent {
event: WindowEvent::Resized(size),
..
@@ -162,15 +163,15 @@ pub fn run<E: Example>(title: &str) {
_ => {
example.update(event);
}
},
event::Event::EventsCleared => {
}
event::Event::RedrawRequested(_) => {
let frame = swap_chain
.get_next_texture()
.expect("Timeout when acquiring next swap chain texture");
let command_buf = example.render(&frame, &device);
queue.submit(&[command_buf]);
}
_ => (),
_ => {}
}
});
}

View File

@@ -8,7 +8,7 @@ fn main() {
let event_loop = EventLoop::new();
#[cfg(not(feature = "gl"))]
let (_window, size, surface) = {
let (window, size, surface) = {
let window = winit::window::Window::new(&event_loop).unwrap();
let size = window.inner_size().to_physical(window.hidpi_factor());
@@ -17,7 +17,7 @@ fn main() {
};
#[cfg(feature = "gl")]
let (_window, instance, size, surface) = {
let (window, instance, size, surface) = {
let wb = winit::WindowBuilder::new();
let cb = wgpu::glutin::ContextBuilder::new().with_vsync(true);
let context = cb.build_windowed(wb, &event_loop).unwrap();
@@ -113,28 +113,10 @@ fn main() {
);
event_loop.run(move |event, _, control_flow| {
*control_flow = if cfg!(feature = "metal-auto-capture") {
ControlFlow::Exit
} else {
ControlFlow::Poll
};
*control_flow = ControlFlow::Poll;
match event {
event::Event::WindowEvent { event, .. } => match event {
event::WindowEvent::KeyboardInput {
input:
event::KeyboardInput {
virtual_keycode: Some(event::VirtualKeyCode::Escape),
state: event::ElementState::Pressed,
..
},
..
}
| event::WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
_ => {}
},
event::Event::EventsCleared => {
event::Event::MainEventsCleared => window.request_redraw(),
event::Event::RedrawRequested(_) => {
let frame = swap_chain
.get_next_texture()
.expect("Timeout when acquiring next swap chain texture");
@@ -158,7 +140,11 @@ fn main() {
queue.submit(&[encoder.finish()]);
}
_ => (),
event::Event::WindowEvent {
event: event::WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
_ => {}
}
});
}