aboutsummaryrefslogtreecommitdiff
path: root/stockton-render/src/draw/ui/texture.rs
blob: 0ec48731b751994fce8709e4fe8c05b3baff7170 (plain)
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
use crate::draw::texture::{LoadableImage, TextureRepo};
use crate::types::*;
use crate::UiState;
use egui::Texture;
use stockton_levels::{prelude::HasTextures, traits::textures::Texture as LTexture};

pub struct UiTextures;

impl HasTextures for UiTextures {
    type TexturesIter<'a> = std::slice::Iter<'a, LTexture>;

    fn textures_iter(&self) -> Self::TexturesIter<'_> {
        (&[]).iter()
    }

    fn get_texture(&self, _idx: u32) -> Option<&stockton_levels::prelude::textures::Texture> {
        None
    }
}

impl LoadableImage for &Texture {
    fn width(&self) -> u32 {
        self.width as u32
    }
    fn height(&self) -> u32 {
        self.height as u32
    }
    fn copy_row(&self, y: u32, ptr: *mut u8) {
        let row_size = self.width();
        let pixels = &self.pixels[(y * row_size) as usize..((y + 1) * row_size) as usize];

        for (i, x) in pixels.iter().enumerate() {
            unsafe {
                *ptr.offset(i as isize * 3) = *x;
                *ptr.offset((i as isize * 3) + 1) = *x;
                *ptr.offset((i as isize * 3) + 2) = *x;
            }
        }
    }

    unsafe fn copy_into(&self, _ptr: *mut u8, _row_size: usize) {
        todo!()
    }
}

pub fn ensure_textures(
    _tex_repo: &mut TextureRepo,
    ui: &mut UiState,
    _device: &mut DeviceT,
    _adapter: &mut Adapter,
    _allocator: &mut DynamicAllocator,
    _command_queue: &mut QueueT,
    _command_pool: &mut CommandPoolT,
) {
    let tex = ui.ctx.texture();

    if tex.version != ui.last_tex_ver {
        // tex_repo.force_queue_load(0).unwrap(); // TODO
        ui.last_tex_ver = tex.version;
    }
}