Skip to content

Commit

Permalink
polish glutin upgrade with glutin-winit crate (#2526)
Browse files Browse the repository at this point in the history
* use glutin-winit for glow context creation

* added some tracing for easier debugging of glutin problems

* fmt

* add more debug logs

* more tracing

* fallback egl instead of prefer egl

* update pure glow example to use glutin_winit

* add more logging. ignore vsync option if not supported

* cranky lint

* add some logging for easier debugging

* drop window after glutin surface

* small changes based on pr review

* build fix

---------

Co-authored-by: Emil Ernerfeldt <[email protected]>
  • Loading branch information
coderedart and emilk authored Feb 8, 2023
1 parent e8b9e70 commit be9b5a3
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 180 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 3 additions & 9 deletions crates/eframe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dark-light = ["dep:dark-light"]
default_fonts = ["egui/default_fonts"]

## Use [`glow`](https://github.com/grovesNL/glow) for painting, via [`egui_glow`](https://github.com/emilk/egui/tree/master/crates/egui_glow).
glow = ["dep:glow", "dep:egui_glow", "dep:glutin"]
glow = ["dep:glow", "dep:egui_glow", "dep:glutin", "dep:glutin-winit"]

## Enable saving app state to disk.
persistence = [
Expand Down Expand Up @@ -104,14 +104,8 @@ pollster = { version = "0.2", optional = true } # needed for wgpu

# we can expose these to user so that they can select which backends they want to enable to avoid compiling useless deps.
# this can be done at the same time we expose x11/wayland features of winit crate.
glutin = { version = "0.30.0", optional = true, es = [
"egl",
"glx",
"x11",
"wayland",
"wgl",
] }

glutin = { version = "0.30", optional = true }
glutin-winit = { version = "0.3.0", optional = true }
image = { version = "0.24", optional = true, default-features = false, features = [
"png",
] }
Expand Down
4 changes: 2 additions & 2 deletions crates/eframe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ pub enum Error {
Glutin(#[from] glutin::error::Error),

#[cfg(all(feature = "glow", not(target_arch = "wasm32")))]
#[error("Found no glutin configs matching the template: {0:?}")]
NoGlutinConfigs(glutin::config::ConfigTemplate),
#[error("Found no glutin configs matching the template: {0:?}. error: {1:?}")]
NoGlutinConfigs(glutin::config::ConfigTemplate, Box<dyn std::error::Error>),

#[cfg(feature = "wgpu")]
#[error("WGPU error: {0}")]
Expand Down
18 changes: 12 additions & 6 deletions crates/eframe/src/native/epi_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,13 @@ pub fn read_window_info(
monitor_size,
}
}

pub fn build_window<E>(
pub fn window_builder<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
native_options: &epi::NativeOptions,
window_settings: Option<WindowSettings>,
) -> Result<winit::window::Window, winit::error::OsError> {
) -> winit::window::WindowBuilder {
let epi::NativeOptions {
always_on_top,
maximized,
decorated,
fullscreen,
Expand Down Expand Up @@ -159,11 +157,19 @@ pub fn build_window<E>(
}
}
}

window_builder
}
pub fn build_window<E>(
event_loop: &EventLoopWindowTarget<E>,
title: &str,
native_options: &epi::NativeOptions,
window_settings: Option<WindowSettings>,
) -> Result<winit::window::Window, winit::error::OsError> {
let window_builder = window_builder(event_loop, title, native_options, window_settings);
let window = window_builder.build(event_loop)?;

use winit::window::WindowLevel;
window.set_window_level(if *always_on_top {
window.set_window_level(if native_options.always_on_top {
WindowLevel::AlwaysOnTop
} else {
WindowLevel::Normal
Expand Down
Loading

0 comments on commit be9b5a3

Please sign in to comment.