1use mtl_foundation::{Integer, UInteger};
6
7#[repr(transparent)]
11#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
12pub struct PrimitiveType(pub UInteger);
13
14impl PrimitiveType {
15 pub const POINT: Self = Self(0);
16 pub const LINE: Self = Self(1);
17 pub const LINE_STRIP: Self = Self(2);
18 pub const TRIANGLE: Self = Self(3);
19 pub const TRIANGLE_STRIP: Self = Self(4);
20}
21
22#[repr(transparent)]
26#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
27pub struct VisibilityResultMode(pub UInteger);
28
29impl VisibilityResultMode {
30 pub const DISABLED: Self = Self(0);
31 pub const BOOLEAN: Self = Self(1);
32 pub const COUNTING: Self = Self(2);
33}
34
35#[repr(transparent)]
39#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
40pub struct CullMode(pub UInteger);
41
42impl CullMode {
43 pub const NONE: Self = Self(0);
44 pub const FRONT: Self = Self(1);
45 pub const BACK: Self = Self(2);
46}
47
48#[repr(transparent)]
52#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
53pub struct Winding(pub UInteger);
54
55impl Winding {
56 pub const CLOCKWISE: Self = Self(0);
57 pub const COUNTER_CLOCKWISE: Self = Self(1);
58}
59
60#[repr(transparent)]
64#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
65pub struct DepthClipMode(pub UInteger);
66
67impl DepthClipMode {
68 pub const CLIP: Self = Self(0);
69 pub const CLAMP: Self = Self(1);
70}
71
72#[repr(transparent)]
76#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
77pub struct TriangleFillMode(pub UInteger);
78
79impl TriangleFillMode {
80 pub const FILL: Self = Self(0);
81 pub const LINES: Self = Self(1);
82}
83
84#[repr(transparent)]
88#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
89pub struct RenderStages(pub UInteger);
90
91impl RenderStages {
92 pub const VERTEX: Self = Self(1);
93 pub const FRAGMENT: Self = Self(1 << 1);
94 pub const TILE: Self = Self(1 << 2);
95 pub const OBJECT: Self = Self(1 << 3);
96 pub const MESH: Self = Self(1 << 4);
97
98 #[inline]
100 pub const fn bits(&self) -> UInteger {
101 self.0
102 }
103
104 #[inline]
106 pub const fn from_bits(bits: UInteger) -> Self {
107 Self(bits)
108 }
109
110 #[inline]
112 pub const fn is_empty(&self) -> bool {
113 self.0 == 0
114 }
115
116 #[inline]
118 pub const fn contains(&self, other: Self) -> bool {
119 (self.0 & other.0) == other.0
120 }
121}
122
123impl std::ops::BitOr for RenderStages {
124 type Output = Self;
125 #[inline]
126 fn bitor(self, rhs: Self) -> Self {
127 Self(self.0 | rhs.0)
128 }
129}
130
131impl std::ops::BitAnd for RenderStages {
132 type Output = Self;
133 #[inline]
134 fn bitand(self, rhs: Self) -> Self {
135 Self(self.0 & rhs.0)
136 }
137}
138
139impl std::ops::BitOrAssign for RenderStages {
140 #[inline]
141 fn bitor_assign(&mut self, rhs: Self) {
142 self.0 |= rhs.0;
143 }
144}
145
146#[repr(transparent)]
150#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
151pub struct LoadAction(pub UInteger);
152
153impl LoadAction {
154 pub const DONT_CARE: Self = Self(0);
155 pub const LOAD: Self = Self(1);
156 pub const CLEAR: Self = Self(2);
157}
158
159#[repr(transparent)]
163#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
164pub struct StoreAction(pub UInteger);
165
166impl StoreAction {
167 pub const DONT_CARE: Self = Self(0);
168 pub const STORE: Self = Self(1);
169 pub const MULTISAMPLE_RESOLVE: Self = Self(2);
170 pub const STORE_AND_MULTISAMPLE_RESOLVE: Self = Self(3);
171 pub const UNKNOWN: Self = Self(4);
172 pub const CUSTOM_SAMPLE_DEPTH_STORE: Self = Self(5);
173}
174
175#[repr(transparent)]
179#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
180pub struct StoreActionOptions(pub UInteger);
181
182impl StoreActionOptions {
183 pub const NONE: Self = Self(0);
184 pub const CUSTOM_SAMPLE_POSITIONS: Self = Self(1);
185 pub const VALID_MASK: Self = Self(1);
186
187 #[inline]
189 pub const fn bits(&self) -> UInteger {
190 self.0
191 }
192
193 #[inline]
195 pub const fn from_bits(bits: UInteger) -> Self {
196 Self(bits)
197 }
198}
199
200impl std::ops::BitOr for StoreActionOptions {
201 type Output = Self;
202 #[inline]
203 fn bitor(self, rhs: Self) -> Self {
204 Self(self.0 | rhs.0)
205 }
206}
207
208#[repr(transparent)]
212#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
213pub struct VisibilityResultType(pub Integer);
214
215impl VisibilityResultType {
216 pub const RESET: Self = Self(0);
217 pub const ACCUMULATE: Self = Self(1);
218}
219
220#[repr(transparent)]
224#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
225pub struct MultisampleDepthResolveFilter(pub UInteger);
226
227impl MultisampleDepthResolveFilter {
228 pub const SAMPLE0: Self = Self(0);
229 pub const MIN: Self = Self(1);
230 pub const MAX: Self = Self(2);
231}
232
233#[repr(transparent)]
237#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Hash)]
238pub struct MultisampleStencilResolveFilter(pub UInteger);
239
240impl MultisampleStencilResolveFilter {
241 pub const SAMPLE0: Self = Self(0);
242 pub const DEPTH_RESOLVED_SAMPLE: Self = Self(1);
243}
244
245#[cfg(test)]
246mod tests {
247 use super::*;
248
249 #[test]
250 fn test_primitive_type_values() {
251 assert_eq!(PrimitiveType::POINT.0, 0);
252 assert_eq!(PrimitiveType::TRIANGLE.0, 3);
253 }
254
255 #[test]
256 fn test_cull_mode_values() {
257 assert_eq!(CullMode::NONE.0, 0);
258 assert_eq!(CullMode::FRONT.0, 1);
259 assert_eq!(CullMode::BACK.0, 2);
260 }
261
262 #[test]
263 fn test_render_stages_bitor() {
264 let stages = RenderStages::VERTEX | RenderStages::FRAGMENT;
265 assert!(stages.contains(RenderStages::VERTEX));
266 assert!(stages.contains(RenderStages::FRAGMENT));
267 }
268}