diff options
| author | LLLL Colonq <llll@colonq> | 2024-04-16 15:55:04 -0400 |
|---|---|---|
| committer | LLLL Colonq <llll@colonq> | 2024-04-16 15:55:04 -0400 |
| commit | f449efbebd6f04a94648c8c662191845a6ed9472 (patch) | |
| tree | 15c124153542b38652536cc63aa9c720a6e5b062 /src/shader.rs | |
| parent | f0b945d378a157a780f56b1fc015b7937e151852 (diff) | |
Point lights
Diffstat (limited to 'src/shader.rs')
| -rw-r--r-- | src/shader.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/shader.rs b/src/shader.rs index 6e58bb7..ec0f24b 100644 --- a/src/shader.rs +++ b/src/shader.rs @@ -70,6 +70,8 @@ impl Shader { } else { log::warn!("failed to get location for uniform: {}", active.name); } + } else { + log::warn!("failed to get active uniform for index: {}", index); } } @@ -105,6 +107,30 @@ impl Shader { unsafe { ctx.gl.uniform_1_f32(Some(loc), val) } } } + + pub fn set_vec2(&self, ctx: &context::Context, name: &str, val: &glam::Vec2) { + if let Some(loc) = self.uniforms.get(name) { + unsafe { + ctx.gl.uniform_2_f32( + Some(loc), + val.x, + val.y, + ); + } + } + } + + pub fn set_vec2_array(&self, ctx: &context::Context, name: &str, val: &[glam::Vec2]) { + if let Some(loc) = self.uniforms.get(name) { + let vs: Vec<f32> = val.iter().flat_map(|v| [v.x, v.y]).collect(); + unsafe { + ctx.gl.uniform_2_f32_slice( + Some(loc), + &vs, + ); + } + } + } pub fn set_vec3(&self, ctx: &context::Context, name: &str, val: &glam::Vec3) { if let Some(loc) = self.uniforms.get(name) { @@ -119,6 +145,18 @@ impl Shader { } } + pub fn set_vec3_array(&self, ctx: &context::Context, name: &str, val: &[glam::Vec3]) { + if let Some(loc) = self.uniforms.get(name) { + let vs: Vec<f32> = val.iter().flat_map(|v| [v.x, v.y, v.z]).collect(); + unsafe { + ctx.gl.uniform_3_f32_slice( + Some(loc), + &vs, + ); + } + } + } + pub fn set_vec4(&self, ctx: &context::Context, name: &str, val: &glam::Vec4) { if let Some(loc) = self.uniforms.get(name) { unsafe { |
