1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use glin;
use std::borrow::Borrow;
use glin::RenderSurface;
use super::{Material, Renderer};

/// A material from a custom shader, it's uniforms and gl properties
pub struct ShaderMaterial<P = glin::Program>{
    program: P,
    uniforms: Vec<glin::program::Uniform>,
    props: Vec<glin::Property>
}

impl<P: Borrow<glin::Program>> ShaderMaterial<P>{
    pub fn new(program: P) -> ShaderMaterial<P>{
        ShaderMaterial{ program: program, uniforms: vec![], props: vec![] }
    }

    pub fn set_uniforms(&mut self, uniforms: Vec<glin::program::Uniform>){
    	self.uniforms = uniforms;
    }

    pub fn set_properties(&mut self, props: Vec<glin::Property>){
    	self.props = props;
    }
}

impl<P: Borrow<glin::Program>> Material for ShaderMaterial<P>{
    fn program<R: RenderSurface>(&self, _renderer: &Renderer<R>) -> &glin::Program{
        self.program.borrow()
    }

    fn uniforms<R: RenderSurface>(&self, _: &Renderer<R>) -> &[glin::program::Uniform]{
    	&self.uniforms
    }

    fn properties(&self) -> &[glin::Property]{
    	&self.props
    }
}

impl Material for glin::Program{
    fn program<R: RenderSurface>(&self, _: &Renderer<R>) -> &glin::Program{
        self
    }

    fn uniforms<R: RenderSurface>(&self, _: &Renderer<R>) -> &[glin::program::Uniform]{
    	&[]
    }

    fn properties(&self) -> &[glin::Property]{
    	&[]
    }
}