From 7001b4955c8c1b337ce26bf75305417f6963a836 Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 5 Nov 2023 12:32:42 +0100 Subject: refactor(engine): add shader program currently bound safety --- engine/src/opengl/shader.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'engine/src/opengl') 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) + pub fn set_uniform_matrix_4fv( + &self, + _: &CurrentlyBound, + name: &CStr, + matrix: &Matrix, + ) { let uniform_location = unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; -- cgit v1.2.3-18-g5258