summaryrefslogtreecommitdiff
path: root/engine/src/opengl/buffer.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2025-10-18 17:04:28 +0200
committerHampusM <hampus@hampusmat.com>2025-10-18 17:04:28 +0200
commit7083a19bf1029bff21a9550d40cc3260e99aac53 (patch)
tree524a8bd2e75ca712b0536218089804cf9838553b /engine/src/opengl/buffer.rs
parent7f3072ed7e016dff359439d7580403e36ad6b325 (diff)
refactor(engine): use winit instead of glfw
Diffstat (limited to 'engine/src/opengl/buffer.rs')
-rw-r--r--engine/src/opengl/buffer.rs101
1 files changed, 0 insertions, 101 deletions
diff --git a/engine/src/opengl/buffer.rs b/engine/src/opengl/buffer.rs
deleted file mode 100644
index eded553..0000000
--- a/engine/src/opengl/buffer.rs
+++ /dev/null
@@ -1,101 +0,0 @@
-use std::marker::PhantomData;
-use std::mem::size_of_val;
-use std::ptr::null;
-
-#[derive(Debug)]
-pub struct Buffer<Item>
-{
- buf: gl::types::GLuint,
- _pd: PhantomData<Item>,
-}
-
-impl<Item> Buffer<Item>
-{
- pub fn new() -> Self
- {
- let mut buffer = gl::types::GLuint::default();
-
- unsafe {
- gl::CreateBuffers(1, &mut buffer);
- };
-
- Self { buf: buffer, _pd: PhantomData }
- }
-
- /// Stores items in the currently bound buffer.
- pub fn store(&mut self, items: &[Item], usage: Usage)
- {
- unsafe {
- #[allow(clippy::cast_possible_wrap)]
- gl::NamedBufferData(
- self.buf,
- size_of_val(items) as gl::types::GLsizeiptr,
- items.as_ptr().cast(),
- usage.into_gl(),
- );
- }
- }
-
- pub fn store_mapped<Value>(
- &mut self,
- values: &[Value],
- usage: Usage,
- mut map_func: impl FnMut(&Value) -> Item,
- )
- {
- unsafe {
- #[allow(clippy::cast_possible_wrap)]
- gl::NamedBufferData(
- self.buf,
- (size_of::<Item>() * values.len()) as gl::types::GLsizeiptr,
- null(),
- usage.into_gl(),
- );
- }
-
- for (index, value) in values.iter().enumerate() {
- let item = map_func(value);
-
- unsafe {
- gl::NamedBufferSubData(
- self.buf,
- (index * size_of::<Item>()) as gl::types::GLintptr,
- size_of::<Item>() as gl::types::GLsizeiptr,
- (&raw const item).cast(),
- );
- }
- }
- }
-
- pub fn object(&self) -> gl::types::GLuint
- {
- self.buf
- }
-}
-
-/// Buffer usage.
-#[derive(Debug)]
-#[allow(dead_code)]
-pub enum Usage
-{
- /// 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 Usage
-{
- fn into_gl(self) -> gl::types::GLenum
- {
- match self {
- Self::Stream => gl::STREAM_DRAW,
- Self::Static => gl::STATIC_DRAW,
- Self::Dynamic => gl::DYNAMIC_DRAW,
- }
- }
-}