diff options
Diffstat (limited to 'engine/src/opengl/shader.rs')
-rw-r--r-- | engine/src/opengl/shader.rs | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/engine/src/opengl/shader.rs b/engine/src/opengl/shader.rs index 2312adc..070897e 100644 --- a/engine/src/opengl/shader.rs +++ b/engine/src/opengl/shader.rs @@ -2,7 +2,6 @@ use std::ffi::CStr; use std::ptr::null_mut; use crate::matrix::Matrix; -use crate::opengl::currently_bound::CurrentlyBound; use crate::shader::Kind; use crate::vector::Vec3; @@ -146,65 +145,56 @@ impl Program Ok(()) } - pub fn activate<Ret>(&self, cb: impl FnOnce(CurrentlyBound<'_, Self>) -> Ret) -> Ret + pub fn activate(&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, - _: &CurrentlyBound<Self>, - name: &CStr, - matrix: &Matrix<f32, 4, 4>, - ) + pub fn set_uniform_matrix_4fv(&mut self, name: &CStr, matrix: &Matrix<f32, 4, 4>) { let uniform_location = unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; unsafe { - gl::UniformMatrix4fv(uniform_location, 1, gl::FALSE, matrix.as_ptr()); + gl::ProgramUniformMatrix4fv( + self.program, + uniform_location, + 1, + gl::FALSE, + matrix.as_ptr(), + ); } } - pub fn set_uniform_vec_3fv( - &self, - _: &CurrentlyBound<Self>, - name: &CStr, - vec: &Vec3<f32>, - ) + pub fn set_uniform_vec_3fv(&mut self, name: &CStr, vec: &Vec3<f32>) { let uniform_location = unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; unsafe { - gl::Uniform3fv(uniform_location, 1, vec.as_ptr()); + gl::ProgramUniform3fv(self.program, uniform_location, 1, vec.as_ptr()); } } - pub fn set_uniform_1fv(&self, _: &CurrentlyBound<Self>, name: &CStr, num: f32) + pub fn set_uniform_1fv(&mut self, name: &CStr, num: f32) { let uniform_location = unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; unsafe { - gl::Uniform1fv(uniform_location, 1, &num); + gl::ProgramUniform1fv(self.program, uniform_location, 1, &num); } } - pub fn set_uniform_1i(&self, _: &CurrentlyBound<Self>, name: &CStr, num: i32) + pub fn set_uniform_1i(&mut self, name: &CStr, num: i32) { let uniform_location = unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; unsafe { - gl::Uniform1i(uniform_location, num); + gl::ProgramUniform1i(self.program, uniform_location, num); } } |