From af11d766fcfb1c5c90303b0e4f7f07734e450a19 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 7 Nov 2020 11:44:32 +0100 Subject: [PATCH] Split out tesselation from Context::end_frame() --- CHANGELOG.md | 1 + README.md | 3 ++- egui/benches/benchmark.rs | 15 ++++++++++++++- egui/src/context.rs | 34 +++++++++++++++++++--------------- egui/src/lib.rs | 6 ++++-- egui/src/paint/mod.rs | 4 +++- egui/src/paint/tessellator.rs | 19 ++++++++++++------- egui_glium/src/backend.rs | 3 ++- egui_web/src/backend.rs | 3 ++- 9 files changed, 59 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3135943f..1aab8513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * You can no longer throw windows * `Context::begin_frame()` no longer returns anything. * Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. +* `Context::end_frame()` now returns "paint jobs" that need to be converted to triangles with `Context::tesselate()`. ## 0.2.0 - 2020-10-10 diff --git a/README.md b/README.md index 5fd90c12..8593be9c 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,8 @@ loop { let raw_input: egui::RawInput = my_integration.gather_input(); egui_ctx.begin_frame(raw_input); my_app.ui(&mut egui_ctx); // add panels, windows and widgets to `egui_ctx` here - let (output, paint_jobs) = egui_ctx.end_frame(); + let (output, paint_commands) = egui_ctx.end_frame(); + let paint_jobs = self.ctx.tesselate(paint_commands); // create triangles to paint my_integration.paint(paint_jobs); my_integration.set_cursor_icon(output.cursor_icon); // Also see `egui::Output` for more diff --git a/egui/benches/benchmark.rs b/egui/benches/benchmark.rs index 763bab74..aa49a73a 100644 --- a/egui/benches/benchmark.rs +++ b/egui/benches/benchmark.rs @@ -33,6 +33,19 @@ pub fn criterion_benchmark(c: &mut Criterion) { }); } + { + let mut ctx = egui::Context::new(); + ctx.memory().all_collpasing_are_open = true; // expand the demo window with everything + let mut demo_windows = egui::demos::DemoWindows::default(); + ctx.begin_frame(raw_input.clone()); + demo_windows.ui(&ctx, &Default::default(), &mut None); + let (_, paint_commands) = ctx.end_frame(); + + c.bench_function("tesselate", |b| { + b.iter(|| ctx.tesselate(paint_commands.clone())) + }); + } + { let mut ctx = egui::Context::new(); ctx.begin_frame(raw_input); @@ -43,7 +56,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { }) }); }); - // let _ = ctx.end_frame(); // skip, because tessellating all that text is slow + let _ = ctx.end_frame(); } } diff --git a/egui/src/context.rs b/egui/src/context.rs index cbfd47c9..0ebcb07f 100644 --- a/egui/src/context.rs +++ b/egui/src/context.rs @@ -20,7 +20,7 @@ struct Options { /// The default style for new `Ui`:s. style: Arc