diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index 0340476..996f0d9 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -142,7 +142,7 @@ struct BorrowedShaderVars <'a> { fn get_shader_attrs ( shader: &ShaderProgram, - attr_names: &Vec <(usize, &str)> + attr_names: &[(usize, &str)] ) -> renderable_model::AttrMap { @@ -150,8 +150,8 @@ fn get_shader_attrs ( let attrs = shader.get_attribute_locations (attr_names.iter ().map (|(_, v)| v).copied ()); - for ((i, _), loc) in attr_names.iter ().zip (attrs.iter ()) { - v [*i] = *loc; + for ((i, _), loc) in attr_names.iter ().zip (attrs.into_iter ()) { + v [*i] = loc; } v @@ -159,23 +159,26 @@ fn get_shader_attrs ( fn get_shader_uniforms ( shader: &ShaderProgram, - uni_names: &Vec <(u32, &str)> + uni_names: &[(u32, &str)] ) -> HashMap { let unis = shader.get_uniform_locations (uni_names.iter ().map (|(_, v)| v).copied ()); - HashMap::from_iter ( - uni_names.iter () - .map (|(key, name)| (*key, *unis.get (*name).unwrap ())) - ) + let pairs = + uni_names.iter ().map (|(i, _)| i).copied () + .zip (unis.into_iter ()) + .filter (|(_, v)| *v >= 0) + ; + + HashMap::from_iter (pairs) } impl ShaderClosure { pub fn new ( program: ShaderProgram, - uniform_names: &Vec <(u32, &str)>, - attr_names: &Vec <(usize, &str)> + uniform_names: &[(u32, &str)], + attr_names: &[(usize, &str)] ) -> Self { let uniforms = get_shader_uniforms (&program, uniform_names); @@ -244,13 +247,13 @@ fn main () { let uniform_names = { use uniforms::*; vec! [ - (MVP, "mvp"), - (OBJECT_SPACE_LIGHT, "object_space_light"), - (OBJECT_SPACE_SKY, "object_space_sky"), - (ALBEDO, "albedo"), - (MIN_ALBEDO, "min_albedo"), - (MIN_BRIGHT, "min_bright"), - (TEXTURE, "texture"), + (MVP, "uni_mvp"), + (OBJECT_SPACE_LIGHT, "uni_object_space_light"), + (OBJECT_SPACE_SKY, "uni_object_space_sky"), + (ALBEDO, "uni_albedo"), + (MIN_ALBEDO, "uni_min_albedo"), + (MIN_BRIGHT, "uni_min_bright"), + (TEXTURE, "uni_texture"), ] }; diff --git a/src/shader.rs b/src/shader.rs index b4f485d..a90ea2c 100644 --- a/src/shader.rs +++ b/src/shader.rs @@ -136,22 +136,19 @@ impl ShaderProgram { } pub fn get_uniform_locations <'a, I> (&self, names: I) - -> HashMap + -> Vec where I: Iterator { self.use_program (); names .map (|name| { - let mut s = String::from ("uni_"); - s.push_str (name); - - let c_str = CString::new (s.as_bytes ()).unwrap (); + let c_str = CString::new (name.as_bytes ()).unwrap (); let loc = unsafe { gl::GetUniformLocation (self.id, c_str.as_ptr ()) }; - (String::from (name), loc) + loc }) .collect () }