1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use densevec::DenseVec;

#[derive(Default, Clone, Debug)]
pub struct UniformsCache{
    cache: DenseVec<Vec<glin::program::Uniform>>,
}

impl UniformsCache{
    pub fn new() -> UniformsCache {
        UniformsCache::default()
    }

    pub fn uniforms<C, F>(&mut self, gl: &super::Renderer<C>, f: F) -> &[glin::program::Uniform]
    where C: glin::RenderSurface,
        F: FnOnce() -> Vec<glin::program::Uniform>,
    {
        self.cache.entry(gl.id()).or_insert_with(f)
    }

    pub fn invalidate(&mut self) {
        self.cache.clear()
    }
}