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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use crate::material::{OutlineMaterial, Material, AlphaType, texture::TextureSampler};
use super::shader_data::Data;
use super::TexturesPool;
use super::components::ProgramRef;
use rinecs::{EntitiesThreadLocal, ResourcesThreadLocal};
use generational_arena::Arena;
use rin::gl;

pub static PRIORITY: i32 = 100;

impl super::Material for OutlineMaterial{
    fn data(&self) -> Option<Data>{
        None
    }

    fn uniforms(&self, _: &EntitiesThreadLocal, _: &TexturesPool) -> Vec<glin::program::Uniform>{
        uniforms!{
            color_outline: self.color,
            offset: self.offset,
        }
    }

    fn properties(&self) -> Vec<glin::Property>{
    	vec![
            glin::Property::CullFace(Some(gl::FRONT)),
            glin::Property::DepthMask(true),
            glin::Property::DepthFunc(gl::LEQUAL),
            glin::Property::ColorMask([true, true, true, true]),
        ]
    }

    fn program(&self, _: &EntitiesThreadLocal, programs: &mut Arena<glin::Program>, gl: &gl::Renderer) -> ProgramRef{
        shaders::get_program(gl, programs)
    }

    fn textures(&self) -> Vec<&TextureSampler>{
        vec![]
    }

    fn double_sided(&self) -> bool{
        false
    }

    fn alpha(&self) -> f32{
        1.
    }

    fn update(&mut self, _: &EntitiesThreadLocal, _: &ResourcesThreadLocal) -> bool{
        //TODO: Reload if glsl-debug and return true if changed
        let changed = self.changed();
        self.reset_changed();
        changed
    }

    fn alpha_type(&self) -> AlphaType{
        AlphaType::None
    }

    fn priority(&self) -> Option<i32>{
        Some(PRIORITY)
    }
}

mod shaders{
    use glin;
    use crate::renderer::{
        default_attribute_bindings, default_glsl_version, use_model_as_attribute
    };

    programref_cache!(glin::program::Settings{
        version: default_glsl_version(),
        extensions: vec![],
        precission: glin::program::ShaderPrecision::High,
        defines: vec![
            ("USE_MODEL_ATTR",    (use_model_as_attribute() as u8).to_string().as_str()),
            ("USE_CAMERA_UBO",    "1"),
            ("NEEDS_CAMERA_INFO", "1"),
        ],
        shaders: vec![
            (glin::gl::VERTEX_SHADER, include_str!("shaders/outline_material.vs.glsl")),
            (glin::gl::FRAGMENT_SHADER, include_str!("shaders/outline_material.fs.glsl")),
        ],
        bindings: default_attribute_bindings(),
        base_path: "",
        includes: hash_map!{
            "mvp_uniforms.glsl" => {include_str!("shaders/mvp_uniforms.glsl")}
        },
    }, get_program, SHADER);
}