From 908ae3fcaa119f8fcac1aacbf43bac649c75eac6 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 14 Jul 2026 14:14:46 +0200 Subject: refactor(engine): use texture builder in opengl rendering backend --- engine/src/rendering/backend/opengl.rs | 41 +++++++++++++++++----------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/engine/src/rendering/backend/opengl.rs b/engine/src/rendering/backend/opengl.rs index 2394acf..821d039 100644 --- a/engine/src/rendering/backend/opengl.rs +++ b/engine/src/rendering/backend/opengl.rs @@ -48,8 +48,8 @@ use opengl_bindings::shader::{ }; use opengl_bindings::texture::{ ColorSpace as GlTextureColorSpace, + Error as GlTextureGenerateError, Filtering as GlTextureFiltering, - GenerateError as GlTextureGenerateError, PixelDataFormat as GlTexturePixelDataFormat, Texture as GlTexture, Wrapping as GlTextureWrapping, @@ -1175,43 +1175,42 @@ fn draw_mesh( } fn create_gl_texture( - current_context: &MaybeCurrentContextWithFns, + curr_gl_context: &MaybeCurrentContextWithFns, image: &Image, texture_properties: &TextureProperties, ) -> Result { - let gl_texture = GlTexture::new(current_context); - - gl_texture.generate( - current_context, - &image.dimensions().into(), - image.as_bytes(), - match image.color_type() { - ImageColorType::Rgb8 => GlTexturePixelDataFormat::Rgb8, - ImageColorType::Rgba8 => GlTexturePixelDataFormat::Rgba8, - _ => { - unimplemented!(); - } - }, - if image.color_space_is_srgb() { + let gl_texture = GlTexture::builder() + .image( + image.as_bytes(), + match image.color_type() { + ImageColorType::Rgb8 => GlTexturePixelDataFormat::Rgb8, + ImageColorType::Rgba8 => GlTexturePixelDataFormat::Rgba8, + _ => { + unimplemented!(); + } + }, + ) + .size(image.dimensions().into()) + .color_space(if image.color_space_is_srgb() { GlTextureColorSpace::Srgb } else { GlTextureColorSpace::Linear - }, - )?; + }) + .create(curr_gl_context)?; gl_texture.set_wrap( - current_context, + curr_gl_context, texture_wrapping_to_gl(texture_properties.wrap), ); gl_texture.set_magnifying_filter( - current_context, + curr_gl_context, texture_filtering_to_gl(texture_properties.magnifying_filter), ); gl_texture.set_minifying_filter( - current_context, + curr_gl_context, texture_filtering_to_gl(texture_properties.minifying_filter), ); -- cgit v1.2.3-18-g5258