diff --git a/crates/eframe/CHANGELOG.md b/crates/eframe/CHANGELOG.md index 130ef4f3bda7..332bf676e1b5 100644 --- a/crates/eframe/CHANGELOG.md +++ b/crates/eframe/CHANGELOG.md @@ -8,7 +8,7 @@ NOTE: [`egui-winit`](../egui-winit/CHANGELOG.md), [`egui_glium`](../egui_glium/C * Added `NativeOptions::event_loop_builder` hook for apps to change platform specific event loop options ([#1952](https://github.com/emilk/egui/pull/1952)). * Enabled deferred render state initialization to support Android ([#1952](https://github.com/emilk/egui/pull/1952)). * Allow empty textures with the glow renderer. - +* Added `shader_version` to `NativeOptions` for cross compilling support on different target OpenGL | ES versions (on native `glow` renderer only) ([#1993](https://github.com/emilk/egui/pull/1993)).. ## 0.19.0 - 2022-08-20 * MSRV (Minimum Supported Rust Version) is now `1.61.0` ([#1846](https://github.com/emilk/egui/pull/1846)). diff --git a/crates/eframe/src/epi.rs b/crates/eframe/src/epi.rs index ee42b06c7a6d..9ca952fd25da 100644 --- a/crates/eframe/src/epi.rs +++ b/crates/eframe/src/epi.rs @@ -311,6 +311,13 @@ pub struct NativeOptions { /// /// Note: A [`NativeOptions`] clone will not include any `event_loop_builder` hook. pub event_loop_builder: Option<EventLoopBuilderHook>, + + #[cfg(feature = "glow")] + /// Needed for cross compiling for VirtualBox VMSVGA driver with OpenGL ES 2.0 and OpenGL 2.1 which doesn't support SRGB texture. + /// See <https://github.com/emilk/egui/pull/1993>. + /// + /// For OpenGL ES 2.0: set this to [`egui_glow::ShaderVersion::Es100`] to solve blank texture problem (by using the "fallback shader"). + pub shader_version: Option<egui_glow::ShaderVersion>, } #[cfg(not(target_arch = "wasm32"))] @@ -350,6 +357,8 @@ impl Default for NativeOptions { default_theme: Theme::Dark, run_and_return: true, event_loop_builder: None, + #[cfg(feature = "glow")] + shader_version: None, } } } diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index d76a9e5934db..2f42151c9991 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -337,8 +337,9 @@ mod glow_integration { ); let gl = Arc::new(gl); - let painter = egui_glow::Painter::new(gl.clone(), None, "") - .unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error)); + let painter = + egui_glow::Painter::new(gl.clone(), None, "", self.native_options.shader_version) + .unwrap_or_else(|error| panic!("some OpenGL error occurred {}\n", error)); let system_theme = self.native_options.system_theme(); let mut integration = epi_integration::EpiIntegration::new( diff --git a/crates/eframe/src/web/web_glow_painter.rs b/crates/eframe/src/web/web_glow_painter.rs index 610949287b10..16a600ade793 100644 --- a/crates/eframe/src/web/web_glow_painter.rs +++ b/crates/eframe/src/web/web_glow_painter.rs @@ -23,7 +23,7 @@ impl WebPainter { let gl = std::sync::Arc::new(gl); let dimension = [canvas.width() as i32, canvas.height() as i32]; - let painter = egui_glow::Painter::new(gl, Some(dimension), shader_prefix) + let painter = egui_glow::Painter::new(gl, Some(dimension), shader_prefix, None) .map_err(|error| format!("Error starting glow painter: {}", error))?; Ok(Self { diff --git a/crates/egui_glow/CHANGELOG.md b/crates/egui_glow/CHANGELOG.md index 4ded9e0cff63..40ccd5f55925 100644 --- a/crates/egui_glow/CHANGELOG.md +++ b/crates/egui_glow/CHANGELOG.md @@ -4,7 +4,7 @@ All notable changes to the `egui_glow` integration will be noted in this file. ## Unreleased * Allow empty textures. - +* Added `shader_version` variable on `EguiGlow::new` for easier cross compilling on different OpenGL | ES targets ([#1993](https://github.com/emilk/egui/pull/1993)). ## 0.19.0 - 2022-08-20 * MSRV (Minimum Supported Rust Version) is now `1.61.0` ([#1846](https://github.com/emilk/egui/pull/1846)). diff --git a/crates/egui_glow/examples/pure_glow.rs b/crates/egui_glow/examples/pure_glow.rs index cda339028519..e6f4f0b4709d 100644 --- a/crates/egui_glow/examples/pure_glow.rs +++ b/crates/egui_glow/examples/pure_glow.rs @@ -10,7 +10,7 @@ fn main() { let (gl_window, gl) = create_display(&event_loop); let gl = std::sync::Arc::new(gl); - let mut egui_glow = egui_glow::EguiGlow::new(&event_loop, gl.clone()); + let mut egui_glow = egui_glow::EguiGlow::new(&event_loop, gl.clone(), None); event_loop.run(move |event, _, control_flow| { let mut redraw = || { diff --git a/crates/egui_glow/src/painter.rs b/crates/egui_glow/src/painter.rs index 5a38356269be..95c93e29733f 100644 --- a/crates/egui_glow/src/painter.rs +++ b/crates/egui_glow/src/painter.rs @@ -106,19 +106,19 @@ impl Painter { gl: Arc<glow::Context>, pp_fb_extent: Option<[i32; 2]>, shader_prefix: &str, + shader_version: Option<ShaderVersion>, ) -> Result<Painter, String> { crate::profile_function!(); crate::check_for_gl_error_even_in_release!(&gl, "before Painter::new"); let max_texture_side = unsafe { gl.get_parameter_i32(glow::MAX_TEXTURE_SIZE) } as usize; - - let shader_version = ShaderVersion::get(&gl); - let is_webgl_1 = shader_version == ShaderVersion::Es100; - let header = shader_version.version_declaration(); + let shader = shader_version.unwrap_or_else(|| ShaderVersion::get(&gl)); + let is_webgl_1 = shader == ShaderVersion::Es100; + let header = shader.version_declaration(); tracing::debug!("Shader header: {:?}.", header); let srgb_support = gl.supported_extensions().contains("EXT_sRGB"); - let (post_process, srgb_support_define) = match (shader_version, srgb_support) { + let (post_process, srgb_support_define) = match (shader, srgb_support) { // WebGL2 support sRGB default (ShaderVersion::Es300, _) | (ShaderVersion::Es100, true) => unsafe { // Add sRGB support marker for fragment shader @@ -155,7 +155,7 @@ impl Painter { "{}\n{}\n{}\n{}", header, shader_prefix, - if shader_version.is_new_shader_interface() { + if shader.is_new_shader_interface() { "#define NEW_SHADER_INTERFACE\n" } else { "" @@ -171,7 +171,7 @@ impl Painter { header, shader_prefix, srgb_support_define, - if shader_version.is_new_shader_interface() { + if shader.is_new_shader_interface() { "#define NEW_SHADER_INTERFACE\n" } else { "" @@ -233,7 +233,7 @@ impl Painter { u_screen_size, u_sampler, is_webgl_1, - is_embedded: matches!(shader_version, ShaderVersion::Es100 | ShaderVersion::Es300), + is_embedded: matches!(shader, ShaderVersion::Es100 | ShaderVersion::Es300), vao, srgb_support, post_process, diff --git a/crates/egui_glow/src/winit.rs b/crates/egui_glow/src/winit.rs index 931b69575c3b..f3f79a64c576 100644 --- a/crates/egui_glow/src/winit.rs +++ b/crates/egui_glow/src/winit.rs @@ -1,7 +1,7 @@ +use crate::shader_version::ShaderVersion; pub use egui_winit; -pub use egui_winit::EventResponse; - use egui_winit::winit; +pub use egui_winit::EventResponse; /// Use [`egui`] from a [`glow`] app based on [`winit`]. pub struct EguiGlow { @@ -14,11 +14,13 @@ pub struct EguiGlow { } impl EguiGlow { + /// For automatic shader version detection set `shader_version` to `None`. pub fn new<E>( event_loop: &winit::event_loop::EventLoopWindowTarget<E>, gl: std::sync::Arc<glow::Context>, + shader_version: Option<ShaderVersion>, ) -> Self { - let painter = crate::Painter::new(gl, None, "") + let painter = crate::Painter::new(gl, None, "", shader_version) .map_err(|error| { tracing::error!("error occurred in initializing painter:\n{}", error); }) diff --git a/examples/retained_image/src/main.rs b/examples/retained_image/src/main.rs index f5f0004908e3..453e47721281 100644 --- a/examples/retained_image/src/main.rs +++ b/examples/retained_image/src/main.rs @@ -8,6 +8,7 @@ fn main() { initial_window_size: Some(egui::vec2(500.0, 900.0)), ..Default::default() }; + eframe::run_native( "Show an image with eframe/egui", options,