From f449efbebd6f04a94648c8c662191845a6ed9472 Mon Sep 17 00:00:00 2001 From: LLLL Colonq Date: Tue, 16 Apr 2024 15:55:04 -0400 Subject: Point lights --- src/shader.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/shader.rs') 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 = 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 = 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 { -- cgit v1.2.3