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
use swapchain::Swapchain;
use vk;
#[derive(Debug, Clone)]
pub struct PresentRegion {
pub rectangles: Vec<RectangleLayer>,
}
impl PresentRegion {
pub fn is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool {
self.rectangles
.iter()
.all(|rect| rect.is_compatible_with(swapchain))
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct RectangleLayer {
pub offset: [i32; 2],
pub extent: [u32; 2],
pub layer: u32,
}
impl RectangleLayer {
pub fn is_compatible_with<W>(&self, swapchain: &Swapchain<W>) -> bool {
debug_assert!(self.offset[0] >= 0);
debug_assert!(self.offset[1] >= 0);
self.offset[0] as u32 + self.extent[0] <= swapchain.dimensions()[0] &&
self.offset[1] as u32 + self.extent[1] <= swapchain.dimensions()[1] &&
self.layer < swapchain.layers()
}
pub(crate) fn to_vk(&self) -> vk::RectLayerKHR {
vk::RectLayerKHR {
offset: vk::Offset2D {
x: self.offset[0],
y: self.offset[1],
},
extent: vk::Extent2D {
width: self.extent[0],
height: self.extent[1],
},
layer: self.layer,
}
}
}