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
use Graphic;
use GraphicBuilder;
use GraphicDecodeErr;
use adi_gpu;
use Window;
pub struct Texture(pub(crate) adi_gpu::Texture, pub(crate) u32, pub(crate) u32);
impl Texture {
#[doc(hidden)]
pub fn new(window: &mut Window, image_data: Graphic) -> Texture {
let (w, h, _) = image_data.as_slice();
Texture(window.window.texture(&image_data), w, h)
}
pub fn empty(window: &mut Window, w: u32, h: u32) -> Texture {
let size = (w as usize) * (h as usize);
let graphic = GraphicBuilder::new().rgba(w, h, vec![0; size]);
Texture(window.window.texture(&graphic), w, h)
}
pub fn new_vec<F>(window: &mut Window,
loader: F, files: &[&[u8]])
-> Result<Vec<Texture>, GraphicDecodeErr>
where F: Fn(&[u8]) -> Result<Graphic, GraphicDecodeErr>
{
let mut textures = Vec::new();
for i in files {
textures.push(Texture::new(window, loader(i)?));
}
Ok(textures)
}
pub fn wh(&self) -> (u32, u32) {
(self.1, self.2)
}
pub fn set(&mut self, window: &mut Window, data: &[u32]) -> () {
window.window.set_texture(&mut self.0, data);
}
}