From: Josh Simmons Date: Fri, 15 Nov 2024 22:00:40 +0000 (+0100) Subject: narcissus-font: Fix cache writing wrong rects X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=82415f8825f2f3bbaca27d7d3b0979921360341d;p=josh%2Fnarcissus narcissus-font: Fix cache writing wrong rects The rect id was being set to zero rather than the touched glyph index, so for the first frame after packing the data would always have gaps. --- diff --git a/engine/narcissus-font/src/cache.rs b/engine/narcissus-font/src/cache.rs index 7b62ba6..f34151b 100644 --- a/engine/narcissus-font/src/cache.rs +++ b/engine/narcissus-font/src/cache.rs @@ -150,11 +150,6 @@ where } pub fn update_atlas(&mut self) -> (&[TouchedGlyph], Option<&[u8]>) { - // We might have touched more, or fewer, glyphs this iteration, so - // update the touched glyphs array. - self.touched_glyphs - .resize(self.touched_glyph_lookup.len(), TouchedGlyph::default()); - // We can only repack once. let mut is_emergency_repack = false; @@ -162,6 +157,13 @@ where let cached_glyphs_len = self.cached_glyphs.len(); let sorted_indices = self.cached_glyph_indices_sorted.as_slice(); + // We might have touched more, or fewer, glyphs this iteration, so + // update the touched glyphs array. + if self.touched_glyphs.len() < self.touched_glyph_lookup.len() { + self.touched_glyphs + .resize(self.touched_glyph_lookup.len(), TouchedGlyph::default()); + } + // For each touched glyph, try and find it in our cached glyph list. for (glyph_key, touched_glyph_index) in self.touched_glyph_lookup.iter() { match sorted_indices @@ -213,7 +215,7 @@ where }); self.rects.push(Rect { - id: 0, + id: touched_glyph_index.as_u32() as i32, w, h, x: 0, @@ -248,6 +250,7 @@ where // update. self.cached_glyph_indices_sorted.clear(); self.cached_glyphs.clear(); + self.touched_glyphs.clear(); self.rects.clear(); self.packer.clear(); self.texture.fill(0);