summaryrefslogtreecommitdiff
path: root/engine/src/renderer/vertex_buffer.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-13 22:55:56 +0200
committerHampusM <hampus@hampusmat.com>2023-10-13 22:55:56 +0200
commitcfa73b1ea42fa491ff9e00bb5efb5e5a5d860578 (patch)
tree95af08ec7e9598daef6a740ce3494c4e0f1c645d /engine/src/renderer/vertex_buffer.rs
parent25b5ca97c5e5597570360c37d7452662e0118a00 (diff)
refactor(engine): add OpenGL object currently bound guards
Diffstat (limited to 'engine/src/renderer/vertex_buffer.rs')
-rw-r--r--engine/src/renderer/vertex_buffer.rs18
1 files changed, 17 insertions, 1 deletions
diff --git a/engine/src/renderer/vertex_buffer.rs b/engine/src/renderer/vertex_buffer.rs
index 27ed705..57debc3 100644
--- a/engine/src/renderer/vertex_buffer.rs
+++ b/engine/src/renderer/vertex_buffer.rs
@@ -1,5 +1,6 @@
use std::mem::size_of_val;
+use crate::currently_bound::CurrentlyBound;
use crate::vertex::Vertex;
#[derive(Debug)]
@@ -21,12 +22,27 @@ impl VertexBuffer
Self { buffer }
}
- pub fn store(&self, vertices: &[Vertex], usage: BufferUsage)
+ #[allow(clippy::inline_always)]
+ #[inline(always)]
+ pub fn bind(&self, cb: impl FnOnce(CurrentlyBound<'_, Self>))
{
unsafe {
gl::BindBuffer(gl::ARRAY_BUFFER, self.buffer);
}
+ // SAFETY: A vertex array object is currently bound
+ let currently_bound = unsafe { CurrentlyBound::new() };
+
+ cb(currently_bound);
+ }
+
+ /// Stores vertices in the currently bound vertex bound.
+ pub fn store(
+ _currently_bound: &CurrentlyBound<Self>,
+ vertices: &[Vertex],
+ usage: BufferUsage,
+ )
+ {
unsafe {
#[allow(clippy::cast_possible_wrap)]
gl::BufferData(