Skip to main content

lumen_engine_gpu/
geometry.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub struct Size {
3    pub width: u32,
4    pub height: u32,
5}
6
7impl Size {
8    pub const fn new(width: u32, height: u32) -> Self {
9        Self { width, height }
10    }
11
12    pub fn as_extent(self) -> wgpu::Extent3d {
13        wgpu::Extent3d {
14            width: self.width.max(1),
15            height: self.height.max(1),
16            depth_or_array_layers: 1,
17        }
18    }
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
22pub struct RectI {
23    pub x: i32,
24    pub y: i32,
25    pub width: u32,
26    pub height: u32,
27}
28
29impl RectI {
30    pub const fn new(x: i32, y: i32, width: u32, height: u32) -> Self {
31        Self {
32            x,
33            y,
34            width,
35            height,
36        }
37    }
38
39    pub const fn from_size(size: Size) -> Self {
40        Self::new(0, 0, size.width, size.height)
41    }
42}
43
44#[derive(Debug, Clone, Copy, PartialEq, Eq)]
45pub struct TextureDomain {
46    pub storage_size: Size,
47    pub display_rect: RectI,
48    pub data_rect: RectI,
49}
50
51impl TextureDomain {
52    pub const fn full_frame(size: Size) -> Self {
53        let rect = RectI::from_size(size);
54        Self {
55            storage_size: size,
56            display_rect: rect,
57            data_rect: rect,
58        }
59    }
60}