1use mtl_foundation::UInteger;
6
7#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct BlitOption(pub UInteger);
13
14impl BlitOption {
15 pub const NONE: Self = Self(0);
16 pub const DEPTH_FROM_DEPTH_STENCIL: Self = Self(1);
17 pub const STENCIL_FROM_DEPTH_STENCIL: Self = Self(1 << 1);
18 pub const ROW_LINEAR_PVRTC: Self = Self(1 << 2);
19
20 #[inline]
22 pub const fn bits(&self) -> UInteger {
23 self.0
24 }
25
26 #[inline]
28 pub const fn from_bits(bits: UInteger) -> Self {
29 Self(bits)
30 }
31
32 #[inline]
34 pub const fn is_empty(&self) -> bool {
35 self.0 == 0
36 }
37
38 #[inline]
40 pub const fn contains(&self, other: Self) -> bool {
41 (self.0 & other.0) == other.0
42 }
43}
44
45impl std::ops::BitOr for BlitOption {
46 type Output = Self;
47 #[inline]
48 fn bitor(self, rhs: Self) -> Self {
49 Self(self.0 | rhs.0)
50 }
51}
52
53impl std::ops::BitAnd for BlitOption {
54 type Output = Self;
55 #[inline]
56 fn bitand(self, rhs: Self) -> Self {
57 Self(self.0 & rhs.0)
58 }
59}
60
61impl std::ops::BitOrAssign for BlitOption {
62 #[inline]
63 fn bitor_assign(&mut self, rhs: Self) {
64 self.0 |= rhs.0;
65 }
66}
67
68#[cfg(test)]
69mod tests {
70 use super::*;
71
72 #[test]
73 fn test_blit_option_values() {
74 assert_eq!(BlitOption::NONE.0, 0);
75 assert_eq!(BlitOption::DEPTH_FROM_DEPTH_STENCIL.0, 1);
76 assert_eq!(BlitOption::STENCIL_FROM_DEPTH_STENCIL.0, 2);
77 assert_eq!(BlitOption::ROW_LINEAR_PVRTC.0, 4);
78 }
79
80 #[test]
81 fn test_blit_option_bitor() {
82 let opt = BlitOption::DEPTH_FROM_DEPTH_STENCIL | BlitOption::STENCIL_FROM_DEPTH_STENCIL;
83 assert!(opt.contains(BlitOption::DEPTH_FROM_DEPTH_STENCIL));
84 assert!(opt.contains(BlitOption::STENCIL_FROM_DEPTH_STENCIL));
85 }
86}