diff options
Diffstat (limited to 'opengl-bindings')
| -rw-r--r-- | opengl-bindings/src/texture.rs | 51 |
1 files 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<Cow<'image, [u8]>>, + image: Option<impl Into<Cow<'image, [u8]>>>, pixel_data_format: PixelDataFormat, ) -> Result<Texture, Error> { - 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<Texture, Error> where Image: Into<Cow<'image, [u8]>>, { - 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) } |
