diff --git a/Cargo.lock b/Cargo.lock index 939fadfe47e..593823c2485 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1073,7 +1073,6 @@ dependencies = [ "bytemuck", "egui", "egui-winit", - "epi", "glium", "image", ] diff --git a/egui_glium/CHANGELOG.md b/egui_glium/CHANGELOG.md index 81bcbcbeeb6..6f8cbd8c4ae 100644 --- a/egui_glium/CHANGELOG.md +++ b/egui_glium/CHANGELOG.md @@ -3,6 +3,8 @@ All notable changes to the `egui_glium` integration will be noted in this file. ## Unreleased +* Remove "epi" feature ([#1361](https://github.com/emilk/egui/pull/1361)). +* Remove need for `trait epi::NativeTexture` to use the `fn register_native_texture/replace_native_texture` ([#1361](https://github.com/emilk/egui/pull/1361)). ## 0.17.0 - 2022-02-22 diff --git a/egui_glium/Cargo.toml b/egui_glium/Cargo.toml index 8dbcfbf7abe..b23a7a610d7 100644 --- a/egui_glium/Cargo.toml +++ b/egui_glium/Cargo.toml @@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"] links = ["egui-winit/links"] # enable persisting native window options and egui memory -persistence = [ - "egui-winit/persistence", - "egui/persistence", - "epi", # also implied by the lines below, see https://github.com/rust-lang/cargo/issues/8832 - "epi/file_storage", - "epi/persistence", -] +persistence = ["egui-winit/persistence", "egui/persistence"] # experimental support for a screen reader screen_reader = ["egui-winit/screen_reader"] @@ -55,10 +49,7 @@ egui = { version = "0.17.0", path = "../egui", default-features = false, feature "convert_bytemuck", "single_threaded", ] } -egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false, features = [ - "epi", -] } -epi = { version = "0.17.0", path = "../epi", optional = true } +egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false } ahash = "0.7" bytemuck = "1.7" diff --git a/egui_glium/examples/native_texture.rs b/egui_glium/examples/native_texture.rs index 821c3c87343..a5197ccf117 100644 --- a/egui_glium/examples/native_texture.rs +++ b/egui_glium/examples/native_texture.rs @@ -2,7 +2,6 @@ #![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release -use epi::NativeTexture; use glium::glutin; fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display { diff --git a/egui_glium/src/epi_backend.rs b/egui_glium/src/epi_backend.rs deleted file mode 100644 index dafca3b4c9a..00000000000 --- a/egui_glium/src/epi_backend.rs +++ /dev/null @@ -1,141 +0,0 @@ -use glium::glutin; - -use crate::*; - -struct RequestRepaintEvent; - -struct GliumRepaintSignal( - std::sync::Mutex>, -); - -impl epi::backend::RepaintSignal for GliumRepaintSignal { - fn request_repaint(&self) { - self.0.lock().unwrap().send_event(RequestRepaintEvent).ok(); - } -} - -fn create_display( - window_builder: glutin::window::WindowBuilder, - event_loop: &glutin::event_loop::EventLoop, -) -> glium::Display { - let context_builder = glutin::ContextBuilder::new() - .with_depth_buffer(0) - .with_srgb(true) - .with_stencil_buffer(0) - .with_vsync(true); - - glium::Display::new(window_builder, context_builder, event_loop).unwrap() -} - -// ---------------------------------------------------------------------------- - -pub use epi::NativeOptions; - -/// Run an egui app -pub fn run(app: Box, native_options: &epi::NativeOptions) -> ! { - let persistence = egui_winit::epi::Persistence::from_app_name(app.name()); - let window_settings = persistence.load_window_settings(); - let window_builder = - egui_winit::epi::window_builder(native_options, &window_settings).with_title(app.name()); - let event_loop = glutin::event_loop::EventLoop::with_user_event(); - let display = create_display(window_builder, &event_loop); - - let repaint_signal = std::sync::Arc::new(GliumRepaintSignal(std::sync::Mutex::new( - event_loop.create_proxy(), - ))); - - let mut painter = crate::Painter::new(&display); - let mut integration = egui_winit::epi::EpiIntegration::new( - "egui_glium", - painter.max_texture_side(), - display.gl_window().window(), - repaint_signal, - persistence, - app, - ); - - let mut is_focused = true; - - event_loop.run(move |event, _, control_flow| { - let mut redraw = || { - if !is_focused { - // On Mac, a minimized Window uses up all CPU: https://github.com/emilk/egui/issues/325 - // We can't know if we are minimized: https://github.com/rust-windowing/winit/issues/208 - // But we know if we are focused (in foreground). When minimized, we are not focused. - // However, a user may want an egui with an animation in the background, - // so we still need to repaint quite fast. - std::thread::sleep(std::time::Duration::from_millis(10)); - } - - let egui::FullOutput { - platform_output, - needs_repaint, - textures_delta, - shapes, - } = integration.update(display.gl_window().window()); - - integration.handle_platform_output(display.gl_window().window(), platform_output); - - let clipped_meshes = integration.egui_ctx.tessellate(shapes); - - // paint: - { - use glium::Surface as _; - let mut target = display.draw(); - let color = integration.app.clear_color(); - target.clear_color(color[0], color[1], color[2], color[3]); - - painter.paint_and_update_textures( - &display, - &mut target, - integration.egui_ctx.pixels_per_point(), - clipped_meshes, - &textures_delta, - ); - - target.finish().unwrap(); - } - - { - *control_flow = if integration.should_quit() { - glutin::event_loop::ControlFlow::Exit - } else if needs_repaint { - display.gl_window().window().request_redraw(); - glutin::event_loop::ControlFlow::Poll - } else { - glutin::event_loop::ControlFlow::Wait - }; - } - - integration.maybe_autosave(display.gl_window().window()); - }; - - match event { - // Platform-dependent event handlers to workaround a winit bug - // See: https://github.com/rust-windowing/winit/issues/987 - // See: https://github.com/rust-windowing/winit/issues/1619 - glutin::event::Event::RedrawEventsCleared if cfg!(windows) => redraw(), - glutin::event::Event::RedrawRequested(_) if !cfg!(windows) => redraw(), - - glutin::event::Event::WindowEvent { event, .. } => { - if let glutin::event::WindowEvent::Focused(new_focused) = event { - is_focused = new_focused; - } - - integration.on_event(&event); - if integration.should_quit() { - *control_flow = glium::glutin::event_loop::ControlFlow::Exit; - } - - display.gl_window().window().request_redraw(); // TODO: ask egui if the events warrants a repaint instead - } - glutin::event::Event::LoopDestroyed => { - integration.on_exit(display.gl_window().window()); - } - glutin::event::Event::UserEvent(RequestRepaintEvent) => { - display.gl_window().window().request_redraw(); - } - _ => (), - } - }); -} diff --git a/egui_glium/src/lib.rs b/egui_glium/src/lib.rs index 991a072aba6..db6bf66a1c8 100644 --- a/egui_glium/src/lib.rs +++ b/egui_glium/src/lib.rs @@ -90,11 +90,6 @@ mod painter; pub use painter::Painter; -#[cfg(feature = "epi")] -mod epi_backend; -#[cfg(feature = "epi")] -pub use epi_backend::{run, NativeOptions}; - pub use egui_winit; // ---------------------------------------------------------------------------- diff --git a/egui_glium/src/painter.rs b/egui_glium/src/painter.rs index 26f74133a4b..5299a11f5b1 100644 --- a/egui_glium/src/painter.rs +++ b/egui_glium/src/painter.rs @@ -21,7 +21,6 @@ pub struct Painter { textures: AHashMap>, - #[cfg(feature = "epi")] /// [`egui::TextureId::User`] index next_native_tex_id: u64, } @@ -56,7 +55,6 @@ impl Painter { max_texture_side, program, textures: Default::default(), - #[cfg(feature = "epi")] next_native_tex_id: 0, } } @@ -266,20 +264,15 @@ impl Painter { fn get_texture(&self, texture_id: egui::TextureId) -> Option<&SrgbTexture2d> { self.textures.get(&texture_id).map(|rc| rc.as_ref()) } -} - -#[cfg(feature = "epi")] -impl epi::NativeTexture for Painter { - type Texture = Rc; - fn register_native_texture(&mut self, native: Self::Texture) -> egui::TextureId { + pub fn register_native_texture(&mut self, native: Rc) -> egui::TextureId { let id = egui::TextureId::User(self.next_native_tex_id); self.next_native_tex_id += 1; self.textures.insert(id, native); id } - fn replace_native_texture(&mut self, id: egui::TextureId, replacing: Self::Texture) { + pub fn replace_native_texture(&mut self, id: egui::TextureId, replacing: Rc) { self.textures.insert(id, replacing); } }