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
//!
//! Unassigned helpful utilities.
//!

pub enum ShaderStage {
    Vertex,
    Fragment,
    Compute,
}

pub fn load_glsl(code: &str, stage: ShaderStage) -> Vec<u32> {
    let ty = match stage {
        ShaderStage::Vertex => glsl_to_spirv::ShaderType::Vertex,
        ShaderStage::Fragment => glsl_to_spirv::ShaderType::Fragment,
        ShaderStage::Compute => glsl_to_spirv::ShaderType::Compute,
    };

    wgpu::read_spirv(glsl_to_spirv::compile(&code, ty).unwrap()).unwrap()
}

pub trait RoundToMultiple {
    fn round_to_multiple(&self, multiple: i32) -> Self;
}

impl RoundToMultiple for f32 {
    fn round_to_multiple(&self, multiple: i32) -> f32 {
        let number = *self;

        if number < 0.0 {
            let number = (number.floor() as i32) * -1;
            -(((number + multiple - 1) / multiple) * multiple) as f32
        } else {
            let number = number.ceil() as i32;
            (((number + multiple - 1) / multiple) * multiple) as f32
        }
    }
}