From e1443308e60e1b8e93acf5ea56a0310561c4d4c9 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 26 Aug 2026 16:30:40 +0200 Subject: feat(opengl-bindings): make textures creatable without pixel data --- opengl-bindings/src/texture.rs | 51 ++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/opengl-bindings/src/texture.rs b/opengl-bindings/src/texture.rs index 4bf8ac6..b0b729f 100644 --- a/opengl-bindings/src/texture.rs +++ b/opengl-bindings/src/texture.rs @@ -28,17 +28,19 @@ impl Builder pub fn create_2d<'image>( &self, current_context: &MaybeCurrentContextWithFns, - image: impl Into>, + image: Option>>, pixel_data_format: PixelDataFormat, ) -> Result { - let image = image.into(); + let image = image.map(Into::into); - check_image_buffer_len_correct_for_size( - image.as_ref(), - [self.size.width, self.size.height, 1], - pixel_data_format, - )?; + if let Some(image) = &image { + check_image_buffer_len_correct_for_size( + image.as_ref(), + [self.size.width, self.size.height, 1], + pixel_data_format, + )?; + } let size = try_convert_size([self.size.width, self.size.height])?; @@ -46,16 +48,18 @@ impl Builder texture.alloc_2d(current_context, self.mipmap_levels, pixel_data_format, size); - texture.sub_image_2d( - current_context, - 0, - [0, 0], - size, - pixel_data_format, - image.as_ref(), - ); + if let Some(image) = &image { + texture.sub_image_2d( + current_context, + 0, + [0, 0], + size, + pixel_data_format, + image.as_ref(), + ); - texture.generate_mipmap(current_context); + texture.generate_mipmap(current_context); + } Ok(texture) } @@ -64,15 +68,16 @@ impl Builder pub fn create_cube_map<'image, Image>( &self, current_context: &MaybeCurrentContextWithFns, - images: [(CubeMapFace, Image); 6], + images: Option<[(CubeMapFace, Image); 6]>, pixel_data_format: PixelDataFormat, ) -> Result where Image: Into>, { - let images = images.map(|(face, image)| (face, image.into())); + let images = + images.map(|images| images.map(|(face, image)| (face, image.into()))); - for (_, image) in &images { + for (_, image) in images.iter().flatten() { check_image_buffer_len_correct_for_size( image.as_ref(), [self.size.width, self.size.height, 1], @@ -86,18 +91,20 @@ impl Builder texture.alloc_2d(current_context, self.mipmap_levels, pixel_data_format, size); - for (face, image) in images { + for (face, image) in images.iter().flatten() { texture.sub_image_3d( current_context, 0, - [0, 0, face as crate::sys::types::GLint], + [0, 0, *face as crate::sys::types::GLint], [size[0], size[1], 1], pixel_data_format, image.as_ref(), ); } - texture.generate_mipmap(current_context); + if images.is_some() { + texture.generate_mipmap(current_context); + } Ok(texture) } -- cgit v1.2.3-18-g5258