From 5a807bb45ddc2ea01e44559ed66115e6006ff0b9 Mon Sep 17 00:00:00 2001 From: Varphone Wong Date: Mon, 5 Aug 2024 13:44:15 +0800 Subject: [PATCH] `eframe`: Introduce `NativeOptions::prefer_gl_api` to specify the preferred OpenGL API --- crates/eframe/src/epi.rs | 14 ++++++++++++++ crates/eframe/src/native/glow_integration.rs | 5 +---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index 7a7e92244..d4c200087 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -25,6 +25,10 @@ use static_assertions::assert_not_impl_any; #[cfg(any(feature = "glow", feature = "wgpu"))] pub use winit::{event_loop::EventLoopBuilder, window::WindowAttributes}; +#[cfg(not(target_arch = "wasm32"))] +#[cfg(feature = "glow")] +pub use glutin_winit::ApiPreference as GlApiPreference; + /// Hook into the building of an event loop before it is run /// /// You can configure any platform specific details required on top of the default configuration @@ -396,6 +400,13 @@ pub struct NativeOptions { /// [`with_android_app`]: winit::platform::android::EventLoopBuilderExtAndroid::with_android_app #[cfg(target_os = "android")] pub android_app: Option, + + /// Which OpenGL API to prefer when using [`Renderer::Glow`]. + /// + /// This is only used when the `glow` feature is enabled. + /// Default: [`GlApiPreference::FallbackEgl`]. + #[cfg(feature = "glow")] + pub prefer_gl_api: GlApiPreference, } #[cfg(not(target_arch = "wasm32"))] @@ -462,6 +473,9 @@ impl Default for NativeOptions { #[cfg(target_os = "android")] android_app: None, + + #[cfg(feature = "glow")] + prefer_gl_api: GlApiPreference::FallbackEgl, } } } diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f17c6ad50..c2716d1a3 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -939,10 +939,7 @@ impl GlutinWindowContext { // Create GL display. This may probably create a window too on most platforms. Definitely on `MS windows`. Never on Android. let display_builder = glutin_winit::DisplayBuilder::new() - // we might want to expose this option to users in the future. maybe using an env var or using native_options. - // - // The justification for FallbackEgl over PreferEgl is at https://github.com/emilk/egui/pull/2526#issuecomment-1400229576 . - .with_preference(glutin_winit::ApiPreference::FallbackEgl) + .with_preference(native_options.prefer_gl_api) // https://github.com/emilk/egui/issues/2520#issuecomment-1367841150 .with_window_attributes(Some(egui_winit::create_winit_window_attributes( egui_ctx, event_loop,