@@ -214,6 +214,9 @@ pub struct GlyphBrush<'a, R: gfx::Resources, F: gfx::Factory<R>>{
214
214
// to be rendered on the next `draw_queued` call
215
215
section_buffer : Vec < u64 > ,
216
216
217
+ // Set of section hashs to keep in the glyph cache this frame even if they haven't been drawn
218
+ keep_in_cache : HashSet < u64 > ,
219
+
217
220
// config
218
221
gpu_cache_scale_tolerance : f32 ,
219
222
gpu_cache_position_tolerance : f32 ,
@@ -241,6 +244,7 @@ impl<'font, R: gfx::Resources, F: gfx::Factory<R>> GlyphBrush<'font, R, F> {
241
244
let mut no_match = true ;
242
245
243
246
let section_hash = self . cache_glyphs ( & section, custom_layout) ;
247
+ self . keep_in_cache . insert ( section_hash) ;
244
248
245
249
for g in & self . calculate_glyph_cache [ & section_hash] . glyphs {
246
250
if let Some ( Rect { min, max } ) = g. pixel_bounding_box ( ) {
@@ -521,15 +525,22 @@ impl<'font, R: gfx::Resources, F: gfx::Factory<R>> GlyphBrush<'font, R, F> {
521
525
fn clear_section_buffer ( & mut self ) {
522
526
if self . cache_glyph_positioning {
523
527
// clear section_buffer & trim calculate_glyph_cache to active sections
524
- let mut active = HashSet :: with_capacity ( self . section_buffer . len ( ) ) ;
528
+ let mut active = HashSet :: with_capacity (
529
+ self . section_buffer . len ( ) + self . keep_in_cache . len ( )
530
+ ) ;
531
+
525
532
for h in self . section_buffer . drain ( ..) {
526
533
active. insert ( h) ;
527
534
}
535
+ for h in self . keep_in_cache . drain ( ) {
536
+ active. insert ( h) ;
537
+ }
528
538
self . calculate_glyph_cache . retain ( |key, _| active. contains ( key) ) ;
529
539
}
530
540
else {
531
541
self . section_buffer . clear ( ) ;
532
542
self . calculate_glyph_cache . clear ( ) ;
543
+ self . keep_in_cache . clear ( ) ;
533
544
}
534
545
}
535
546
@@ -707,6 +718,7 @@ impl<'a> GlyphBrushBuilder<'a> {
707
718
draw_cache : None ,
708
719
section_buffer : Vec :: new ( ) ,
709
720
calculate_glyph_cache : HashMap :: new ( ) ,
721
+ keep_in_cache : HashSet :: new ( ) ,
710
722
711
723
gpu_cache_scale_tolerance : self . gpu_cache_scale_tolerance ,
712
724
gpu_cache_position_tolerance : self . gpu_cache_position_tolerance ,
0 commit comments