diff options
| author | HampusM <hampus@hampusmat.com> | 2026-03-20 14:00:34 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-03-20 14:00:34 +0100 |
| commit | eca5ed3d7f6344eebbbf34cc10ef72c6a312fa43 (patch) | |
| tree | d1f79cfbe5517a3d48210f53f32585d96025430a /opengl-bindings | |
| parent | 5af997a02f21e7f6bd16d3849e921a643b963304 (diff) | |
feat(opengl-bindings): add Buffer store_at_byte_offset fn
Diffstat (limited to 'opengl-bindings')
| -rw-r--r-- | opengl-bindings/src/buffer.rs | 48 |
1 files changed, 48 insertions, 0 deletions
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<Item: ReprC> Buffer<Item> 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, + }, } |
