diff options
Diffstat (limited to 'engine/src/opengl')
-rw-r--r-- | engine/src/opengl/buffer.rs (renamed from engine/src/opengl/vertex_buffer.rs) | 33 | ||||
-rw-r--r-- | engine/src/opengl/mod.rs | 2 | ||||
-rw-r--r-- | engine/src/opengl/vertex_array.rs | 4 |
3 files changed, 20 insertions, 19 deletions
diff --git a/engine/src/opengl/vertex_buffer.rs b/engine/src/opengl/buffer.rs index 0050a9f..34514fd 100644 --- a/engine/src/opengl/vertex_buffer.rs +++ b/engine/src/opengl/buffer.rs @@ -1,15 +1,16 @@ +use std::marker::PhantomData; use std::mem::size_of_val; use crate::opengl::currently_bound::CurrentlyBound; -use crate::vertex::Vertex; #[derive(Debug)] -pub struct VertexBuffer +pub struct Buffer<Item> { buffer: gl::types::GLuint, + _item_pd: PhantomData<Item>, } -impl VertexBuffer +impl<Item> Buffer<Item> { pub fn new() -> Self { @@ -19,7 +20,10 @@ impl VertexBuffer gl::GenBuffers(1, &mut buffer); }; - Self { buffer } + Self { + buffer, + _item_pd: PhantomData, + } } #[allow(clippy::inline_always)] @@ -30,32 +34,28 @@ impl VertexBuffer gl::BindBuffer(gl::ARRAY_BUFFER, self.buffer); } - // SAFETY: A vertex array object is currently bound + // SAFETY: The buffer object is bound above 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, - ) + /// Stores items in the currently bound buffer. + pub fn store(_currently_bound: &CurrentlyBound<Self>, items: &[Item], usage: Usage) { unsafe { #[allow(clippy::cast_possible_wrap)] gl::BufferData( gl::ARRAY_BUFFER, - size_of_val(vertices) as gl::types::GLsizeiptr, - vertices.as_ptr().cast(), + size_of_val(items) as gl::types::GLsizeiptr, + items.as_ptr().cast(), usage.into_gl(), ); } } } -impl Drop for VertexBuffer +impl<Item> Drop for Buffer<Item> { fn drop(&mut self) { @@ -66,9 +66,10 @@ impl Drop for VertexBuffer } } +/// Buffer usage. #[derive(Debug)] #[allow(dead_code)] -pub enum BufferUsage +pub enum Usage { /// The buffer data is set only once and used by the GPU at most a few times. Stream, @@ -80,7 +81,7 @@ pub enum BufferUsage Dynamic, } -impl BufferUsage +impl Usage { fn into_gl(self) -> gl::types::GLenum { diff --git a/engine/src/opengl/mod.rs b/engine/src/opengl/mod.rs index ce375f5..6f95a1f 100644 --- a/engine/src/opengl/mod.rs +++ b/engine/src/opengl/mod.rs @@ -3,10 +3,10 @@ use glfw::WindowSize; use crate::vector::Vec2; +pub mod buffer; pub mod currently_bound; pub mod shader; pub mod vertex_array; -pub mod vertex_buffer; mod util; diff --git a/engine/src/opengl/vertex_array.rs b/engine/src/opengl/vertex_array.rs index f255b8a..ba2ded2 100644 --- a/engine/src/opengl/vertex_array.rs +++ b/engine/src/opengl/vertex_array.rs @@ -1,7 +1,7 @@ use std::mem::size_of; +use crate::opengl::buffer::Buffer; use crate::opengl::currently_bound::CurrentlyBound; -use crate::opengl::vertex_buffer::VertexBuffer; use crate::vertex::{Attribute, AttributeComponentType, Vertex}; const VERTEX_STRIDE: usize = size_of::<Vertex>(); @@ -45,7 +45,7 @@ impl VertexArray pub fn configure_attrs( _currently_bound: &CurrentlyBound<Self>, - _vert_buf_curr_bound: &CurrentlyBound<VertexBuffer>, + _vert_buf_curr_bound: &CurrentlyBound<Buffer<Vertex>>, ) { let mut offset = 0; |