diff --git a/src/app.rs b/src/app.rs index ec168ef..c8bac5a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -562,7 +562,12 @@ impl eframe::App for TemplateApp { if let Some(ref cache) = self.text_cache { ui.separator(); - ui.label(format!("Text cache: {} entries", cache.cache_size())); + let bytes = cache.cache_memory_bytes(); + let mb = bytes as f32 / (1024.0 * 1024.0); + ui.label(format!( + "Text cache: {} entries (~{mb:.2} MB)", + cache.cache_size() + )); } }); } diff --git a/src/text_cache.rs b/src/text_cache.rs index 9d1faff..a65c1f2 100644 --- a/src/text_cache.rs +++ b/src/text_cache.rs @@ -23,7 +23,7 @@ const TEXTURE_OPTIONS: TextureOptions = TextureOptions { }; /// Maximum texture dimension to prevent memory issues. -const MAX_TEXTURE_DIM: u32 = 4096; +const MAX_TEXTURE_DIM: u32 = 8192; /// Maximum pixel count (16M pixels = 64MB for RGBA). const MAX_PIXEL_COUNT: usize = 16 * 1024 * 1024; @@ -74,6 +74,14 @@ impl TextCache { self.cache.len() } + /// Returns approximate GPU memory used by cached text textures (bytes). + pub fn cache_memory_bytes(&self) -> usize { + self.cache + .values() + .map(|cached| cached.width as usize * cached.height as usize * 4) + .sum() + } + /// Get or create a cached texture for the given text. /// /// The texture is rendered at the smallest available render scale that can