Deallocate atlas entries and remove padding
This commit is contained in:
parent
48d70280eb
commit
d06d06e050
5 changed files with 82 additions and 44 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue