mirror of
https://github.com/emilk/egui.git
synced 2026-09-03 23:30:04 -04:00
Optimize tessellation of filled circles (#1616)
When painting a scatter plot we sometimes want to paint hundreds of thousands of points (filled circles) on screen every frame. In this PR the font texture atlas is pre-populated with some filled circled of various radii. These are then used when painting (small) filled circled, which means A LOT less triangles and vertices are generated for them. In a new benchmark we can see a 10x speedup in circle tessellation, but the the real benefit comes in the painting of these circles: since we generate a lot less vertices, the backend painter has less to do. In a real-life scenario with a lot of things being painted (including around 100k points) I saw tessellation go from 35ms -> 7ms and painting go from 45ms -> 1ms. This means the total frame time went from 80ms to 8ms, or a 10x speedup.
This commit is contained in:
@@ -124,8 +124,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
|
||||
let galley = fonts.layout(LOREM_IPSUM_LONG.to_owned(), font_id, color, wrap_width);
|
||||
let font_image_size = fonts.font_image_size();
|
||||
let mut tessellator =
|
||||
egui::epaint::Tessellator::new(1.0, Default::default(), font_image_size);
|
||||
let prepared_discs = fonts.texture_atlas().lock().prepared_discs();
|
||||
let mut tessellator = egui::epaint::Tessellator::new(
|
||||
1.0,
|
||||
Default::default(),
|
||||
font_image_size,
|
||||
prepared_discs,
|
||||
);
|
||||
let mut mesh = egui::epaint::Mesh::default();
|
||||
let text_shape = TextShape::new(egui::Pos2::ZERO, galley);
|
||||
c.bench_function("tessellate_text", |b| {
|
||||
|
||||
@@ -158,6 +158,20 @@ impl View for MiscDemoWindow {
|
||||
painter.line_segment([c, c + r * Vec2::angled(TAU * 3.0 / 8.0)], stroke);
|
||||
});
|
||||
});
|
||||
|
||||
CollapsingHeader::new("Many circles of different sizes")
|
||||
.default_open(false)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal_wrapped(|ui| {
|
||||
for i in 0..100 {
|
||||
let r = i as f32 * 0.5;
|
||||
let size = Vec2::splat(2.0 * r + 5.0);
|
||||
let (rect, _response) = ui.allocate_at_least(size, Sense::hover());
|
||||
ui.painter()
|
||||
.circle_filled(rect.center(), r, ui.visuals().text_color());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user