From c4686c2992417545e7a05a6a40ee9f1a8bbf3b96 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 16 Aug 2024 22:10:00 +0200 Subject: perf(engine): create OpenGL objects as needed instead of each frame --- engine/src/opengl/buffer.rs | 13 +++++++++++++ engine/src/opengl/vertex_array.rs | 11 +++++++++++ 2 files changed, 24 insertions(+) (limited to 'engine/src/opengl') diff --git a/engine/src/opengl/buffer.rs b/engine/src/opengl/buffer.rs index 68a75fb..2be7f12 100644 --- a/engine/src/opengl/buffer.rs +++ b/engine/src/opengl/buffer.rs @@ -39,6 +39,19 @@ impl Buffer { self.buf } + + /// Does a weak clone of this buffer. The buffer itself is NOT copied in any way this + /// function only copies the internal buffer ID. + /// + /// # Safety + /// The returned `Buffer` must not be dropped if another `Buffer` referencing the + /// same buffer ID is used later or if a [`VertexArray`] is used later. + /// + /// [`VertexArray`]: crate::opengl::vertex_array::VertexArray + pub unsafe fn clone_weak(&self) -> Self + { + Self { buf: self.buf, _pd: PhantomData } + } } impl Drop for Buffer diff --git a/engine/src/opengl/vertex_array.rs b/engine/src/opengl/vertex_array.rs index e1e1a15..da5d91e 100644 --- a/engine/src/opengl/vertex_array.rs +++ b/engine/src/opengl/vertex_array.rs @@ -125,6 +125,17 @@ impl VertexArray { unsafe { gl::BindVertexArray(self.array) } } + + /// Does a weak clone of this vertex array. The vertex array itself is NOT copied in + /// any way this function only copies the internal vertex array ID. + /// + /// # Safety + /// The returned `VertexArray` must not be dropped if another `VertexArray` + /// referencing the same vertex array ID is used later. + pub unsafe fn clone_unsafe(&self) -> Self + { + Self { array: self.array } + } } impl Drop for VertexArray -- cgit v1.2.3-18-g5258