1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Make epi::Frame cloneable so you can allocate textures in other threads (#999)

Closes https://github.com/emilk/egui/issues/673

Also adds `epi::Image`
This commit is contained in:
Emil Ernerfeldt
2021-12-26 21:21:28 +01:00
committed by GitHub
parent 647e020824
commit b7441eeee7
28 changed files with 548 additions and 824 deletions

View File

@@ -4,7 +4,7 @@ struct RequestRepaintEvent;
struct GlowRepaintSignal(std::sync::Mutex<glutin::event_loop::EventLoopProxy<RequestRepaintEvent>>);
impl epi::RepaintSignal for GlowRepaintSignal {
impl epi::backend::RepaintSignal for GlowRepaintSignal {
fn request_repaint(&self) {
self.0.lock().unwrap().send_event(RequestRepaintEvent).ok();
}
@@ -64,7 +64,6 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
let mut integration = egui_winit::epi::EpiIntegration::new(
"egui_glow",
gl_window.window(),
&mut painter,
repaint_signal,
persistence,
app,
@@ -83,9 +82,15 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
std::thread::sleep(std::time::Duration::from_millis(10));
}
let (needs_repaint, shapes) = integration.update(gl_window.window(), &mut painter);
let (needs_repaint, mut tex_allocation_data, shapes) =
integration.update(gl_window.window());
let clipped_meshes = integration.egui_ctx.tessellate(shapes);
for (id, image) in tex_allocation_data.creations {
painter.set_texture(&gl, id, &image);
}
// paint:
{
let color = integration.app.clear_color();
unsafe {
@@ -96,8 +101,8 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
}
painter.upload_egui_texture(&gl, &integration.egui_ctx.texture());
painter.paint_meshes(
gl_window.window().inner_size().into(),
&gl,
gl_window.window().inner_size().into(),
integration.egui_ctx.pixels_per_point(),
clipped_meshes,
);
@@ -105,6 +110,10 @@ pub fn run(app: Box<dyn epi::App>, native_options: &epi::NativeOptions) -> ! {
gl_window.swap_buffers().unwrap();
}
for id in tex_allocation_data.destructions.drain(..) {
painter.free_texture(id);
}
{
*control_flow = if integration.should_quit() {
glutin::event_loop::ControlFlow::Exit