diff options
Diffstat (limited to 'src/texture.rs')
| -rw-r--r-- | src/texture.rs | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/src/texture.rs b/src/texture.rs index ac2dd63..3b998a8 100644 --- a/src/texture.rs +++ b/src/texture.rs @@ -40,14 +40,26 @@ impl ImageFormat { } } -type PackError = impl std::fmt::Debug; +#[derive(Debug, Error)] +#[error("{:?}", .0)] +pub struct PackError(PackErrorInternal); + +type PackErrorInternal = impl std::fmt::Debug; #[derive(Error, Debug)] pub enum TextureError { #[error("{:?}", .0)] - TextureTooLarge(PackError), // use an error with a source + TextureTooLarge( + #[source] + #[from] + PackError, + ), #[error("{}", .0)] - BadImage(#[source] DecodingError), // TODO don't export this + BadImage( + #[source] + #[from] + DecodingError, + ), // TODO don't export this #[error("Unexpected Error (this is a bug in alligator_render): {}", .0)] Unexpected(#[source] Box<dyn Error>), } @@ -55,7 +67,7 @@ pub enum TextureError { impl From<ImageError> for TextureError { fn from(ie: ImageError) -> Self { match ie { - ImageError::Decoding(de) => Self::BadImage(de), + ImageError::Decoding(de) => de.into(), _ => Self::Unexpected(Box::new(ie)), } } @@ -189,11 +201,12 @@ impl TextureAtlas { format: ImageFormat, ) -> Result<TextureId, TextureError> { let img = image::load_from_memory_with_format(buf, format.format())?.into_rgba8(); - let id = TextureId::new(); - self.packer - .pack_own(id, img) - .map_err(TextureError::TextureTooLarge)?; + Ok(self.pack_rgba8(img)?) + } + 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) } |
