Switch attributes to use iota in a complicated way
parent
cd4a66d764
commit
0db0df9e0e
|
@ -132,19 +132,19 @@ where P: AsRef <std::path::Path>
|
|||
struct ShaderClosure {
|
||||
program: ShaderProgram,
|
||||
uniforms: HashMap <u32, i32>,
|
||||
attributes: HashMap <usize, Option <u32>>,
|
||||
attributes: renderable_model::AttrMap,
|
||||
}
|
||||
|
||||
struct BorrowedShaderVars <'a> {
|
||||
unis: &'a HashMap <u32, i32>,
|
||||
attrs: &'a HashMap <usize, Option <u32>>,
|
||||
attrs: &'a renderable_model::AttrMap,
|
||||
}
|
||||
|
||||
impl ShaderClosure {
|
||||
pub fn new (
|
||||
program: ShaderProgram,
|
||||
uniforms: HashMap <u32, i32>,
|
||||
attributes: HashMap <usize, Option <u32>>
|
||||
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);
|
||||
|
|
|
@ -37,7 +37,7 @@ unsafe fn vertex_attrib_pointer (id: Option <u32>, num_coords: i32, float_offset
|
|||
}
|
||||
}
|
||||
|
||||
pub type AttrMap = HashMap <usize, Option <u32>>;
|
||||
pub type AttrMap = Vec <Option <u32>>;
|
||||
|
||||
pub mod attributes {
|
||||
use iota::iota;
|
||||
|
@ -110,9 +110,9 @@ impl RenderableModel {
|
|||
|
||||
unsafe {
|
||||
use attributes::*;
|
||||
vertex_attrib_pointer (attrs [&POS], 3, 0);
|
||||
vertex_attrib_pointer (attrs [&UV], 2, self.num_pos);
|
||||
vertex_attrib_pointer (attrs [&NORMAL], 3, self.num_pos + self.num_uv);
|
||||
vertex_attrib_pointer (attrs [POS], 3, 0);
|
||||
vertex_attrib_pointer (attrs [UV], 2, self.num_pos);
|
||||
vertex_attrib_pointer (attrs [NORMAL], 3, self.num_pos + self.num_uv);
|
||||
}
|
||||
|
||||
for mesh_num in start..end {
|
||||
|
|
Loading…
Reference in New Issue