mirror of
https://github.com/emilk/egui.git
synced 2026-09-01 14:20: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:
@@ -830,14 +830,17 @@ impl Context {
|
||||
|
||||
let pixels_per_point = self.pixels_per_point();
|
||||
let tessellation_options = *self.tessellation_options();
|
||||
let font_image_size = self.fonts().font_image_size();
|
||||
let texture_atlas = self.fonts().texture_atlas();
|
||||
let font_tex_size = texture_atlas.lock().size();
|
||||
let prepared_discs = texture_atlas.lock().prepared_discs();
|
||||
|
||||
let paint_stats = PaintStats::from_shapes(&shapes);
|
||||
let clipped_primitives = tessellator::tessellate_shapes(
|
||||
pixels_per_point,
|
||||
tessellation_options,
|
||||
font_tex_size,
|
||||
prepared_discs,
|
||||
shapes,
|
||||
font_image_size,
|
||||
);
|
||||
self.write().paint_stats = paint_stats.with_clipped_primitives(&clipped_primitives);
|
||||
clipped_primitives
|
||||
|
||||
@@ -142,6 +142,7 @@ impl Widget for &mut epaint::TessellationOptions {
|
||||
feathering,
|
||||
feathering_size_in_pixels,
|
||||
coarse_tessellation_culling,
|
||||
prerasterized_discs,
|
||||
round_text_to_pixels,
|
||||
debug_paint_clip_rects,
|
||||
debug_paint_text_rects,
|
||||
@@ -158,6 +159,8 @@ impl Widget for &mut epaint::TessellationOptions {
|
||||
.text("Feathering size in pixels");
|
||||
ui.add_enabled(*feathering, feathering_slider);
|
||||
|
||||
ui.checkbox(prerasterized_discs, "Speed up filled circles with pre-rasterization");
|
||||
|
||||
ui.add(
|
||||
crate::widgets::Slider::new(bezier_tolerance, 0.0001..=10.0)
|
||||
.logarithmic(true)
|
||||
|
||||
Reference in New Issue
Block a user