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 afi::GraphicBuilder;
use adi_gpu;
use Window;
pub use adi_gpu::DisplayTrait;
pub use adi_gpu::TextureTrait;
#[macro_export] macro_rules! textures {
( $window:expr, $decode:expr, $( $x:expr ),*) => {
&[ $( $crate::Texture::new($window,
$decode(include_bytes!($x)).unwrap()) ),* ]
}
}
#[derive(Copy,Clone)]
pub struct Texture(pub(crate) adi_gpu::Texture);
impl Texture {
pub fn new(window: &mut Window, image_data: ::afi::Graphic) -> Texture {
Texture(window.window.texture(image_data))
}
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))
}
pub fn new_vec<F>(window: &mut Window,
loader: F, files: &[&[u8]])
-> Result<Vec<Texture>, ::afi::GraphicDecodeErr>
where F: Fn(&[u8]) -> Result<::afi::Graphic, ::afi::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.0.wh()
}
pub fn set(&mut self, window: &mut Window, data: &[u32]) -> () {
window.window.set_texture(&mut self.0, data);
}
}