From 0ea3a53d97fc2b9814d0ec0d8f72b6b4cd90d769 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 9 Sep 2020 15:24:44 +0200 Subject: [PATCH] [font] texture atlas: add one pixel of padding for old GPUs --- egui/src/paint/texture_atlas.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/egui/src/paint/texture_atlas.rs b/egui/src/paint/texture_atlas.rs index c9f5f6d8..546f21c2 100644 --- a/egui/src/paint/texture_atlas.rs +++ b/egui/src/paint/texture_atlas.rs @@ -61,18 +61,18 @@ impl TextureAtlas { &mut self.texture } - pub fn clear(&mut self) { - self.cursor = (0, 0); - self.row_height = 0; - } - /// Returns the coordinates of where the rect ended up. pub fn allocate(&mut self, (w, h): (usize, usize)) -> (usize, usize) { + /// On some low-precision GPUs (my old iPad) characters get muddled up + /// if we don't add some empty pixels between the characters. + /// On modern high-precision GPUs this is not be needed. + const PADDING: usize = 1; + assert!(w <= self.texture.width); if self.cursor.0 + w > self.texture.width { // New row: self.cursor.0 = 0; - self.cursor.1 += self.row_height; + self.cursor.1 += self.row_height + PADDING; self.row_height = 0; } @@ -88,7 +88,7 @@ impl TextureAtlas { } let pos = self.cursor; - self.cursor.0 += w; + self.cursor.0 += w + PADDING; self.texture.version += 1; (pos.0 as usize, pos.1 as usize) }