main
parent
e751288dee
commit
fcac505286
|
@ -142,29 +142,44 @@ struct BorrowedShaderVars <'a> {
|
||||||
|
|
||||||
fn get_shader_attrs (
|
fn get_shader_attrs (
|
||||||
shader: &ShaderProgram,
|
shader: &ShaderProgram,
|
||||||
attr_lookup: &Vec <(usize, &str)>
|
attr_names: &Vec <(usize, &str)>
|
||||||
)
|
)
|
||||||
-> renderable_model::AttrMap
|
-> renderable_model::AttrMap
|
||||||
{
|
{
|
||||||
let mut v = vec! [None; attr_lookup.iter ().map (|(i, _)| i).max ().unwrap () + 1];
|
let mut v = vec! [None; attr_names.iter ().map (|(i, _)| i).max ().unwrap () + 1];
|
||||||
|
|
||||||
let attrs = shader.get_attribute_locations (attr_lookup.iter ().map (|(_, v)| v).copied ());
|
let attrs = shader.get_attribute_locations (attr_names.iter ().map (|(_, v)| v).copied ());
|
||||||
|
|
||||||
for ((i, _), loc) in attr_lookup.iter ().zip (attrs.iter ()) {
|
for ((i, _), loc) in attr_names.iter ().zip (attrs.iter ()) {
|
||||||
v [*i] = *loc;
|
v [*i] = *loc;
|
||||||
}
|
}
|
||||||
|
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_shader_uniforms (
|
||||||
|
shader: &ShaderProgram,
|
||||||
|
uni_names: &Vec <(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 ()))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
impl ShaderClosure {
|
impl ShaderClosure {
|
||||||
pub fn new (
|
pub fn new (
|
||||||
program: ShaderProgram,
|
program: ShaderProgram,
|
||||||
uniforms: HashMap <u32, i32>,
|
uniform_names: &Vec <(u32, &str)>,
|
||||||
attr_lookup: &Vec <(usize, &str)>
|
attr_names: &Vec <(usize, &str)>
|
||||||
) -> Self
|
) -> Self
|
||||||
{
|
{
|
||||||
let attributes = get_shader_attrs (&program, attr_lookup);
|
let uniforms = get_shader_uniforms (&program, uniform_names);
|
||||||
|
let attributes = get_shader_attrs (&program, attr_names);
|
||||||
Self {
|
Self {
|
||||||
program,
|
program,
|
||||||
uniforms,
|
uniforms,
|
||||||
|
@ -226,7 +241,7 @@ fn main () {
|
||||||
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
|
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
|
||||||
};
|
};
|
||||||
|
|
||||||
let uni_lookup: HashMap <_, &str> = HashMap::from_iter ({
|
let uniform_names = {
|
||||||
use uniforms::*;
|
use uniforms::*;
|
||||||
vec! [
|
vec! [
|
||||||
(MVP, "mvp"),
|
(MVP, "mvp"),
|
||||||
|
@ -236,30 +251,10 @@ fn main () {
|
||||||
(MIN_ALBEDO, "min_albedo"),
|
(MIN_ALBEDO, "min_albedo"),
|
||||||
(MIN_BRIGHT, "min_bright"),
|
(MIN_BRIGHT, "min_bright"),
|
||||||
(TEXTURE, "texture"),
|
(TEXTURE, "texture"),
|
||||||
].into_iter ()
|
]
|
||||||
});
|
|
||||||
|
|
||||||
let unis = {
|
|
||||||
let unis = shader_program.get_uniform_locations (uni_lookup.values ().copied ());
|
|
||||||
|
|
||||||
let unis: HashMap <u32, i32> = HashMap::from_iter (
|
|
||||||
uni_lookup.iter ()
|
|
||||||
.map (|(key, name)| (*key, *unis.get (*name).unwrap ()))
|
|
||||||
);
|
|
||||||
unis
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let shadow_unis = {
|
let attr_names = {
|
||||||
let unis = shadow_shader.get_uniform_locations (uni_lookup.values ().copied ());
|
|
||||||
|
|
||||||
let unis: HashMap <u32, i32> = HashMap::from_iter (
|
|
||||||
uni_lookup.iter ()
|
|
||||||
.map (|(key, name)| (*key, *unis.get (*name).unwrap ()))
|
|
||||||
);
|
|
||||||
unis
|
|
||||||
};
|
|
||||||
|
|
||||||
let attr_lookup: Vec <(_, &str)> = {
|
|
||||||
use renderable_model::attributes::*;
|
use renderable_model::attributes::*;
|
||||||
vec! [
|
vec! [
|
||||||
(POS, "attr_pos"),
|
(POS, "attr_pos"),
|
||||||
|
@ -268,8 +263,8 @@ fn main () {
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
let shader_diffuse = ShaderClosure::new (shader_program, unis, &attr_lookup);
|
let shader_diffuse = ShaderClosure::new (shader_program, &uniform_names, &attr_names);
|
||||||
let shader_shadow = ShaderClosure::new (shadow_shader, shadow_unis, &attr_lookup);
|
let shader_shadow = ShaderClosure::new (shadow_shader, &uniform_names, &attr_names);
|
||||||
|
|
||||||
shader_diffuse.with (|shader_vars| {
|
shader_diffuse.with (|shader_vars| {
|
||||||
let attrs = shader_vars.attrs;
|
let attrs = shader_vars.attrs;
|
||||||
|
|
Loading…
Reference in New Issue