Created
April 5, 2016 17:33
-
-
Save mheistermann/e2a22b5295a25643247808d7ac4d0311 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate glium; | |
use glium::Program; | |
use glium::program::{ProgramCreationError, ProgramCreationInput}; | |
use glium::backend::Facade; | |
pub struct ReloadingProgram<'a, F: Facade + 'a> { | |
current: Option<Result<Program, ProgramCreationError>>, | |
facade: &'a F, | |
input: Box<ProgramCreationInput<'a>>, | |
} | |
impl<'a, F: Facade + 'a> ReloadingProgram<'a, F> { | |
pub fn from_source(facade: &'a F, | |
vertex_shader: &'a str, | |
fragment_shader: &'a str, | |
geometry_shader: Option<&'a str>) | |
-> ReloadingProgram<'a, F> | |
where F: Facade | |
{ | |
let input = Box::new(ProgramCreationInput::SourceCode { | |
vertex_shader: vertex_shader, | |
fragment_shader: fragment_shader, | |
geometry_shader: geometry_shader, | |
tessellation_control_shader: None, | |
tessellation_evaluation_shader: None, | |
transform_feedback_varyings: None, | |
outputs_srgb: false, | |
uses_point_size: false, | |
}); | |
return ReloadingProgram { | |
facade: facade, | |
input: input, | |
current: None, | |
}; | |
} | |
pub fn current(&self) -> Result<Program, ProgramCreationError> { | |
/* TODO | |
if ... { | |
self.current = None; | |
} | |
*/ | |
match self.current { | |
None => { | |
let test: &ProgramCreationInput = &*self.input; | |
let prog = Program::new(self.facade, test); | |
self.current = Some(prog); | |
prog | |
}, | |
Some(prog) => prog, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment