From eca5ed3d7f6344eebbbf34cc10ef72c6a312fa43 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 20 Mar 2026 14:00:34 +0100 Subject: feat(opengl-bindings): add Buffer store_at_byte_offset fn --- opengl-bindings/src/buffer.rs | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/opengl-bindings/src/buffer.rs b/opengl-bindings/src/buffer.rs index 3bb6c48..66ab719 100644 --- a/opengl-bindings/src/buffer.rs +++ b/opengl-bindings/src/buffer.rs @@ -87,6 +87,47 @@ impl Buffer Ok(()) } + /// Stores items in this buffer, starting at a byte offset. + /// + /// # Errors + /// Returns `Err` if the total size (in bytes) is too large. + pub fn store_at_byte_offset( + &self, + current_context: &CurrentContextWithFns<'_>, + byte_offset: usize, + items: &[Item], + // usage: Usage, + ) -> Result<(), Error> + { + let total_size = size_of_val(items); + + let byte_offset: crate::sys::types::GLintptr = + byte_offset + .try_into() + .map_err(|_| Error::ByteOffsetTooLarge { + byte_offset, + max_byte_offset: crate::sys::types::GLintptr::MAX as usize, + })?; + + let total_size: crate::sys::types::GLsizeiptr = + total_size.try_into().map_err(|_| Error::SizeTooLarge { + size: total_size, + max_size: crate::sys::types::GLsizeiptr::MAX as usize, + })?; + + unsafe { + current_context.fns().NamedBufferSubData( + self.buf, + byte_offset, + total_size, + items.as_ptr().cast(), + // usage.into_gl(), + ); + } + + Ok(()) + } + /// Maps the values in the `values` slice into `Item`s which is stored into this /// buffer. /// @@ -203,4 +244,11 @@ pub enum Error { size: usize, max_size: usize }, + + #[error("Byte offset ({byte_offset}) is too large. Must be < {max_byte_offset}")] + ByteOffsetTooLarge + { + byte_offset: usize, + max_byte_offset: usize, + }, } -- cgit v1.2.3-18-g5258