diff options
Diffstat (limited to 'alligator_resources/src')
| -rw-r--r-- | alligator_resources/src/texture.rs | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/alligator_resources/src/texture.rs b/alligator_resources/src/texture.rs index 9aca56d..22cad17 100644 --- a/alligator_resources/src/texture.rs +++ b/alligator_resources/src/texture.rs @@ -122,7 +122,11 @@ impl TextureFile { } fn unload(&mut self) { - self.texture = None; + if let Some(arc) = &self.texture { + if Arc::strong_count(arc) == 1 { + self.texture = None; + } + } } fn allocated_size(&self) -> usize { @@ -221,6 +225,7 @@ pub struct TextureManager { textures: HashMap<TextureId, Texture>, packer: TexturePacker<'static, Rgba16Texture, TextureId>, atlas: Rgba16Texture, // cached texture atlas + max_size: usize, width: u32, height: u32, } @@ -250,6 +255,7 @@ impl TextureManager { pub fn new(config: TextureConfig) -> Self { let width = config.atlas_width; let height = config.atlas_height; + let max_size = config.max_size; let textures = HashMap::with_capacity(config.initial_capacity); let packer = packer(width, height); @@ -262,34 +268,12 @@ impl TextureManager { textures, packer, atlas, + max_size, width, height, } } - pub fn load_to_atlas(&mut self, id: TextureId, texture: &TextureRef) { - let get_texture = || texture.texture().clone(); - - if self.packer.pack_own(id, get_texture()).is_err() { - let texture = get_texture(); - self.resize_atlas(self.width + texture.width(), self.height + texture.height()); - - self.packer - .pack_own(id, get_texture()) - .expect("packer is still too small after resizing"); - } - } - - /// Clear and resize the texture atlas - pub fn resize_atlas(&mut self, width: u32, height: u32) { - self.packer = packer(width, height); - } - - /// Clear the texture atlas - pub fn clear_atlas(&mut self) { - self.packer = packer(self.width, self.height); - } - /// Loads a texture from memory in the given format. /// /// # Errors |
