diff options
Diffstat (limited to 'src/texture.rs')
| -rw-r--r-- | src/texture.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/texture.rs b/src/texture.rs index 3b998a8..ee9ff26 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -13,6 +13,7 @@ use thiserror::Error; static NEXT_TEXTURE_ID: AtomicUsize = AtomicUsize::new(0); +/// The unique ID for a subtexture #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct TextureId(usize); @@ -23,7 +24,9 @@ impl TextureId { } } +/// These are the formats supported by the renderer. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[non_exhaustive] pub enum ImageFormat { Bmp, Ico, @@ -40,10 +43,12 @@ impl ImageFormat { } } +/// The texture did not fit in the texture atlas #[derive(Debug, Error)] #[error("{:?}", .0)] pub struct PackError(PackErrorInternal); +// TODO this can be removed when a new texture packer is made type PackErrorInternal = impl std::fmt::Debug; #[derive(Error, Debug)] @@ -73,6 +78,7 @@ impl From<ImageError> for TextureError { } } +/// Simpler constructor for a wgpu extent3d const fn extent_3d(width: u32, height: u32) -> wgpu::Extent3d { wgpu::Extent3d { width, @@ -81,6 +87,7 @@ const fn extent_3d(width: u32, height: u32) -> wgpu::Extent3d { } } +/// A texture atlas, usable by the renderer // TODO make this Debug // TODO make these resizable pub struct TextureAtlas { @@ -190,10 +197,12 @@ impl TextureAtlas { ) } + /// get the bind group for the texture pub(crate) const fn bind_group(&self) -> &wgpu::BindGroup { &self.diffuse_bind_group } + /// Load a new subtexture from memory // TODO support RGBA16 pub fn load_from_memory( &mut self, @@ -204,12 +213,14 @@ impl TextureAtlas { Ok(self.pack_rgba8(img)?) } + /// Add a new subtexture pub fn pack_rgba8(&mut self, img: RgbaImage) -> Result<TextureId, PackError> { let id = TextureId::new(); self.packer.pack_own(id, img).map_err(PackError)?; Ok(id) } + /// Get the frame for s particular subtexture fn texture_frame(&self, id: TextureId) -> Option<&texture_packer::Frame<TextureId>> { self.packer.get_frame(&id) } @@ -219,6 +230,7 @@ impl TextureAtlas { texture_info!(texture_x, x, width); texture_info!(texture_y, y, height); + /// Fill the cached image fn fill_image(&mut self) -> ExportResult<()> { let atlas = { profiling::scope!("export atlas"); @@ -231,6 +243,7 @@ impl TextureAtlas { Ok(()) } + /// Clear the texture atlas pub fn clear(&mut self) { self.packer = TexturePacker::new_skyline(TexturePackerConfig { max_width: self.width, @@ -239,6 +252,7 @@ impl TextureAtlas { }); } + /// Fill the GPU texture atlas #[profiling::function] pub fn fill_textures(&mut self, queue: &wgpu::Queue) { // saves time if nothing changed since the last time we did this |
