diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index b39defa8..a585782e 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -152,6 +152,9 @@ impl Renderer { self.triangle.end_frame(); self.text.end_frame(); + // TODO: Move to runtime! + self.engine.text_pipeline.trim(); + #[cfg(any(feature = "svg", feature = "image"))] { self.image.end_frame(); diff --git a/wgpu/src/text.rs b/wgpu/src/text.rs index 7f88cac4..05e99396 100644 --- a/wgpu/src/text.rs +++ b/wgpu/src/text.rs @@ -276,6 +276,33 @@ pub struct Pipeline { atlas: Arc>, } +impl Pipeline { + pub fn new( + device: &wgpu::Device, + queue: &wgpu::Queue, + format: wgpu::TextureFormat, + ) -> Self { + let cache = cryoglyph::Cache::new(device); + let atlas = cryoglyph::TextAtlas::with_color_mode( + device, queue, &cache, format, COLOR_MODE, + ); + + Pipeline { + format, + cache, + atlas: Arc::new(RwLock::new(atlas)), + } + } + + pub fn create_viewport(&self, device: &wgpu::Device) -> Viewport { + Viewport(cryoglyph::Viewport::new(device, &self.cache)) + } + + pub fn trim(&self) { + self.atlas.write().expect("Write text atlas").trim(); + } +} + #[derive(Default)] pub struct State { renderers: Vec, @@ -414,29 +441,6 @@ impl State { } } -impl Pipeline { - pub fn new( - device: &wgpu::Device, - queue: &wgpu::Queue, - format: wgpu::TextureFormat, - ) -> Self { - let cache = cryoglyph::Cache::new(device); - let atlas = cryoglyph::TextAtlas::with_color_mode( - device, queue, &cache, format, COLOR_MODE, - ); - - Pipeline { - format, - cache, - atlas: Arc::new(RwLock::new(atlas)), - } - } - - pub fn create_viewport(&self, device: &wgpu::Device) -> Viewport { - Viewport(cryoglyph::Viewport::new(device, &self.cache)) - } -} - fn prepare( device: &wgpu::Device, queue: &wgpu::Queue,