Skip to content

Commit

Permalink
Merge pull request #2084 from est31/update_glutin_031
Browse files Browse the repository at this point in the history
Update glutin to 0.31
  • Loading branch information
est31 committed Nov 2, 2023
2 parents e73d401 + ee6c22e commit 77f48cd
Show file tree
Hide file tree
Showing 25 changed files with 542 additions and 491 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ vk_interop = [] # used for texture import from Vulkan
simple_window_builder = ["glutin", "glutin-winit", "winit", "raw-window-handle"] # used in the tutorial

[dependencies.glutin]
version = "0.30.4"
version = "0.31"
features = []
optional = true
default-features = false

[dependencies.glutin-winit]
version = "0.3"
version = "0.4"
features = []
optional = true
default-features = false

[dependencies.winit]
version = "0.28"
version = "0.29"
features = []
optional = true
default-features = false
Expand Down Expand Up @@ -76,9 +76,9 @@ image = "0.24"
obj = { version = "0.10", features = ["genmesh"] }
rand = "0.8"
libc = "0.2.62"
winit = "0.28"
winit = "0.29"
raw-window-handle = "0.5"
glutin-winit = "0.3"
glutin-winit = "0.4"

[package.metadata.docs.rs]
all-features = true
8 changes: 4 additions & 4 deletions examples/fullscreen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use glium::index::PrimitiveType;
use glium::{Display, Frame, Surface};
use glutin::surface::WindowSurface;
use support::{ApplicationContext, State};
use winit::{event::VirtualKeyCode, window::Fullscreen};
use winit::{window::Fullscreen, keyboard::{PhysicalKey, KeyCode}};

mod support;

