main
_ 2020-03-08 05:26:11 +00:00
parent 6c964c2dd2
commit 00a51efb19
1 changed files with 11 additions and 24 deletions

View File

@ -129,6 +129,15 @@ where P: AsRef <std::path::Path>
RenderableModel::from_iqm (&model)
}
fn shader_from_files <P> (vert: P, frag: P) -> ShaderProgram
where P: AsRef <std::path::Path>
{
let vert_shader = ShaderObject::from_file (gl::VERTEX_SHADER, vert).unwrap ();
let frag_shader = ShaderObject::from_file (gl::FRAGMENT_SHADER, frag).unwrap ();
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
}
struct ShaderClosure {
program: ShaderProgram,
uniforms: HashMap <u32, i32>,
@ -222,28 +231,6 @@ fn main () {
window.gl_make_current (&gl_ctx).unwrap ();
// I love how with Rust I can throw unwrap ()s everywhere
// It's safer than C / C++'s default behavior of unchecked errors
// It's more programmer-friendly and explicit than C#'s unchecked
// exceptions that can appear almost anywhere at runtime with no
// compile-time warning
// And I'm still not actually checking errors - Just checkmarking
// that I know where they are.
let shader_program = {
let vert_shader = ShaderObject::from_file (gl::VERTEX_SHADER, "shaders/pumpkin-vert.glsl").unwrap ();
let frag_shader = ShaderObject::from_file (gl::FRAGMENT_SHADER, "shaders/pumpkin-frag.glsl").unwrap ();
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
};
let shadow_shader = {
let vert_shader = ShaderObject::from_file (gl::VERTEX_SHADER, "shaders/shadow-vert.glsl").unwrap ();
let frag_shader = ShaderObject::from_file (gl::FRAGMENT_SHADER, "shaders/shadow-frag.glsl").unwrap ();
ShaderProgram::new (&vert_shader, &frag_shader).unwrap ()
};
let uniform_names = {
use uniforms::*;
vec! [
@ -266,8 +253,8 @@ fn main () {
]
};
let shader_diffuse = ShaderClosure::new (shader_program, &uniform_names, &attr_names);
let shader_shadow = ShaderClosure::new (shadow_shader, &uniform_names, &attr_names);
let shader_diffuse = ShaderClosure::new (shader_from_files ("shaders/pumpkin-vert.glsl", "shaders/pumpkin-frag.glsl"), &uniform_names, &attr_names);
let shader_shadow = ShaderClosure::new (shader_from_files ("shaders/shadow-vert.glsl", "shaders/shadow-frag.glsl"), &uniform_names, &attr_names);
shader_diffuse.with (|shader_vars| {
let attrs = shader_vars.attrs;