diff options
author | HampusM <hampus@hampusmat.com> | 2024-04-14 14:33:44 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2024-04-15 22:07:42 +0200 |
commit | 97bb50d42d7c1f475bf63861449a2162f665be26 (patch) | |
tree | b25091d4ab06b60863b4ea1bf08f1ef36ad083a6 /engine/src/opengl/buffer.rs | |
parent | 73c5bb19e7274b3e4048f70a19a7b9a2d361bfa1 (diff) |
refactor(engine): use OpenGL DSA functions
Diffstat (limited to 'engine/src/opengl/buffer.rs')
-rw-r--r-- | engine/src/opengl/buffer.rs | 63 |
1 files changed, 13 insertions, 50 deletions
diff --git a/engine/src/opengl/buffer.rs b/engine/src/opengl/buffer.rs index 1622804..68a75fb 100644 --- a/engine/src/opengl/buffer.rs +++ b/engine/src/opengl/buffer.rs @@ -1,62 +1,50 @@ use std::marker::PhantomData; use std::mem::size_of_val; -use crate::opengl::currently_bound::CurrentlyBound; - #[derive(Debug)] -pub struct Buffer<Item, ModeT: Mode> +pub struct Buffer<Item> { buf: gl::types::GLuint, - _pd: PhantomData<(Item, ModeT)>, + _pd: PhantomData<Item>, } -impl<Item, ModeT: Mode> Buffer<Item, ModeT> +impl<Item> Buffer<Item> { pub fn new() -> Self { let mut buffer = gl::types::GLuint::default(); unsafe { - gl::GenBuffers(1, &mut buffer); + gl::CreateBuffers(1, &mut buffer); }; Self { buf: buffer, _pd: PhantomData } } - #[allow(clippy::inline_always)] - #[inline(always)] - pub fn bind(&self, cb: impl FnOnce(CurrentlyBound<'_, Self>)) - { - unsafe { - gl::BindBuffer(ModeT::GL_ENUM, self.buf); - } - - // SAFETY: The buffer object is bound above - let currently_bound = unsafe { CurrentlyBound::new() }; - - cb(currently_bound); - } - /// Stores items in the currently bound buffer. - pub fn store(_currently_bound: &CurrentlyBound<Self>, items: &[Item], usage: Usage) + pub fn store(&mut self, items: &[Item], usage: Usage) { unsafe { #[allow(clippy::cast_possible_wrap)] - gl::BufferData( - ModeT::GL_ENUM, + gl::NamedBufferData( + self.buf, size_of_val(items) as gl::types::GLsizeiptr, items.as_ptr().cast(), usage.into_gl(), ); } } + + pub fn object(&self) -> gl::types::GLuint + { + self.buf + } } -impl<Item, ModeT: Mode> Drop for Buffer<Item, ModeT> +impl<Item> Drop for Buffer<Item> { fn drop(&mut self) { - #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)] unsafe { gl::DeleteBuffers(1, &self.buf); } @@ -89,28 +77,3 @@ impl Usage } } } - -/// Buffer mode. -pub trait Mode -{ - #[doc(hidden)] - const GL_ENUM: gl::types::GLenum; -} - -/// Array buffer kind. -#[derive(Debug)] -pub struct ArrayKind; - -impl Mode for ArrayKind -{ - const GL_ENUM: gl::types::GLenum = gl::ARRAY_BUFFER; -} - -/// Element array buffer kind. -#[derive(Debug)] -pub struct ElementArrayKind; - -impl Mode for ElementArrayKind -{ - const GL_ENUM: gl::types::GLenum = gl::ELEMENT_ARRAY_BUFFER; -} |