1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

eframe: Introduce NativeOptions::prefer_gl_api to specify the preferred OpenGL API

This commit is contained in:
Varphone Wong
2024-08-05 13:44:15 +08:00
parent a083cdaea4
commit 7d32e74c81
2 changed files with 15 additions and 4 deletions

View File

@@ -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
@@ -364,6 +368,13 @@ pub struct NativeOptions {
///
/// Defaults to true.
pub dithering: bool,
/// 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"))]
@@ -424,6 +435,9 @@ impl Default for NativeOptions {
persistence_path: None,
dithering: true,
#[cfg(feature = "glow")]
prefer_gl_api: GlApiPreference::FallbackEgl,
}
}
}

View File

@@ -940,10 +940,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,