From 67023d6a095f457a2579367d59d13c6c804e7108 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 12 Nov 2023 13:40:49 +0100 Subject: feat(engine): add support for textures with 8-bit rgba data --- engine/src/texture.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'engine/src/texture.rs') diff --git a/engine/src/texture.rs b/engine/src/texture.rs index 7874df4..bde3cd2 100644 --- a/engine/src/texture.rs +++ b/engine/src/texture.rs @@ -3,7 +3,7 @@ use std::path::Path; use image::io::Reader as ImageReader; use image::{DynamicImage, ImageError}; -use crate::opengl::texture::Texture as InnerTexture; +use crate::opengl::texture::{PixelDataFormat, Texture as InnerTexture}; use crate::vector::Vec2; mod reexports @@ -35,9 +35,13 @@ impl Texture .decode() .map_err(Error::DecodeImageFailed)?; - if !matches!(image, DynamicImage::ImageRgb8(_)) { - return Err(Error::UnsupportedImageDataKind); - } + let pixel_data_format = match &image { + DynamicImage::ImageRgb8(_) => PixelDataFormat::Rgb, + DynamicImage::ImageRgba8(_) => PixelDataFormat::Rgba, + _ => { + return Err(Error::UnsupportedImageDataKind); + } + }; let inner = InnerTexture::new(); @@ -46,6 +50,7 @@ impl Texture &texture_curr_bound, &Vec2 { x: image.width(), y: image.height() }, image.as_bytes(), + pixel_data_format, ); }); -- cgit v1.2.3-18-g5258