summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-03-26 14:28:11 +0100
committerHampusM <hampus@hampusmat.com>2026-03-26 14:28:11 +0100
commitbf024cf66bd64840faed19e0c35ee0c40ba6b3c6 (patch)
tree503a66730afa1c7febbf438e20d7e1912dd40e1a
parentde74c71eb6d6a67e8c7ac006a1e906175ca32a72 (diff)
feat(opengl-bindings): add SRGB texture support
-rw-r--r--opengl-bindings/src/texture.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/opengl-bindings/src/texture.rs b/opengl-bindings/src/texture.rs
index 2683772..c5d43c9 100644
--- a/opengl-bindings/src/texture.rs
+++ b/opengl-bindings/src/texture.rs
@@ -48,6 +48,7 @@ impl Texture
size: &Dimens<u32>,
data: &[u8],
pixel_data_format: PixelDataFormat,
+ color_space: ColorSpace,
) -> Result<(), GenerateError>
{
let size = Dimens::<crate::sys::types::GLsizei> {
@@ -65,7 +66,7 @@ impl Texture
})?,
};
- self.alloc_image(current_context, pixel_data_format, &size, data);
+ self.alloc_image(current_context, pixel_data_format, color_space, &size, data);
unsafe {
current_context.fns().GenerateTextureMipmap(self.texture);
@@ -148,6 +149,7 @@ impl Texture
&self,
current_context: &CurrentContextWithFns<'_>,
pixel_data_format: PixelDataFormat,
+ color_space: ColorSpace,
size: &Dimens<crate::sys::types::GLsizei>,
data: &[u8],
)
@@ -156,7 +158,7 @@ impl Texture
current_context.fns().TextureStorage2D(
self.texture,
1,
- pixel_data_format.to_sized_internal_format(),
+ pixel_data_format.to_sized_internal_format(color_space),
size.width,
size.height,
);
@@ -212,11 +214,16 @@ pub enum PixelDataFormat
impl PixelDataFormat
{
- fn to_sized_internal_format(self) -> crate::sys::types::GLenum
+ fn to_sized_internal_format(
+ self,
+ color_space: ColorSpace,
+ ) -> crate::sys::types::GLenum
{
- match self {
- Self::Rgb8 => crate::sys::RGB8,
- Self::Rgba8 => crate::sys::RGBA8,
+ 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,
}
}
@@ -229,6 +236,14 @@ impl PixelDataFormat
}
}
+#[derive(Debug, Clone, Copy)]
+#[non_exhaustive]
+pub enum ColorSpace
+{
+ Linear,
+ Srgb,
+}
+
/// Error generating texture.
#[derive(Debug, thiserror::Error)]
pub enum GenerateError