summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-07-14 14:14:46 +0200
committerHampusM <hampus@hampusmat.com>2026-07-14 14:14:46 +0200
commit908ae3fcaa119f8fcac1aacbf43bac649c75eac6 (patch)
tree25a3757706e7bf941cf71c99c321f368bcca28a1
parent9f465af5044a4fef0061433e85a4e2c28b0ae61c (diff)
refactor(engine): use texture builder in opengl rendering backend
-rw-r--r--engine/src/rendering/backend/opengl.rs41
1 files 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<GlTexture, GlTextureGenerateError>
{
- 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),
);