diff options
author | 2020-02-26 20:10:19 +0100 | |
---|---|---|
committer | 2020-02-26 20:10:19 +0100 | |
commit | d06d06e05096e0145be74fd02d67eada0a1665a1 (patch) | |
tree | 7e1d5e256d553a4d98c10b7751441d6fa541990f /wgpu/src/texture/atlas.rs | |
parent | 48d70280eb4f5908f1c9339bebdfbab856d55ae1 (diff) | |
download | iced-d06d06e05096e0145be74fd02d67eada0a1665a1.tar.gz iced-d06d06e05096e0145be74fd02d67eada0a1665a1.tar.bz2 iced-d06d06e05096e0145be74fd02d67eada0a1665a1.zip |
Deallocate atlas entries and remove padding
Diffstat (limited to '')
-rw-r--r-- | wgpu/src/texture/atlas.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/wgpu/src/texture/atlas.rs b/wgpu/src/texture/atlas.rs index 3d4e81c1..a76c035b 100644 --- a/wgpu/src/texture/atlas.rs +++ b/wgpu/src/texture/atlas.rs @@ -112,11 +112,47 @@ impl Atlas { } } - log::info!("Current atlas: {:?}", &self); + log::info!("Current atlas: {:?}", self); Some(entry) } + pub fn remove(&mut self, entry: &Entry) { + log::info!("Removing atlas entry: {:?}", entry); + + match entry { + Entry::Contiguous(allocation) => { + self.deallocate(allocation); + } + Entry::Fragmented { fragments, .. } => { + for fragment in fragments { + self.deallocate(&fragment.allocation); + } + } + } + } + + fn deallocate(&mut self, allocation: &Allocation) { + log::info!("Deallocating atlas: {:?}", allocation); + + match allocation { + Allocation::Full { layer } => { + self.layers[*layer] = Layer::Empty; + } + Allocation::Partial { layer, region } => { + let layer = &mut self.layers[*layer]; + + if let Layer::Busy(allocator) = layer { + allocator.deallocate(region); + + if allocator.is_empty() { + *layer = Layer::Empty; + } + } + } + } + } + fn allocate(&mut self, width: u32, height: u32) -> Option<Entry> { // Allocate one layer if texture fits perfectly if width == SIZE && height == SIZE { |