summaryrefslogtreecommitdiff
path: root/opengl-bindings/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-03-20 13:58:29 +0100
committerHampusM <hampus@hampusmat.com>2026-03-20 13:58:29 +0100
commit5af997a02f21e7f6bd16d3849e921a643b963304 (patch)
treef834b547fa55754829b15d227c28c6b19f595633 /opengl-bindings/src
parent21aafa3b070425e1fa84d2c6bb322e75cb52dfd5 (diff)
feat(opengl-bindings): add Buffer init fn
Diffstat (limited to 'opengl-bindings/src')
-rw-r--r--opengl-bindings/src/buffer.rs68
1 files changed, 50 insertions, 18 deletions
diff --git a/opengl-bindings/src/buffer.rs b/opengl-bindings/src/buffer.rs
index 4c91649..3bb6c48 100644
--- a/opengl-bindings/src/buffer.rs
+++ b/opengl-bindings/src/buffer.rs
@@ -27,6 +27,35 @@ impl<Item: ReprC> Buffer<Item>
Self { buf: buffer, _pd: PhantomData }
}
+ /// Initializes this buffer with a size and a usage.
+ ///
+ /// # Errors
+ /// Returns `Err` if the size (in bytes) is too large.
+ pub fn init(
+ &self,
+ current_context: &CurrentContextWithFns<'_>,
+ size: usize,
+ usage: Usage,
+ ) -> Result<(), Error>
+ {
+ let size: crate::sys::types::GLsizeiptr =
+ size.try_into().map_err(|_| Error::SizeTooLarge {
+ size,
+ max_size: crate::sys::types::GLsizeiptr::MAX as usize,
+ })?;
+
+ unsafe {
+ current_context.fns().NamedBufferData(
+ self.buf,
+ size,
+ null(),
+ usage.into_gl(),
+ );
+ }
+
+ Ok(())
+ }
+
/// Stores items in this buffer.
///
/// # Errors
@@ -41,12 +70,10 @@ impl<Item: ReprC> Buffer<Item>
let total_size = size_of_val(items);
let total_size: crate::sys::types::GLsizeiptr =
- total_size
- .try_into()
- .map_err(|_| Error::TotalItemsSizeTooLarge {
- total_size,
- max_total_size: crate::sys::types::GLsizeiptr::MAX as usize,
- })?;
+ total_size.try_into().map_err(|_| Error::SizeTooLarge {
+ size: total_size,
+ max_size: crate::sys::types::GLsizeiptr::MAX as usize,
+ })?;
unsafe {
current_context.fns().NamedBufferData(
@@ -82,12 +109,10 @@ impl<Item: ReprC> Buffer<Item>
let total_size = size_of::<Item>() * values.len();
let total_size: crate::sys::types::GLsizeiptr =
- total_size
- .try_into()
- .map_err(|_| Error::TotalItemsSizeTooLarge {
- total_size,
- max_total_size: crate::sys::types::GLsizeiptr::MAX as usize,
- })?;
+ total_size.try_into().map_err(|_| Error::SizeTooLarge {
+ size: total_size,
+ max_size: crate::sys::types::GLsizeiptr::MAX as usize,
+ })?;
unsafe {
current_context.fns().NamedBufferData(
@@ -160,15 +185,22 @@ impl Usage
}
}
+#[derive(Debug)]
+#[repr(u32)]
+pub enum BindingTarget
+{
+ AtomicCounterBuffer = crate::sys::ATOMIC_COUNTER_BUFFER,
+ TransformFeedbackBuffer = crate::sys::TRANSFORM_FEEDBACK_BUFFER,
+ UniformBuffer = crate::sys::UNIFORM_BUFFER,
+ ShaderStorageBuffer = crate::sys::SHADER_STORAGE_BUFFER,
+}
+
#[derive(Debug, thiserror::Error)]
pub enum Error
{
- #[error(
- "Total size of items ({total_size}) is too large. Must be < {max_total_size}"
- )]
- TotalItemsSizeTooLarge
+ #[error("Size ({size}) is too large. Must be < {max_size}")]
+ SizeTooLarge
{
- total_size: usize,
- max_total_size: usize,
+ size: usize, max_size: usize
},
}