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
use crate::prelude::*;
use macroquad::prelude::draw_texture_ex;

#[derive(Debug, Copy, Clone)]
pub struct Texture {
    texture: Texture2D,
    height_map: Option<Texture2D>,
    normal_map: Option<Texture2D>,
}

impl Texture {
    pub fn new(
        texture: Texture2D,
        height_map: Option<Texture2D>,
        normal_map: Option<Texture2D>,
    ) -> Self {
        Texture {
            texture,
            height_map,
            normal_map,
        }
    }

    pub fn has_height_map(&self) -> bool {
        self.height_map.is_some()
    }

    pub fn has_normal_map(&self) -> bool {
        self.normal_map.is_some()
    }

    pub fn get(&self) -> Texture2D {
        self.texture
    }

    pub fn get_height_map(&self) -> Option<Texture2D> {
        self.normal_map
    }

    pub fn get_normal_map(&self) -> Option<Texture2D> {
        self.normal_map
    }

    pub fn draw(&self, position: Vec2, color: Option<Color>, params: DrawTextureParams) {
        draw_texture_ex(
            self.texture,
            position.x,
            position.y,
            color.unwrap_or(color::WHITE),
            params,
        )
    }
}

pub fn draw_texture(
    texture: &Texture,
    position: Vec2,
    color: Option<Color>,
    params: DrawTextureParams,
) {
    texture.draw(position, color, params)
}