main
parent
fcac505286
commit
6c964c2dd2
|
@ -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 <u32, i32>
|
||||
{
|
||||
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"),
|
||||
]
|
||||
};
|
||||
|
||||
|
|
|
@ -136,22 +136,19 @@ impl ShaderProgram {
|
|||
}
|
||||
|
||||
pub fn get_uniform_locations <'a, I> (&self, names: I)
|
||||
-> HashMap <String, i32>
|
||||
-> Vec <i32>
|
||||
where I: Iterator <Item = &'a str>
|
||||
{
|
||||
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 ()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue