From 0db0df9e0ed404415fc0f7ffe84dafd9a3b82016 Mon Sep 17 00:00:00 2001 From: _ <> Date: Sun, 8 Mar 2020 04:55:04 +0000 Subject: [PATCH] Switch attributes to use iota in a complicated way --- src/bin/pumpkin.rs | 23 +++++++++++++---------- src/renderable_model.rs | 8 ++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index 7189504..d158c32 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -132,19 +132,19 @@ where P: AsRef struct ShaderClosure { program: ShaderProgram, uniforms: HashMap , - attributes: HashMap >, + attributes: renderable_model::AttrMap, } struct BorrowedShaderVars <'a> { unis: &'a HashMap , - attrs: &'a HashMap >, + attrs: &'a renderable_model::AttrMap, } impl ShaderClosure { pub fn new ( program: ShaderProgram, uniforms: HashMap , - attributes: HashMap > + attributes: renderable_model::AttrMap ) -> Self { Self { @@ -231,12 +231,15 @@ fn main () { }); let get_shader_attrs = |shader: &ShaderProgram| { + let mut v = vec! [None; attr_lookup.iter ().map (|(i, _)| i).max ().unwrap () + 1]; + let attrs = shader.get_attribute_locations (attr_lookup.iter ().map (|(_, v)| v).copied ()); - HashMap::from_iter ( - attr_lookup.iter ().enumerate () - .map (|(i, _)| (i, attrs [i])) - ) + for ((i, _), loc) in attr_lookup.iter ().zip (attrs.iter ()) { + v [*i] = *loc; + } + + v }; let attrs = get_shader_attrs (&shader_program); @@ -264,9 +267,9 @@ fn main () { { use renderable_model::attributes::*; - glezz::enable_vertex_attrib_array (attrs [&POS]); - glezz::enable_vertex_attrib_array (attrs [&UV]); - glezz::enable_vertex_attrib_array (attrs [&NORMAL]); + glezz::enable_vertex_attrib_array (attrs [POS]); + glezz::enable_vertex_attrib_array (attrs [UV]); + glezz::enable_vertex_attrib_array (attrs [NORMAL]); } let shader_diffuse = ShaderClosure::new (shader_program, unis, attrs); diff --git a/src/renderable_model.rs b/src/renderable_model.rs index 596be93..bea63a3 100644 --- a/src/renderable_model.rs +++ b/src/renderable_model.rs @@ -37,7 +37,7 @@ unsafe fn vertex_attrib_pointer (id: Option , num_coords: i32, float_offset } } -pub type AttrMap = HashMap >; +pub type AttrMap = Vec