gpu/data/textures/
type.rs

1// ref https://www.khronos.org/registry/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
2
3/// Types used by the GPU.
4#[derive(Clone)]
5pub enum Type {
6    /// 8bits unsigned integer.
7    U8,
8    /// 16bits unsigned integer.
9    U16,
10    /// 32bits unsigned integer.
11    U32,
12    /// 8bits signed integer.
13    I8,
14    /// 16bits signed integer.
15    I16,
16    /// 32bits signed integer.
17    I32,
18    /// 16bits float.
19    F16,
20    /// 32bits float.
21    F32,
22}
23
24impl Type {
25    /// Gets the size in bytes.
26    pub fn size(&self) -> usize {
27        match self {
28            Type::U8  | Type::I8 => 1,
29            Type::U16 | Type::I16 | Type::F16 => 2,
30            Type::U32 | Type::I32 | Type::F32 => 4
31        }
32    }
33
34    /// Gets `OpenGL` internal reprensetation.
35    pub fn format(&self) -> u32 {
36        match self {
37            Type::U8  => glow::UNSIGNED_BYTE,
38            Type::U16 => glow::UNSIGNED_SHORT,
39            Type::U32 => glow::UNSIGNED_INT,
40            Type::I8  => glow::BYTE,
41            Type::I16 => glow::SHORT,
42            Type::I32 => glow::INT,
43            Type::F16 => glow::HALF_FLOAT,
44            Type::F32 => glow::FLOAT
45        }
46    }
47}