summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--opengl-bindings/src/blending.rs3
-rw-r--r--opengl-bindings/src/framebuffer.rs10
-rw-r--r--opengl-bindings/src/lib.rs1
-rw-r--r--opengl-bindings/src/misc.rs4
-rw-r--r--opengl-bindings/src/shader.rs3
-rw-r--r--opengl-bindings/src/texture.rs49
-rw-r--r--opengl-bindings/src/vertex_array.rs5
7 files changed, 59 insertions, 16 deletions
diff --git a/opengl-bindings/src/blending.rs b/opengl-bindings/src/blending.rs
index e4229ed..0cb4891 100644
--- a/opengl-bindings/src/blending.rs
+++ b/opengl-bindings/src/blending.rs
@@ -28,18 +28,21 @@ pub struct Configuration
impl Configuration
{
+ #[must_use]
pub fn with_source_factor(mut self, source_factor: Factor) -> Self
{
self.source_factor = source_factor;
self
}
+ #[must_use]
pub fn with_destination_factor(mut self, destination_factor: Factor) -> Self
{
self.destination_factor = destination_factor;
self
}
+ #[must_use]
pub fn with_equation(mut self, equation: Equation) -> Self
{
self.equation = equation;
diff --git a/opengl-bindings/src/framebuffer.rs b/opengl-bindings/src/framebuffer.rs
index a758cc3..5b85f65 100644
--- a/opengl-bindings/src/framebuffer.rs
+++ b/opengl-bindings/src/framebuffer.rs
@@ -74,9 +74,7 @@ impl Framebuffer
unsafe {
current_context.fns().NamedFramebufferDrawBuffer(
self.inner,
- buffer
- .map(ColorAttachment::into_gl)
- .unwrap_or(crate::sys::NONE),
+ buffer.map_or(crate::sys::NONE, ColorAttachment::into_gl),
);
}
}
@@ -91,11 +89,13 @@ impl Framebuffer
}
}
+ #[must_use]
pub fn from_raw(raw: u32) -> Self
{
Self { inner: raw }
}
+ #[must_use]
pub fn into_raw(self) -> u32
{
self.inner
@@ -116,9 +116,7 @@ pub fn bind(
unsafe {
current_context.fns().BindFramebuffer(
target.into_gl(),
- framebuffer
- .map(|framebuffer| framebuffer.inner)
- .unwrap_or(0),
+ framebuffer.map_or(0, |framebuffer| framebuffer.inner),
);
}
}
diff --git a/opengl-bindings/src/lib.rs b/opengl-bindings/src/lib.rs
index ec39c83..e6495d5 100644
--- a/opengl-bindings/src/lib.rs
+++ b/opengl-bindings/src/lib.rs
@@ -1,4 +1,5 @@
#![deny(clippy::all, clippy::pedantic)]
+#![allow(clippy::needless_pass_by_value)]
use std::ffi::CString;
use std::process::abort;
diff --git a/opengl-bindings/src/misc.rs b/opengl-bindings/src/misc.rs
index 9ad8c4a..8440de0 100644
--- a/opengl-bindings/src/misc.rs
+++ b/opengl-bindings/src/misc.rs
@@ -55,6 +55,10 @@ pub fn set_viewport(
Ok(())
}
+/// Returns the current viewport position & size.
+///
+/// # Panics
+/// This function will panic if either the viewport position or viewport size is negative.
#[tracing::instrument(skip(current_context))]
pub fn get_viewport(
current_context: &MaybeCurrentContextWithFns,
diff --git a/opengl-bindings/src/shader.rs b/opengl-bindings/src/shader.rs
index e3df35c..9d7d674 100644
--- a/opengl-bindings/src/shader.rs
+++ b/opengl-bindings/src/shader.rs
@@ -227,11 +227,13 @@ impl Program
var.set(current_context, self, location);
}
+ #[must_use]
pub fn from_raw(raw: u32) -> Self
{
Self { program: raw }
}
+ #[must_use]
pub fn into_raw(self) -> u32
{
self.program
@@ -374,6 +376,7 @@ pub struct UniformLocation(crate::sys::types::GLint);
impl UniformLocation
{
+ #[must_use]
pub fn from_number(number: i32) -> Self
{
Self(number)
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,
})?;
}
diff --git a/opengl-bindings/src/vertex_array.rs b/opengl-bindings/src/vertex_array.rs
index f46b07d..c4fc62f 100644
--- a/opengl-bindings/src/vertex_array.rs
+++ b/opengl-bindings/src/vertex_array.rs
@@ -140,6 +140,11 @@ impl VertexArray
}
}
+ /// Binds a vertex buffer to the index `binding_index` in this vertex array.
+ ///
+ /// # Errors
+ /// Returns `Err` if either `offset` or `vertex_size` in `vertex_buffer_spec` is too
+ /// large.
#[tracing::instrument(skip(current_context))]
pub fn bind_vertex_buffer<VertexBufferItem: ReprC>(
&self,