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
63
64
65
66
67
68
69
use crate::Id;
use crate::assets::{ Assets, Texture };
use crate::renderer::{ Renderer, TextureBuffer };
pub const FACES_COUNT: usize = 6;
#[derive(Default)]
pub struct CubeMap {
pub right: Id<Texture>,
pub left: Id<Texture>,
pub top: Id<Texture>,
pub bottom: Id<Texture>,
pub back: Id<Texture>,
pub front: Id<Texture>,
pub buffer: TextureBuffer,
}
impl CubeMap {
pub fn load(&mut self, renderer: &Renderer, assets: &mut Assets) -> bool {
if self.loaded() {
return true;
}
let faces = [
self.right,
self.left,
self.top,
self.bottom,
self.back,
self.front,
];
let mut textures = Vec::with_capacity(FACES_COUNT);
let mut width = 0;
let mut height = 0;
for &id in faces.iter() {
if let Some(texture) = assets.get(id) {
width = texture.width;
height = texture.height;
textures.push(texture.data.as_slice());
} else {
return false;
}
}
renderer.load_texture_buffer(&mut self.buffer, width, height, textures.as_slice());
true
}
pub fn loaded(&self) -> bool {
self.buffer.loaded()
}
pub fn unload(&mut self) {
self.buffer.unload();
}
}