From cd4a66d7647efaee944da290db885c6a59be28db Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 8 Mar 2020 04:40:15 +0000 Subject: [PATCH] :construction: checkpoint --- src/bin/pumpkin.rs | 30 ++++++++++++------------------ src/shader.rs | 17 ++++++++--------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index 7130608..7189504 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -208,14 +208,14 @@ fn main () { ShaderProgram::new (&vert_shader, &frag_shader).unwrap () }; - let attr_lookup: HashMap <_, &str> = HashMap::from_iter ({ + let attr_lookup: Vec <(_, &str)> = { use renderable_model::attributes::*; vec! [ - (POS, "pos"), - (UV, "uv"), - (NORMAL, "normal"), - ].into_iter () - }); + (POS, "attr_pos"), + (UV, "attr_uv"), + (NORMAL, "attr_normal"), + ] + }; let uni_lookup: HashMap <_, &str> = HashMap::from_iter ({ use uniforms::*; @@ -230,23 +230,17 @@ fn main () { ].into_iter () }); - let attrs = { - let attrs = shader_program.get_attribute_locations (attr_lookup.values ().copied ()); + let get_shader_attrs = |shader: &ShaderProgram| { + let attrs = shader.get_attribute_locations (attr_lookup.iter ().map (|(_, v)| v).copied ()); HashMap::from_iter ( - attr_lookup.iter () - .map (|(key, name)| (*key, *attrs.get (*name).unwrap ())) + attr_lookup.iter ().enumerate () + .map (|(i, _)| (i, attrs [i])) ) }; - let shadow_attrs = { - let attrs = shadow_shader.get_attribute_locations (attr_lookup.values ().copied ()); - - HashMap::from_iter ( - attr_lookup.iter () - .map (|(key, name)| (*key, *attrs.get (*name).unwrap ())) - ) - }; + let attrs = get_shader_attrs (&shader_program); + let shadow_attrs = get_shader_attrs (&shadow_shader); let unis = { let unis = shader_program.get_uniform_locations (uni_lookup.values ().copied ()); diff --git a/src/shader.rs b/src/shader.rs index a6ef9e6..b4f485d 100644 --- a/src/shader.rs +++ b/src/shader.rs @@ -164,27 +164,26 @@ impl ShaderProgram { } } + // This could be an iterator adapter but the code is too long + // and it's only called during startup so I don't care. + pub fn get_attribute_locations <'a, I> (&self, names: I) - -> HashMap > + -> Vec