summaryrefslogtreecommitdiff
path: root/engine/src/opengl/vertex_buffer.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-23 19:21:42 +0200
committerHampusM <hampus@hampusmat.com>2023-10-23 19:21:42 +0200
commitbd427836bfa6f7228951c18e43058d3e35577702 (patch)
tree4d7276d7c7ded85362b3f199dbde2e9939481bfc /engine/src/opengl/vertex_buffer.rs
parent54c0fd70f82eb1a6814872c78bc22380f438c9d1 (diff)
refactor(engine): rename vertex buffer to buffer & make generic
Diffstat (limited to 'engine/src/opengl/vertex_buffer.rs')
-rw-r--r--engine/src/opengl/vertex_buffer.rs93
1 files changed, 0 insertions, 93 deletions
diff --git a/engine/src/opengl/vertex_buffer.rs b/engine/src/opengl/vertex_buffer.rs
deleted file mode 100644
index 0050a9f..0000000
--- a/engine/src/opengl/vertex_buffer.rs
+++ /dev/null
@@ -1,93 +0,0 @@
-use std::mem::size_of_val;
-
-use crate::opengl::currently_bound::CurrentlyBound;
-use crate::vertex::Vertex;
-
-#[derive(Debug)]
-pub struct VertexBuffer
-{
- buffer: gl::types::GLuint,
-}
-
-impl VertexBuffer
-{
- pub fn new() -> Self
- {
- let mut buffer = gl::types::GLuint::default();
-
- unsafe {
- gl::GenBuffers(1, &mut buffer);
- };
-
- Self { buffer }
- }
-
- #[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(
- gl::ARRAY_BUFFER,
- size_of_val(vertices) as gl::types::GLsizeiptr,
- vertices.as_ptr().cast(),
- usage.into_gl(),
- );
- }
- }
-}
-
-impl Drop for VertexBuffer
-{
- fn drop(&mut self)
- {
- #[allow(clippy::cast_possible_wrap, clippy::cast_possible_truncation)]
- unsafe {
- gl::DeleteBuffers(1, &self.buffer);
- }
- }
-}
-
-#[derive(Debug)]
-#[allow(dead_code)]
-pub enum BufferUsage
-{
- /// The buffer data is set only once and used by the GPU at most a few times.
- Stream,
-
- /// The buffer data is set only once and used many times.
- Static,
-
- /// The buffer data is changed a lot and used many times.
- Dynamic,
-}
-
-impl BufferUsage
-{
- fn into_gl(self) -> gl::types::GLenum
- {
- match self {
- Self::Stream => gl::STREAM_DRAW,
- Self::Static => gl::STATIC_DRAW,
- Self::Dynamic => gl::DYNAMIC_DRAW,
- }
- }
-}