Expand Down Expand Up @@ -125,9 +125,9 @@ impl ApplicationContext for Application {

fn handle_window_event(&mut self, event: &winit::event::WindowEvent, window: &winit::window::Window) {
match event {
winit::event::WindowEvent::KeyboardInput { input, .. } => match input.state {
winit::event::ElementState::Pressed => match input.virtual_keycode {
Some(VirtualKeyCode::Return) => {
winit::event::WindowEvent::KeyboardInput { event, .. } => match event.state {
winit::event::ElementState::Pressed => match event.physical_key {
PhysicalKey::Code(KeyCode::Enter) => {
self.toggle_fullscreen(window);
}
_ => (),
Expand Down
7 changes: 4 additions & 3 deletions examples/fxaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{cell::RefCell};
use glium::{Display, Surface, framebuffer::SimpleFrameBuffer};
use glutin::surface::WindowSurface;
use support::{ApplicationContext, State};
use winit::keyboard::{PhysicalKey, KeyCode};

mod support;

Expand Down Expand Up @@ -278,9 +279,9 @@ impl ApplicationContext for Application {
self.camera.process_input(&event);

match event {
winit::event::WindowEvent::KeyboardInput { input, .. } => match input.state {
winit::event::ElementState::Pressed => match input.virtual_keycode {
Some(winit::event::VirtualKeyCode::Space) => {
winit::event::WindowEvent::KeyboardInput { event, .. } => match event.state {
winit::event::ElementState::Pressed => match event.physical_key {
PhysicalKey::Code(KeyCode::Space) => {
self.fxaa_enabled = !self.fxaa_enabled;
println!("FXAA is now {}", if self.fxaa_enabled { "enabled" } else { "disabled" });
},
Expand Down
17 changes: 10 additions & 7 deletions examples/manual-creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ use std::num::NonZeroU32;
use std::os::raw::c_void;

fn main() {
let event_loop = EventLoopBuilder::new().build();
let event_loop = EventLoopBuilder::new()
.build()
.expect("event loop building");
let window_builder = WindowBuilder::new();
let config_template_builder = ConfigTemplateBuilder::new();
let display_builder = DisplayBuilder::new().with_window_builder(Some(window_builder));
Expand Down Expand Up @@ -155,13 +157,14 @@ fn main() {
target.finish().unwrap();

// the window is still available
event_loop.run(|event, _, control_flow| {
*control_flow = match event {
event_loop.run(|event, window_target| {
match event {
winit::event::Event::WindowEvent { event, .. } => match event {
winit::event::WindowEvent::CloseRequested => winit::event_loop::ControlFlow::Exit,
_ => winit::event_loop::ControlFlow::Poll,
winit::event::WindowEvent::CloseRequested => window_target.exit(),
_ => (),
},
_ => winit::event_loop::ControlFlow::Poll,
_ => (),
}
});
})
.unwrap();
}
22 changes: 11 additions & 11 deletions examples/multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ impl ApplicationContext for Application {
}

fn main() {
let event_loop = EventLoopBuilder::new().build();
let event_loop = EventLoopBuilder::new()
.build()
.expect("event loop building");
// To simplify things we use a single type for both the main and sub windows,
// since we can easily distinguish them by their id.
let mut windows: HashMap<WindowId, State<Application>> = HashMap::new();

event_loop.run(move |event, window_target, control_flow| {
event_loop.run(move |event, window_target| {
match event {
// The Resumed/Suspended events are mostly for Android compatiblity since the context can get lost there at any point.
// For convenience's sake the Resumed event is also delivered on other platforms on program startup.
Expand All @@ -52,13 +54,6 @@ fn main() {
winit::event::Event::Suspended => {
windows.clear();
},
winit::event::Event::RedrawRequested(window_id) => {
// Notice the minor difference since we have to find the correct state for the window in our HashMap
if let Some(state) = windows.get_mut(&window_id) {
state.context.update();
state.context.draw_frame(&state.display);
}
}
winit::event::Event::WindowEvent { event, window_id, .. } => {
if let Some(state) = windows.get_mut(&window_id) {
match event {
Expand All @@ -79,9 +74,13 @@ fn main() {
windows.remove(&window_id);
}
},
winit::event::WindowEvent::RedrawRequested => {
state.context.update();
state.context.draw_frame(&state.display);
}
winit::event::WindowEvent::CloseRequested => {
if state.context.id == 1 {
control_flow.set_exit();
window_target.exit();
} else {
windows.remove(&window_id);
}
Expand All @@ -99,5 +98,6 @@ fn main() {
}
_ => (),
};
});
})
.unwrap();
}
7 changes: 4 additions & 3 deletions examples/screenshot-asynchronous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use glium::index::PrimitiveType;
use glium::{Display, Surface};
use glutin::surface::WindowSurface;
use support::{ApplicationContext, State};
use winit::keyboard::{PhysicalKey, KeyCode};

mod screenshot {
use glium::Surface;
Expand Down Expand Up @@ -270,9 +271,9 @@ impl ApplicationContext for Application {
}

fn handle_window_event(&mut self, event: &winit::event::WindowEvent, _window: &winit::window::Window) {
if let winit::event::WindowEvent::KeyboardInput { input, ..} = event {
if let winit::event::ElementState::Pressed = input.state {
if let Some(winit::event::VirtualKeyCode::S) = input.virtual_keycode {
if let winit::event::WindowEvent::KeyboardInput { event, ..} = event {
if let winit::event::ElementState::Pressed = event.state {
if let PhysicalKey::Code(KeyCode::KeyS) = event.physical_key {
self.take_screenshot = true;
}
}
Expand Down
11 changes: 6 additions & 5 deletions examples/shadow_mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extern crate glium;

use cgmath::SquareMatrix;
use winit::keyboard::{PhysicalKey, KeyCode};
use std::time::Instant;
use glium::{Surface, Display, VertexBuffer, IndexBuffer, Program, texture::DepthTexture2d};
use glutin::surface::WindowSurface;
Expand Down Expand Up @@ -276,11 +277,11 @@ impl ApplicationContext for Application {

fn handle_window_event(&mut self, event: &winit::event::WindowEvent, _window: &winit::window::Window) {
match event {
winit::event::WindowEvent::KeyboardInput { input, .. } => if input.state == winit::event::ElementState::Pressed {
if let Some(key) = input.virtual_keycode {
match key {
winit::event::VirtualKeyCode::C => self.camera_rotating = !self.camera_rotating,
winit::event::VirtualKeyCode::L => self.light_rotating = !self.light_rotating,
winit::event::WindowEvent::KeyboardInput { event, .. } => if event.state == winit::event::ElementState::Pressed {
if let PhysicalKey::Code(code) = event.physical_key {
match code {
KeyCode::KeyC => self.camera_rotating = !self.camera_rotating,
KeyCode::KeyL => self.light_rotating = !self.light_rotating,
_ => {}
}
}
Expand Down
4 changes: 3 additions & 1 deletion examples/spirv/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use raw_window_handle::HasRawWindowHandle;

fn main() {
// We start by creating the main EventLoop
let event_loop = winit::event_loop::EventLoopBuilder::new().build();
let event_loop = winit::event_loop::EventLoopBuilder::new()
.build()
.expect("event loop building");
let window_builder = winit::window::WindowBuilder::new().with_title("Glium SPIR-V example");
let config_template_builder = glutin::config::ConfigTemplateBuilder::new();
let display_builder = glutin_winit::DisplayBuilder::new().with_window_builder(Some(window_builder));
Expand Down
28 changes: 12 additions & 16 deletions examples/support/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,23 +148,19 @@ impl CameraState {
}
}

pub fn process_input(&mut self, event: &winit::event::WindowEvent<'_>) {
let input = match *event {
winit::event::WindowEvent::KeyboardInput { input, .. } => input,
_ => return,
pub fn process_input(&mut self, event: &winit::event::WindowEvent) {
use winit::keyboard::{PhysicalKey, KeyCode};
let winit::event::WindowEvent::KeyboardInput { event, .. } = event else {
return
};
let pressed = input.state == winit::event::ElementState::Pressed;
let key = match input.virtual_keycode {
Some(key) => key,
None => return,
};
match key {
winit::event::VirtualKeyCode::Up => self.moving_up = pressed,
winit::event::VirtualKeyCode::Down => self.moving_down = pressed,
winit::event::VirtualKeyCode::A => self.moving_left = pressed,
winit::event::VirtualKeyCode::D => self.moving_right = pressed,
winit::event::VirtualKeyCode::W => self.moving_forward = pressed,
winit::event::VirtualKeyCode::S => self.moving_backward = pressed,
let pressed = event.state == winit::event::ElementState::Pressed;
match &event.physical_key {
PhysicalKey::Code(KeyCode::ArrowUp) => self.moving_up = pressed,
PhysicalKey::Code(KeyCode::ArrowDown) => self.moving_down = pressed,
PhysicalKey::Code(KeyCode::KeyA) => self.moving_left = pressed,
PhysicalKey::Code(KeyCode::KeyD) => self.moving_right = pressed,
PhysicalKey::Code(KeyCode::KeyW) => self.moving_forward = pressed,
PhysicalKey::Code(KeyCode::KeyS) => self.moving_backward = pressed,
_ => (),
};
}
Expand Down
35 changes: 20 additions & 15 deletions examples/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,22 @@ impl<T: ApplicationContext + 'static> State<T> {

/// Start the event_loop and keep rendering frames until the program is closed
pub fn run_loop() {
let event_loop = winit::event_loop::EventLoopBuilder::new().build();
let event_loop = winit::event_loop::EventLoopBuilder::new()
.build()
.expect("event loop building");
let mut state: Option<State<T>> = None;

event_loop.run(move |event, window_target, control_flow| {
let result = event_loop.run(move |event, window_target| {
match event {
// The Resumed/Suspended events are mostly for Android compatiblity since the context can get lost there at any point.
// For convenience's sake the Resumed event is also delivered on other platforms on program startup.
winit::event::Event::Resumed => {
state = Some(State::new(window_target, true));
},
winit::event::Event::Suspended => state = None,
winit::event::Event::RedrawRequested(_) => {
if let Some(state) = &mut state {
state.context.update();
state.context.draw_frame(&state.display);
}
}
// By requesting a redraw in response to a RedrawEventsCleared event we get continuous rendering.
// By requesting a redraw in response to a AboutToWait event we get continuous rendering.
// For applications that only change due to user input you could remove this handler.
winit::event::Event::RedrawEventsCleared => {
winit::event::Event::AboutToWait => {
if let Some(state) = &state {
state.window.request_redraw();
}
Expand All @@ -192,15 +188,21 @@ impl<T: ApplicationContext + 'static> State<T> {
state.display.resize(new_size.into());
}
},
winit::event::WindowEvent::RedrawRequested => {
if let Some(state) = &mut state {
state.context.update();
state.context.draw_frame(&state.display);
}
},
// Exit the event loop when requested (by closing the window for example) or when
// pressing the Esc key.
winit::event::WindowEvent::CloseRequested
| winit::event::WindowEvent::KeyboardInput { input: winit::event::KeyboardInput {
| winit::event::WindowEvent::KeyboardInput { event: winit::event::KeyEvent {
state: winit::event::ElementState::Pressed,
virtual_keycode: Some(winit::event::VirtualKeyCode::Escape),
logical_key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
..
}, ..} => {
control_flow.set_exit()
window_target.exit()
},
// Every other event
ev => {
Expand All @@ -212,13 +214,16 @@ impl<T: ApplicationContext + 'static> State<T> {
_ => (),
};
});
result.unwrap();
}

/// Create a context and draw a single frame
pub fn run_once(visible: bool) {
let event_loop = winit::event_loop::EventLoopBuilder::new().build();
let event_loop = winit::event_loop::EventLoopBuilder::new()
.build()
.expect("event loop building");
let mut state:State<T> = State::new(&event_loop, visible);
state.context.update();
state.context.draw_frame(&state.display);
}
}
}
9 changes: 5 additions & 4 deletions examples/tessellation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,15 @@ impl ApplicationContext for Application {
}

fn handle_window_event(&mut self, event: &winit::event::WindowEvent, _window: &winit::window::Window) {
use winit::keyboard::{PhysicalKey, KeyCode};
match event {
winit::event::WindowEvent::KeyboardInput { input, .. } => match input.state {
winit::event::ElementState::Pressed => match input.virtual_keycode {
Some(winit::event::VirtualKeyCode::Up) => {
winit::event::WindowEvent::KeyboardInput { event, .. } => match event.state {
winit::event::ElementState::Pressed => match event.physical_key {
PhysicalKey::Code(KeyCode::ArrowUp) => {
self.tess_level += 1;
println!("New tessellation level: {}", self.tess_level);
}
Some(winit::event::VirtualKeyCode::Down) => {
PhysicalKey::Code(KeyCode::ArrowDown) => {
if self.tess_level >= 2 {
self.tess_level -= 1;
println!("New tessellation level: {}", self.tess_level);
Expand Down
13 changes: 8 additions & 5 deletions examples/tutorial-01.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use glium::Surface;
fn main() {
// We start by creating the EventLoop, this can only be done once per process.
// This also needs to happen on the main thread to make the program portable.
let event_loop = winit::event_loop::EventLoopBuilder::new().build();
let event_loop = winit::event_loop::EventLoopBuilder::new()
.build()
.expect("event loop building");
let (_window, display) = glium::backend::glutin::SimpleWindowBuilder::new()
.with_title("Glium tutorial #1")
.build(&event_loop);
Expand All @@ -16,14 +18,15 @@ fn main() {
frame.finish().unwrap();

// Now we wait until the program is closed
event_loop.run(move |event, _, control_flow| {
event_loop.run(move |event, window_target| {
match event {
winit::event::Event::WindowEvent { event, .. } => match event {
// This event is sent by the OS when you close the Window, or request the program to quit via the taskbar.
winit::event::WindowEvent::CloseRequested => control_flow.set_exit(),
winit::event::WindowEvent::CloseRequested => window_target.exit(),
_ => (),
},
_ => (),
};
});
}
})
.unwrap();
}

0 comments on commit 77f48cd

Please sign in to comment.