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/opengl/texture.rs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'engine/src/opengl/texture.rs') diff --git a/engine/src/opengl/texture.rs b/engine/src/opengl/texture.rs index c7bf75b..68ac050 100644 --- a/engine/src/opengl/texture.rs +++ b/engine/src/opengl/texture.rs @@ -32,18 +32,23 @@ impl Texture cb(currently_bound); } - pub fn generate(_: &CurrentlyBound, dimens: &Vec2, data: &[u8]) + pub fn generate( + _: &CurrentlyBound, + dimens: &Vec2, + data: &[u8], + pixel_data_format: PixelDataFormat, + ) { #[allow(clippy::cast_possible_wrap)] unsafe { gl::TexImage2D( gl::TEXTURE_2D, 0, - gl::RGB as i32, + pixel_data_format.to_gl() as i32, dimens.x as i32, dimens.y as i32, 0, - gl::RGB, + pixel_data_format.to_gl(), gl::UNSIGNED_BYTE, data.as_ptr().cast(), ); @@ -142,3 +147,22 @@ impl Filtering } } } + +/// Texture pixel data format. +#[derive(Debug, Clone, Copy)] +pub enum PixelDataFormat +{ + Rgb, + Rgba, +} + +impl PixelDataFormat +{ + fn to_gl(self) -> gl::types::GLenum + { + match self { + Self::Rgb => gl::RGB, + Self::Rgba => gl::RGBA, + } + } +} -- cgit v1.2.3-18-g5258