1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -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:
Emil Ernerfeldt
2022-05-10 19:31:19 +02:00
committed by GitHub
parent 28efc0e1c8
commit 7b18fab7a4
12 changed files with 232 additions and 23 deletions

View File

@@ -394,6 +394,12 @@ impl Fonts {
self.lock().fonts.max_texture_side
}
/// The font atlas.
/// Pass this to [`crate::Tessellator`].
pub fn texture_atlas(&self) -> Arc<Mutex<TextureAtlas>> {
self.lock().fonts.atlas.clone()
}
/// Current size of the font image.
/// Pass this to [`crate::Tessellator`].
pub fn font_image_size(&self) -> [usize; 2] {
@@ -535,14 +541,7 @@ impl FontsImpl {
let texture_width = max_texture_side.at_most(8 * 1024);
let initial_height = 64;
let mut atlas = TextureAtlas::new([texture_width, initial_height]);
{
// Make the top left pixel fully white:
let (pos, image) = atlas.allocate((1, 1));
assert_eq!(pos, (0, 0));
image[pos] = 1.0;
}
let atlas = TextureAtlas::new([texture_width, initial_height]);
let atlas = Arc::new(Mutex::new(atlas));

View File

@@ -401,7 +401,7 @@ pub struct Glyph {
pub pos: Pos2,
/// Advance width and font row height.
pub size: Vec2,
/// Position of the glyph in the font texture.
/// Position of the glyph in the font texture, in texels.
pub uv_rect: UvRect,
/// Index into [`LayoutJob::sections`]. Decides color etc.
pub section_index: u32,