diff options
author | HampusM <hampus@hampusmat.com> | 2023-11-12 22:38:52 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-11-12 22:57:19 +0100 |
commit | 8d821588cd4f51d4ae9c4ef52d45c0af0e1ce9e5 (patch) | |
tree | ed1b0dd30e801b9a70537b9806a445e4212978b3 /engine/src/opengl | |
parent | 67023d6a095f457a2579367d59d13c6c804e7108 (diff) |
feat(engine): add basic flat lighting
Diffstat (limited to 'engine/src/opengl')
-rw-r--r-- | engine/src/opengl/shader.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/engine/src/opengl/shader.rs b/engine/src/opengl/shader.rs index 3dc308e..4bf56aa 100644 --- a/engine/src/opengl/shader.rs +++ b/engine/src/opengl/shader.rs @@ -3,6 +3,7 @@ use std::ptr::null_mut; use crate::matrix::Matrix; use crate::opengl::currently_bound::CurrentlyBound; +use crate::vector::Vec3; #[derive(Debug)] pub struct Shader @@ -179,6 +180,41 @@ impl Program } } + pub fn set_uniform_vec_3fv( + &self, + _: &CurrentlyBound<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()); + } + } + + pub fn set_uniform_1fv(&self, _: &CurrentlyBound<Self>, name: &CStr, num: f32) + { + let uniform_location = + unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; + + unsafe { + gl::Uniform1fv(uniform_location, 1, &num); + } + } + + pub fn set_uniform_1uiv(&self, _: &CurrentlyBound<Self>, name: &CStr, num: u32) + { + let uniform_location = + unsafe { gl::GetUniformLocation(self.program, name.as_ptr().cast()) }; + + unsafe { + gl::Uniform1uiv(uniform_location, 1, &num); + } + } + fn get_info_log(&self) -> String { let mut buf = vec![gl::types::GLchar::default(); 512]; |