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
#[macro_export]
macro_rules! programref_cache {
    { $settings:expr, $getter:ident, $shader:ident  } => {
        thread_local!(static $shader: ::std::cell::UnsafeCell<::std::collections::HashMap<usize, crate::renderer::components::ProgramRef>> =
                ::std::cell::UnsafeCell::new(::std::collections::HashMap::new()));

        pub fn $getter(gl: &rin::gl::Renderer, programs: &mut generational_arena::Arena<glin::Program>) -> crate::renderer::components::ProgramRef{
        	$shader.with(|cache| {
                let cache = unsafe{ &mut *cache.get() };
                use rin::util::LogErr;
                *cache
                    .entry(gl.id())
                    .or_insert_with(|| {
                        let program = gl.new_program()
                            .from_settings($settings)
                            .log_err("Error loading shader")
                            .map_err(|_| "")
                            .unwrap();

                        program
                            .set_uniform(&rin::gl::UBOBindingPoints::Camera.to_uniform_block_binding())
                            .unwrap();

                        crate::renderer::components::ProgramRef::new(programs.insert(program))
                    })
            })
        }
    }
}