main
parent
0db0df9e0e
commit
e751288dee
|
@ -140,13 +140,31 @@ struct BorrowedShaderVars <'a> {
|
|||
attrs: &'a renderable_model::AttrMap,
|
||||
}
|
||||
|
||||
fn get_shader_attrs (
|
||||
shader: &ShaderProgram,
|
||||
attr_lookup: &Vec <(usize, &str)>
|
||||
)
|
||||
-> renderable_model::AttrMap
|
||||
{
|
||||
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 ());
|
||||
|
||||
for ((i, _), loc) in attr_lookup.iter ().zip (attrs.iter ()) {
|
||||
v [*i] = *loc;
|
||||
}
|
||||
|
||||
v
|
||||
}
|
||||
|
||||
impl ShaderClosure {
|
||||
pub fn new (
|
||||
program: ShaderProgram,
|
||||
uniforms: HashMap <u32, i32>,
|
||||
attributes: renderable_model::AttrMap
|
||||
attr_lookup: &Vec <(usize, &str)>
|
||||
) -> Self
|
||||
{
|
||||
let attributes = get_shader_attrs (&program, attr_lookup);
|
||||
Self {
|
||||
program,
|
||||
uniforms,
|
||||
|
@ -208,15 +226,6 @@ fn main () {
|
|||
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
|
||||
};
|
||||
|
||||
let attr_lookup: Vec <(_, &str)> = {
|
||||
use renderable_model::attributes::*;
|
||||
vec! [
|
||||
(POS, "attr_pos"),
|
||||
(UV, "attr_uv"),
|
||||
(NORMAL, "attr_normal"),
|
||||
]
|
||||
};
|
||||
|
||||
let uni_lookup: HashMap <_, &str> = HashMap::from_iter ({
|
||||
use uniforms::*;
|
||||
vec! [
|
||||
|
@ -230,21 +239,6 @@ fn main () {
|
|||
].into_iter ()
|
||||
});
|
||||
|
||||
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 ());
|
||||
|
||||
for ((i, _), loc) in attr_lookup.iter ().zip (attrs.iter ()) {
|
||||
v [*i] = *loc;
|
||||
}
|
||||
|
||||
v
|
||||
};
|
||||
|
||||
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 ());
|
||||
|
||||
|
@ -265,15 +259,25 @@ fn main () {
|
|||
unis
|
||||
};
|
||||
|
||||
{
|
||||
let attr_lookup: Vec <(_, &str)> = {
|
||||
use renderable_model::attributes::*;
|
||||
vec! [
|
||||
(POS, "attr_pos"),
|
||||
(UV, "attr_uv"),
|
||||
(NORMAL, "attr_normal"),
|
||||
]
|
||||
};
|
||||
|
||||
let shader_diffuse = ShaderClosure::new (shader_program, unis, &attr_lookup);
|
||||
let shader_shadow = ShaderClosure::new (shadow_shader, shadow_unis, &attr_lookup);
|
||||
|
||||
shader_diffuse.with (|shader_vars| {
|
||||
let attrs = shader_vars.attrs;
|
||||
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]);
|
||||
}
|
||||
|
||||
let shader_diffuse = ShaderClosure::new (shader_program, unis, attrs);
|
||||
let shader_shadow = ShaderClosure::new (shadow_shader, shadow_unis, shadow_attrs);
|
||||
});
|
||||
|
||||
let texture = Texture::from_file ("sky.png");
|
||||
texture.bind ();
|
||||
|
|
Loading…
Reference in New Issue