From b8a8aa64e7eee45a9f17a3079c836a251cc1b873 Mon Sep 17 00:00:00 2001 From: Micha White Date: Sat, 19 Nov 2022 12:37:29 -0500 Subject: Ultimately decided to remove the atlas for now --- alligator_resources/src/texture.rs | 32 ++++++++------------------------ 1 file 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, 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 -- cgit v1.2.3