🚧 checkpoint

main
_ 2020-03-08 04:40:15 +00:00
parent 07d925dc1e
commit cd4a66d764
2 changed files with 20 additions and 27 deletions

View File

@ -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 ());

View File

@ -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 <String, Option <u32>>
-> Vec <Option <u32>>
where I: Iterator <Item = &'a str>
{
self.use_program ();
names
.map (|name| {
let mut s = String::from ("attr_");
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::GetAttribLocation (self.id, c_str.as_ptr ())
};
let loc = match loc.try_into () {
match loc.try_into () {
Ok (loc) => Some (loc),
_ => None,
};
(String::from (name), loc)
}
})
.collect ()
}