summaryrefslogtreecommitdiff
path: root/engine/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-08-26 15:50:00 +0200
committerHampusM <hampus@hampusmat.com>2026-08-26 15:50:00 +0200
commit1d45911e59b53b598e1af1ebe67ef23396eb8e12 (patch)
tree33f008b54ad88a15c651a5ba853fc95563419202 /engine/src
parent5511abdfd118c6d083c24ccbdb4244960846501c (diff)
refactor(engine): adjust gl rendering backend to opengl-bindings crate changes
Diffstat (limited to 'engine/src')
-rw-r--r--engine/src/rendering/backend/opengl.rs72
1 files changed, 43 insertions, 29 deletions
diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs
index e00faa2..9485e68 100644
--- a/engine/src/rendering/backend/opengl.rs
+++ b/engine/src/rendering/backend/opengl.rs
@@ -49,7 +49,6 @@ use opengl_bindings::shader::{
Shader as GlShader,
};
use opengl_bindings::texture::{
- ColorSpace as GlTextureColorSpace,
CubeMapFace as GlCubeMapTextureFace,
Error as GlTextureError,
Filtering as GlTextureFiltering,
@@ -1384,7 +1383,10 @@ fn update_texture_object(
0,
offset.into(),
texture_image.dimensions().into(),
- color_type_to_pixel_data_format(texture_image.color_type()),
+ create_pixel_data_format(ImageDataProperties {
+ color_type: texture_image.color_type(),
+ is_srgb: texture_image.color_space_is_srgb(),
+ }),
texture_image.as_bytes(),
)?;
@@ -1423,12 +1425,33 @@ fn draw_mesh(
Ok(())
}
-fn color_type_to_pixel_data_format(color_type: ImageColorType)
- -> GlTexturePixelDataFormat
+struct ImageDataProperties
{
- match color_type {
- ImageColorType::Rgb8 => GlTexturePixelDataFormat::Rgb8,
- ImageColorType::Rgba8 => GlTexturePixelDataFormat::Rgba8,
+ color_type: ImageColorType,
+ is_srgb: bool,
+}
+
+fn create_pixel_data_format(
+ image_data_props: ImageDataProperties,
+) -> GlTexturePixelDataFormat
+{
+ match image_data_props.color_type {
+ ImageColorType::Rgb8 if image_data_props.is_srgb => {
+ GlTexturePixelDataFormat::Srgb(
+ opengl_bindings::texture::SrgbDataType::UnsignedByte,
+ )
+ }
+ ImageColorType::Rgb8 => GlTexturePixelDataFormat::Rgb(
+ opengl_bindings::texture::RgbDataType::UnsignedByte,
+ ),
+ ImageColorType::Rgba8 if image_data_props.is_srgb => {
+ GlTexturePixelDataFormat::Srgba(
+ opengl_bindings::texture::SrgbaDataType::UnsignedByte,
+ )
+ }
+ ImageColorType::Rgba8 => GlTexturePixelDataFormat::Rgba(
+ opengl_bindings::texture::RgbaDataType::UnsignedByte,
+ ),
_ => {
unimplemented!();
}
@@ -1444,33 +1467,24 @@ fn create_gl_texture(
let gl_texture = match texture_things {
TextureCreationData::Texture2D { image } => GlTexture::builder()
.size(image.dimensions().into())
- .color_space(if image.color_space_is_srgb() {
- GlTextureColorSpace::Srgb
- } else {
- GlTextureColorSpace::Linear
- })
.create_2d(
curr_gl_context,
image.as_bytes(),
- color_type_to_pixel_data_format(image.color_type()),
+ create_pixel_data_format(ImageDataProperties {
+ color_type: image.color_type(),
+ is_srgb: image.color_space_is_srgb(),
+ }),
),
TextureCreationData::CubeMap { images, color_type, is_srgb, size } => {
- GlTexture::builder()
- .size(size.into())
- .color_space(if is_srgb {
- GlTextureColorSpace::Srgb
- } else {
- GlTextureColorSpace::Linear
- })
- .create_cube_map(
- curr_gl_context,
- std::array::from_fn::<_, 6, _>(|index| {
- let (face, image) = &images[index];
-
- (cube_map_texture_face_to_gl(*face), image.as_bytes())
- }),
- color_type_to_pixel_data_format(color_type),
- )
+ GlTexture::builder().size(size.into()).create_cube_map(
+ curr_gl_context,
+ std::array::from_fn::<_, 6, _>(|index| {
+ let (face, image) = &images[index];
+
+ (cube_map_texture_face_to_gl(*face), image.as_bytes())
+ }),
+ create_pixel_data_format(ImageDataProperties { color_type, is_srgb }),
+ )
}
}?;