diff options
| author | Micha White <botahamec@outlook.com> | 2022-11-19 12:37:29 -0500 |
|---|---|---|
| committer | Micha White <botahamec@outlook.com> | 2022-11-19 12:37:29 -0500 |
| commit | b8a8aa64e7eee45a9f17a3079c836a251cc1b873 (patch) | |
| tree | 0212eb10c8e5cccd871effbe5c86142b613c9399 | |
| parent | 20b0a802225da2668263c93b492a49d25714598e (diff) | |
Ultimately decided to remove the atlas for now
| -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 |
