summaryrefslogtreecommitdiff
path: root/engine/src/opengl/shader.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-11-05 12:32:42 +0100
committerHampusM <hampus@hampusmat.com>2023-11-05 12:32:42 +0100
commit7001b4955c8c1b337ce26bf75305417f6963a836 (patch)
tree3ba9e7e2293074ad96a8d333a8603722ddff196d /engine/src/opengl/shader.rs
parentd5b84d968b570fbaeb6a1832a93875116001c504 (diff)
refactor(engine): add shader program currently bound safety
Diffstat (limited to 'engine/src/opengl/shader.rs')
-rw-r--r--engine/src/opengl/shader.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/engine/src/opengl/shader.rs b/engine/src/opengl/shader.rs
index 603c790..3dc308e 100644
--- a/engine/src/opengl/shader.rs
+++ b/engine/src/opengl/shader.rs
@@ -2,6 +2,7 @@ use std::ffi::CStr;
use std::ptr::null_mut;
use crate::matrix::Matrix;
+use crate::opengl::currently_bound::CurrentlyBound;
#[derive(Debug)]
pub struct Shader
@@ -151,14 +152,24 @@ impl Program
Ok(())
}
- pub fn activate(&self)
+ pub fn activate(&self, cb: impl FnOnce(CurrentlyBound<'_, Self>))
{
unsafe {
gl::UseProgram(self.program);
}
+
+ // SAFETY: The shader program object is bound above
+ let currently_bound = unsafe { CurrentlyBound::new() };
+
+ cb(currently_bound);
}
- pub fn set_uniform_matrix_4fv(&self, name: &CStr, matrix: &Matrix<f32, 4, 4>)
+ pub fn set_uniform_matrix_4fv(
+ &self,
+ _: &CurrentlyBound<Self>,
+ name: &CStr,
+ matrix: &Matrix<f32, 4, 4>,
+ )
{
let uniform_location =
unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) };