diff options
Diffstat (limited to 'opengl-bindings/src/texture.rs')
| -rw-r--r-- | opengl-bindings/src/texture.rs | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/opengl-bindings/src/texture.rs b/opengl-bindings/src/texture.rs index e0bd19f..d98e087 100644 --- a/opengl-bindings/src/texture.rs +++ b/opengl-bindings/src/texture.rs @@ -10,21 +10,28 @@ pub struct Builder impl Builder { + #[must_use] pub fn size(mut self, size: Dimens<u32>) -> Self { self.size = size; self } + #[must_use] pub fn mipmap_levels(mut self, mipmap_levels: u16) -> Self { self.mipmap_levels = mipmap_levels; self } + /// Creates a new 2D texture. + /// + /// # Errors + /// Returns `Err` if: + /// - The length of `image` is incorrect for the texture dimensions. + /// - Any value in the texture dimensions is too large. #[tracing::instrument(skip(current_context, image))] - #[must_use] - pub fn create_2d<'image>( + pub fn create_2d( &self, current_context: &MaybeCurrentContextWithFns, image: Option<&[u8]>, @@ -61,9 +68,14 @@ impl Builder Ok(texture) } + /// Creates a new cube map texture. + /// + /// # Errors + /// Returns `Err` if: + /// - The length of any image in `images` is incorrect for the texture dimensions. + /// - Any value in the texture dimensions is too large. #[tracing::instrument(skip(current_context, images))] - #[must_use] - pub fn create_cube_map<'image>( + pub fn create_cube_map( &self, current_context: &MaybeCurrentContextWithFns, images: Option<[(CubeMapFace, &[u8]); 6]>, @@ -72,7 +84,7 @@ impl Builder { for (_, image) in images.iter().flatten() { check_image_buffer_len_correct_for_size( - image.as_ref(), + image, [self.size.width, self.size.height, 1], pixel_data_format, )?; @@ -91,7 +103,7 @@ impl Builder [0, 0, *face as crate::sys::types::GLint], [size[0], size[1], 1], pixel_data_format, - *image, + image, ); } @@ -122,6 +134,7 @@ pub struct Texture impl Texture { + #[must_use] pub fn builder() -> Builder { Builder::default() @@ -149,6 +162,13 @@ impl Texture } } + /// Stores a image in this texture. + /// + /// # Errors + /// Returns `Err` if: + /// - The length of `image` is incorrect for the dimensions `size`. + /// - Any value in `offset` is too large. + /// - Any value in `size` is too large. #[tracing::instrument(skip_all)] pub fn store_image_2d( &self, @@ -181,6 +201,13 @@ impl Texture Ok(()) } + /// Stores a image in this texture. + /// + /// # Errors + /// Returns `Err` if: + /// - The length of `image` is incorrect for the dimensions `size`. + /// - Any value in `offset` is too large. + /// - Any value in `size` is too large. #[tracing::instrument(skip_all)] pub fn store_image_3d( &self, @@ -298,11 +325,13 @@ impl Texture } } + #[must_use] pub fn from_raw(raw: u32) -> Self { Self { texture: raw } } + #[must_use] pub fn into_raw(self) -> u32 { self.texture @@ -541,7 +570,7 @@ impl PixelDataFormat } } - fn pixel_width(&self) -> usize + fn pixel_width(self) -> usize { match self { Self::Rgb(_) | Self::Srgb(_) => 3, @@ -550,7 +579,7 @@ impl PixelDataFormat } } - fn requires_adjust_pixel_unpack_alignment(&self) -> Option<PixelAlignment> + fn requires_adjust_pixel_unpack_alignment(self) -> Option<PixelAlignment> { if matches!( self, @@ -622,7 +651,7 @@ fn try_convert_size<const LEN: usize>( for (value, output_val) in size.into_iter().zip(&mut output) { *output_val = value.try_into().map_err(|_| Error::ValueInSizeIsTooLarge { - value: value, + value, max_value: crate::sys::types::GLsizei::MAX as u32, })?; } @@ -640,7 +669,7 @@ fn try_convert_offset<const LEN: usize>( *output_val = value .try_into() .map_err(|_| Error::ValueInOffsetIsTooLarge { - value: value, + value, max_value: crate::sys::types::GLint::MAX as u32, })?; } |
