diff options
Diffstat (limited to 'engine/src/renderer/vertex_array.rs')
-rw-r--r-- | engine/src/renderer/vertex_array.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/engine/src/renderer/vertex_array.rs b/engine/src/renderer/vertex_array.rs index b0aac81..2bd6a5b 100644 --- a/engine/src/renderer/vertex_array.rs +++ b/engine/src/renderer/vertex_array.rs @@ -1,5 +1,7 @@ use std::mem::size_of; +use crate::currently_bound::CurrentlyBound; +use crate::renderer::vertex_buffer::VertexBuffer; use crate::vertex::{Attribute, AttributeComponentType, Vertex}; const VERTEX_STRIDE: usize = size_of::<Vertex>(); @@ -23,10 +25,14 @@ impl VertexArray Self { array } } - pub fn draw(&self, primitive_kind: PrimitiveKind, start_index: u32, index_cnt: u32) + /// Draws the currently bound vertex array. + pub fn draw( + _currently_bound: &CurrentlyBound<Self>, + primitive_kind: PrimitiveKind, + start_index: u32, + index_cnt: u32, + ) { - self.bind(); - unsafe { #[allow(clippy::cast_possible_wrap)] gl::DrawArrays( @@ -37,7 +43,10 @@ impl VertexArray } } - pub fn configure_attrs() + pub fn configure_attrs( + _currently_bound: &CurrentlyBound<Self>, + _vert_buf_curr_bound: &CurrentlyBound<VertexBuffer>, + ) { let mut offset = 0; @@ -50,9 +59,16 @@ impl VertexArray } } - pub fn bind(&self) + #[allow(clippy::inline_always)] + #[inline(always)] + pub fn bind(&self, cb: impl FnOnce(CurrentlyBound<'_, Self>)) { unsafe { gl::BindVertexArray(self.array) } + + // SAFETY: A vertex array object is currently bound + let currently_bound = unsafe { CurrentlyBound::new() }; + + cb(currently_bound); } fn vertex_attrib_ptr(vertex_attr: &Attribute, offset: usize) |