Remove epi backend from egui_glow (#1361)
This commit is contained in:
parent
50539bd31a
commit
29c52e8eb6
7 changed files with 6 additions and 168 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1073,7 +1073,6 @@ dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui",
|
||||||
"egui-winit",
|
"egui-winit",
|
||||||
"epi",
|
|
||||||
"glium",
|
"glium",
|
||||||
"image",
|
"image",
|
||||||
]
|
]
|
||||||
|
|
|
@ -3,6 +3,8 @@ All notable changes to the `egui_glium` integration will be noted in this file.
|
||||||
|
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
## 0.17.0 - 2022-02-22
|
||||||
|
|
|
@ -38,13 +38,7 @@ default_fonts = ["egui/default_fonts"]
|
||||||
links = ["egui-winit/links"]
|
links = ["egui-winit/links"]
|
||||||
|
|
||||||
# enable persisting native window options and egui memory
|
# enable persisting native window options and egui memory
|
||||||
persistence = [
|
persistence = ["egui-winit/persistence", "egui/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",
|
|
||||||
]
|
|
||||||
|
|
||||||
# experimental support for a screen reader
|
# experimental support for a screen reader
|
||||||
screen_reader = ["egui-winit/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",
|
"convert_bytemuck",
|
||||||
"single_threaded",
|
"single_threaded",
|
||||||
] }
|
] }
|
||||||
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false, features = [
|
egui-winit = { version = "0.17.0", path = "../egui-winit", default-features = false }
|
||||||
"epi",
|
|
||||||
] }
|
|
||||||
epi = { version = "0.17.0", path = "../epi", optional = true }
|
|
||||||
|
|
||||||
ahash = "0.7"
|
ahash = "0.7"
|
||||||
bytemuck = "1.7"
|
bytemuck = "1.7"
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
|
|
||||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release
|
||||||
|
|
||||||
use epi::NativeTexture;
|
|
||||||
use glium::glutin;
|
use glium::glutin;
|
||||||
|
|
||||||
fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
|
fn create_display(event_loop: &glutin::event_loop::EventLoop<()>) -> glium::Display {
|
||||||
|
|
|
@ -1,141 +0,0 @@
|
||||||
use glium::glutin;
|
|
||||||
|
|
||||||
use crate::*;
|
|
||||||
|
|
||||||
struct RequestRepaintEvent;
|
|
||||||
|
|
||||||
struct GliumRepaintSignal(
|
|
||||||
std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>,
|
|
||||||
);
|
|
||||||
|
|
||||||
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<RequestRepaintEvent>,
|
|
||||||
) -> 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<dyn epi::App>, 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();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -90,11 +90,6 @@
|
||||||
mod painter;
|
mod painter;
|
||||||
pub use painter::Painter;
|
pub use painter::Painter;
|
||||||
|
|
||||||
#[cfg(feature = "epi")]
|
|
||||||
mod epi_backend;
|
|
||||||
#[cfg(feature = "epi")]
|
|
||||||
pub use epi_backend::{run, NativeOptions};
|
|
||||||
|
|
||||||
pub use egui_winit;
|
pub use egui_winit;
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -21,7 +21,6 @@ pub struct Painter {
|
||||||
|
|
||||||
textures: AHashMap<egui::TextureId, Rc<SrgbTexture2d>>,
|
textures: AHashMap<egui::TextureId, Rc<SrgbTexture2d>>,
|
||||||
|
|
||||||
#[cfg(feature = "epi")]
|
|
||||||
/// [`egui::TextureId::User`] index
|
/// [`egui::TextureId::User`] index
|
||||||
next_native_tex_id: u64,
|
next_native_tex_id: u64,
|
||||||
}
|
}
|
||||||
|
@ -56,7 +55,6 @@ impl Painter {
|
||||||
max_texture_side,
|
max_texture_side,
|
||||||
program,
|
program,
|
||||||
textures: Default::default(),
|
textures: Default::default(),
|
||||||
#[cfg(feature = "epi")]
|
|
||||||
next_native_tex_id: 0,
|
next_native_tex_id: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -266,20 +264,15 @@ impl Painter {
|
||||||
fn get_texture(&self, texture_id: egui::TextureId) -> Option<&SrgbTexture2d> {
|
fn get_texture(&self, texture_id: egui::TextureId) -> Option<&SrgbTexture2d> {
|
||||||
self.textures.get(&texture_id).map(|rc| rc.as_ref())
|
self.textures.get(&texture_id).map(|rc| rc.as_ref())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "epi")]
|
pub fn register_native_texture(&mut self, native: Rc<SrgbTexture2d>) -> egui::TextureId {
|
||||||
impl epi::NativeTexture for Painter {
|
|
||||||
type Texture = Rc<SrgbTexture2d>;
|
|
||||||
|
|
||||||
fn register_native_texture(&mut self, native: Self::Texture) -> egui::TextureId {
|
|
||||||
let id = egui::TextureId::User(self.next_native_tex_id);
|
let id = egui::TextureId::User(self.next_native_tex_id);
|
||||||
self.next_native_tex_id += 1;
|
self.next_native_tex_id += 1;
|
||||||
self.textures.insert(id, native);
|
self.textures.insert(id, native);
|
||||||
id
|
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<SrgbTexture2d>) {
|
||||||
self.textures.insert(id, replacing);
|
self.textures.insert(id, replacing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue