diff --git a/crates/eframe/src/native/run.rs b/crates/eframe/src/native/run.rs index 10f20f0d3..47207f790 100644 --- a/crates/eframe/src/native/run.rs +++ b/crates/eframe/src/native/run.rs @@ -1204,7 +1204,7 @@ mod glow_integration { let screen_size_in_pixels: [u32; 2] = win.inner_size().into(); - let clipped_primitives = egui_ctx.tessellate(output.shapes, id_pair.this); + let clipped_primitives = egui_ctx.tessellate(output.shapes); let mut glutin = glutin.borrow_mut(); let mut painter = painter.borrow_mut(); @@ -1517,10 +1517,7 @@ mod glow_integration { let clipped_primitives = { crate::profile_scope!("tessellate"); - integration - .borrow() - .egui_ctx - .tessellate(shapes, viewport_id) + integration.borrow().egui_ctx.tessellate(shapes) }; { let mut glutin = glutin.borrow_mut(); @@ -2339,7 +2336,7 @@ mod wgpu_integration { } let pixels_per_point = egui_ctx.input_for(id_pair.this, |i| i.pixels_per_point()); - let clipped_primitives = egui_ctx.tessellate(output.shapes, id_pair.this); + let clipped_primitives = egui_ctx.tessellate(output.shapes); painter.paint_and_update_textures( id_pair.this, pixels_per_point, @@ -2508,10 +2505,7 @@ mod wgpu_integration { let clipped_primitives = { crate::profile_scope!("tessellate"); - integration - .borrow() - .egui_ctx - .tessellate(shapes, viewport_id) + integration.borrow().egui_ctx.tessellate(shapes) }; let integration = &mut *integration.borrow_mut(); diff --git a/crates/egui/src/context.rs b/crates/egui/src/context.rs index 48b911234..37263bae7 100644 --- a/crates/egui/src/context.rs +++ b/crates/egui/src/context.rs @@ -162,6 +162,9 @@ struct ContextImpl { /// How deeply nested are we? viewport_stack: Vec, + /// What is the last viewport rendered? + last: ViewportId, + // The output of a frame: graphics: ViewportIdMap, output: ViewportIdMap, @@ -1540,6 +1543,8 @@ impl Context { let mut viewports = Vec::new(); self.write(|ctx| { + ctx.last = viewport_id; + ctx.viewports.retain(|_, viewport| { let was_used = viewport.used; @@ -1622,10 +1627,18 @@ impl Context { }) } + /// Tessellate the given shapes into triangle meshes. + /// + /// Will use the last viewport id + pub fn tessellate(&self, shapes: Vec) -> Vec { + let last = self.read(|ctx| ctx.last); + self.tessellate_for(shapes, last) + } + /// Tessellate the given shapes into triangle meshes. /// /// The `viewport_id` is used to get the correct `pixels_per_point`. - pub fn tessellate( + pub fn tessellate_for( &self, shapes: Vec, viewport_id: ViewportId, diff --git a/crates/egui_demo_lib/benches/benchmark.rs b/crates/egui_demo_lib/benches/benchmark.rs index b4e4b1678..dcc55ea6e 100644 --- a/crates/egui_demo_lib/benches/benchmark.rs +++ b/crates/egui_demo_lib/benches/benchmark.rs @@ -1,6 +1,6 @@ use criterion::{criterion_group, criterion_main, Criterion}; -use egui::{epaint::TextShape, ViewportId}; +use egui::epaint::TextShape; use egui_demo_lib::LOREM_IPSUM_LONG; pub fn criterion_benchmark(c: &mut Criterion) { @@ -16,7 +16,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { let full_output = ctx.run(RawInput::default(), |ctx| { demo_windows.ui(ctx); }); - ctx.tessellate(full_output.shapes, ViewportId::ROOT) + ctx.tessellate(full_output.shapes) }); }); @@ -32,7 +32,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { demo_windows.ui(ctx); }); c.bench_function("demo_only_tessellate", |b| { - b.iter(|| ctx.tessellate(full_output.shapes.clone(), ViewportId::ROOT)); + b.iter(|| ctx.tessellate(full_output.shapes.clone())); }); } diff --git a/crates/egui_demo_lib/src/lib.rs b/crates/egui_demo_lib/src/lib.rs index 0c53d9f91..9d7eaa536 100644 --- a/crates/egui_demo_lib/src/lib.rs +++ b/crates/egui_demo_lib/src/lib.rs @@ -18,8 +18,6 @@ pub mod easy_mark; pub use color_test::ColorTest; pub use demo::DemoWindows; -#[cfg(test)] -use egui::ViewportId; /// View some Rust code with syntax highlighting and selection. pub(crate) fn rust_view_ui(ui: &mut egui::Ui, code: &str) { @@ -79,7 +77,7 @@ fn test_egui_e2e() { let full_output = ctx.run(raw_input.clone(), |ctx| { demo_windows.ui(ctx); }); - let clipped_primitives = ctx.tessellate(full_output.shapes, ViewportId::ROOT); + let clipped_primitives = ctx.tessellate(full_output.shapes); assert!(!clipped_primitives.is_empty()); } } @@ -98,7 +96,7 @@ fn test_egui_zero_window_size() { let full_output = ctx.run(raw_input.clone(), |ctx| { demo_windows.ui(ctx); }); - let clipped_primitives = ctx.tessellate(full_output.shapes, ViewportId::ROOT); + let clipped_primitives = ctx.tessellate(full_output.shapes); assert!( clipped_primitives.is_empty(), "There should be nothing to show, has at least one primitive with clip_rect: {:?}", diff --git a/crates/egui_glow/src/winit.rs b/crates/egui_glow/src/winit.rs index 54e6701c6..f2cadd05a 100644 --- a/crates/egui_glow/src/winit.rs +++ b/crates/egui_glow/src/winit.rs @@ -77,7 +77,7 @@ impl EguiGlow { self.painter.set_texture(id, &image_delta); } - let clipped_primitives = self.egui_ctx.tessellate(shapes, ViewportId::ROOT); + let clipped_primitives = self.egui_ctx.tessellate(shapes); let dimensions: [u32; 2] = window.inner_size().into(); self.painter.paint_primitives( dimensions,