Deallocate atlas entries and remove padding

This commit is contained in:
Héctor Ramón Jiménez 2020-02-26 20:10:19 +01:00
parent 48d70280eb
commit d06d06e050
5 changed files with 82 additions and 44 deletions

View file

@ -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 {