diff options
| author | HampusM <hampus@hampusmat.com> | 2026-08-26 15:47:18 +0200 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-08-26 15:47:18 +0200 |
| commit | 5511abdfd118c6d083c24ccbdb4244960846501c (patch) | |
| tree | 415c0f27b0c27e0e3f4116f3277d41997236c0b0 /opengl-bindings | |
| parent | 6d710fbc218ae316bf97885902a68567d2751d36 (diff) | |
refactor(opengl-bindings): include srgb(a) & data type in texture::PixelDataFormat
Diffstat (limited to 'opengl-bindings')
| -rw-r--r-- | opengl-bindings/src/texture.rs | 124 |
1 files changed, 71 insertions, 53 deletions
diff --git a/opengl-bindings/src/texture.rs b/opengl-bindings/src/texture.rs index 2f32bc9..9ed7926 100644 --- a/opengl-bindings/src/texture.rs +++ b/opengl-bindings/src/texture.rs @@ -7,7 +7,6 @@ use crate::MaybeCurrentContextWithFns; pub struct Builder { size: Dimens<u32>, - color_space: ColorSpace, mipmap_levels: u16, } @@ -19,12 +18,6 @@ impl Builder self } - pub fn color_space(mut self, color_space: ColorSpace) -> Self - { - self.color_space = color_space; - self - } - pub fn mipmap_levels(mut self, mipmap_levels: u16) -> Self { self.mipmap_levels = mipmap_levels; @@ -51,13 +44,7 @@ impl Builder let texture = Texture::new(current_context, crate::sys::TEXTURE_2D); - texture.alloc_2d( - current_context, - self.mipmap_levels, - pixel_data_format, - self.color_space, - size, - ); + texture.alloc_2d(current_context, self.mipmap_levels, pixel_data_format, size); texture.sub_image_2d( current_context, @@ -97,13 +84,7 @@ impl Builder let texture = Texture::new(current_context, crate::sys::TEXTURE_CUBE_MAP); - texture.alloc_2d( - current_context, - self.mipmap_levels, - pixel_data_format, - self.color_space, - size, - ); + texture.alloc_2d(current_context, self.mipmap_levels, pixel_data_format, size); for (face, image) in images { texture.sub_image_3d( @@ -128,7 +109,6 @@ impl Default for Builder { Self { size: Dimens::default(), - color_space: ColorSpace::default(), mipmap_levels: 1, } } @@ -316,7 +296,6 @@ impl Texture current_context: &MaybeCurrentContextWithFns, mipmap_levels: u16, pixel_data_format: PixelDataFormat, - color_space: ColorSpace, size: [crate::sys::types::GLsizei; 2], ) { @@ -324,7 +303,7 @@ impl Texture current_context.fns().TextureStorage2D( self.texture, mipmap_levels.into(), - pixel_data_format.to_sized_internal_format(color_space), + pixel_data_format.into_gl_sized_internal_format(), size[0], size[1], ); @@ -349,8 +328,8 @@ impl Texture offset[1], size[0], size[1], - pixel_data_format.to_format(), - crate::sys::UNSIGNED_BYTE, + pixel_data_format.into_gl_format(), + pixel_data_format.into_gl_data_type(), image.as_ptr().cast(), ); } @@ -376,8 +355,8 @@ impl Texture size[0], size[1], size[2], - pixel_data_format.to_format(), - crate::sys::UNSIGNED_BYTE, + pixel_data_format.into_gl_format(), + pixel_data_format.into_gl_data_type(), image.as_ptr().cast(), ); } @@ -410,55 +389,94 @@ pub enum Filtering Linear = const { try_cast_u32_to_i32(crate::sys::LINEAR) }, } +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +#[repr(u32)] +pub enum RgbDataType +{ + UnsignedByte = crate::sys::UNSIGNED_BYTE, +} + +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +#[repr(u32)] +pub enum RgbaDataType +{ + UnsignedByte = crate::sys::UNSIGNED_BYTE, +} + +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +#[repr(u32)] +pub enum SrgbDataType +{ + UnsignedByte = crate::sys::UNSIGNED_BYTE, +} + +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] +#[repr(u32)] +pub enum SrgbaDataType +{ + UnsignedByte = crate::sys::UNSIGNED_BYTE, +} + /// Texture pixel data format. -#[derive(Debug, Clone, Copy, Default)] +#[derive(Debug, Clone, Copy)] +#[non_exhaustive] pub enum PixelDataFormat { - Rgb8, - - #[default] - Rgba8, + Rgb(RgbDataType), + Rgba(RgbaDataType), + Srgb(SrgbDataType), + Srgba(SrgbaDataType), } impl PixelDataFormat { - fn to_sized_internal_format( - self, - color_space: ColorSpace, - ) -> crate::sys::types::GLenum + fn into_gl_sized_internal_format(self) -> crate::sys::types::GLenum { - match (self, color_space) { - (Self::Rgb8, ColorSpace::Linear) => crate::sys::RGB8, - (Self::Rgba8, ColorSpace::Linear) => crate::sys::RGBA8, - (Self::Rgb8, ColorSpace::Srgb) => crate::sys::SRGB8, - (Self::Rgba8, ColorSpace::Srgb) => crate::sys::SRGB8_ALPHA8, + match self { + Self::Rgb(RgbDataType::UnsignedByte) => crate::sys::RGB8, + Self::Rgba(RgbaDataType::UnsignedByte) => crate::sys::RGBA8, + Self::Srgb(SrgbDataType::UnsignedByte) => crate::sys::SRGB8, + Self::Srgba(SrgbaDataType::UnsignedByte) => crate::sys::SRGB8_ALPHA8, } } - fn to_format(self) -> crate::sys::types::GLenum + fn into_gl_format(self) -> crate::sys::types::GLenum { match self { - Self::Rgb8 => crate::sys::RGB, - Self::Rgba8 => crate::sys::RGBA, + Self::Rgb(_) | Self::Srgb(_) => crate::sys::RGB, + Self::Rgba(_) | Self::Srgba(_) => crate::sys::RGBA, + } + } + + fn into_gl_data_type(self) -> crate::sys::types::GLenum + { + match self { + Self::Rgb(ty) => ty as crate::sys::types::GLenum, + Self::Srgb(ty) => ty as crate::sys::types::GLenum, + Self::Rgba(ty) => ty as crate::sys::types::GLenum, + Self::Srgba(ty) => ty as crate::sys::types::GLenum, } } fn pixel_width(&self) -> usize { match self { - Self::Rgb8 => 3, - Self::Rgba8 => 4, + Self::Rgb(_) | Self::Srgb(_) => 3, + Self::Rgba(_) | Self::Srgba(_) => 4, } } } -#[derive(Debug, Clone, Copy, Default)] -#[non_exhaustive] -pub enum ColorSpace +impl Default for PixelDataFormat { - #[default] - Linear, - Srgb, + fn default() -> Self + { + PixelDataFormat::Rgba(RgbaDataType::UnsignedByte) + } } #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] |
