1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::RenderBundleEncoderDescriptor`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [color_formats](RenderBundleEncoderDescriptorBuilder::color_formats) Optional, defaults to [::core::default::Default::default()]\n - [depth_stencil](RenderBundleEncoderDescriptorBuilder::depth_stencil) Optional, defaults to `None`\n - [sample_count](RenderBundleEncoderDescriptorBuilder::sample_count) Optional, defaults to `0u32`\n - [multiview](RenderBundleEncoderDescriptorBuilder::multiview) Optional, defaults to `None`\n"]
9pub struct RenderBundleEncoderDescriptorBuilder<'a, CS: State<'a>> {
10 label: CS::Label,
11 color_formats: CS::ColorFormats,
12 depth_stencil: CS::DepthStencil,
13 sample_count: CS::SampleCount,
14 multiview: CS::Multiview,
15}
16impl<'a> RenderBundleEncoderDescriptorBuilder<'a, Empty> {
17 pub fn new() -> RenderBundleEncoderDescriptorBuilder<'a, Empty> {
18 RenderBundleEncoderDescriptorBuilder {
19 label: LabelEmpty,
20 color_formats: ColorFormatsEmpty,
21 depth_stencil: DepthStencilEmpty,
22 sample_count: SampleCountEmpty,
23 multiview: MultiviewEmpty,
24 }
25 }
26}
27#[doc = "\nReturns [RenderBundleEncoderDescriptorBuilder] for building [`wgpu::RenderBundleEncoderDescriptor`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [color_formats](RenderBundleEncoderDescriptorBuilder::color_formats) Optional, defaults to [::core::default::Default::default()]\n - [depth_stencil](RenderBundleEncoderDescriptorBuilder::depth_stencil) Optional, defaults to `None`\n - [sample_count](RenderBundleEncoderDescriptorBuilder::sample_count) Optional, defaults to `0u32`\n - [multiview](RenderBundleEncoderDescriptorBuilder::multiview) Optional, defaults to `None`\n"]
28pub fn render_bundle_encoder_descriptor<'a>(
29 label: wgpu::Label<'a>,
30) -> RenderBundleEncoderDescriptorBuilder<'a, SetLabel<Empty>> {
31 RenderBundleEncoderDescriptorBuilder::new().label(label)
32}
33pub struct LabelEmpty;
34impl Field for LabelEmpty {}
35pub trait LabelIsEmpty {}
36impl LabelIsEmpty for LabelEmpty {}
37pub trait IsSetLabel<'a> {
38 fn get(self) -> wgpu::Label<'a>;
39}
40impl<'a> IsSetLabel<'a> for LabelEmpty {
41 fn get(self) -> wgpu::Label<'a> {
42 None
43 }
44}
45pub struct LabelValue<'a>(pub wgpu::Label<'a>);
46impl<'a> Field for LabelValue<'a> {}
47impl<'a> IsSetLabel<'a> for LabelValue<'a> {
48 fn get(self) -> wgpu::Label<'a> {
49 self.0
50 }
51}
52pub struct ColorFormatsEmpty;
53impl Field for ColorFormatsEmpty {}
54pub trait ColorFormatsIsEmpty {}
55impl ColorFormatsIsEmpty for ColorFormatsEmpty {}
56pub trait IsSetColorFormats<'a> {
57 fn get(self) -> &'a [Option<wgpu::TextureFormat>];
58}
59impl<'a> IsSetColorFormats<'a> for ColorFormatsEmpty {
60 fn get(self) -> &'a [Option<wgpu::TextureFormat>] {
61 ::core::default::Default::default()
62 }
63}
64pub struct ColorFormatsValue<'a>(pub &'a [Option<wgpu::TextureFormat>]);
65impl<'a> Field for ColorFormatsValue<'a> {}
66impl<'a> IsSetColorFormats<'a> for ColorFormatsValue<'a> {
67 fn get(self) -> &'a [Option<wgpu::TextureFormat>] {
68 self.0
69 }
70}
71pub struct DepthStencilEmpty;
72impl Field for DepthStencilEmpty {}
73pub trait DepthStencilIsEmpty {}
74impl DepthStencilIsEmpty for DepthStencilEmpty {}
75pub trait IsSetDepthStencil {
76 fn get(self) -> Option<wgpu::RenderBundleDepthStencil>;
77}
78impl IsSetDepthStencil for DepthStencilEmpty {
79 fn get(self) -> Option<wgpu::RenderBundleDepthStencil> {
80 None
81 }
82}
83pub struct DepthStencilValue(pub Option<wgpu::RenderBundleDepthStencil>);
84impl Field for DepthStencilValue {}
85impl IsSetDepthStencil for DepthStencilValue {
86 fn get(self) -> Option<wgpu::RenderBundleDepthStencil> {
87 self.0
88 }
89}
90pub struct SampleCountEmpty;
91impl Field for SampleCountEmpty {}
92pub trait SampleCountIsEmpty {}
93impl SampleCountIsEmpty for SampleCountEmpty {}
94pub trait IsSetSampleCount {
95 fn get(self) -> u32;
96}
97impl IsSetSampleCount for SampleCountEmpty {
98 fn get(self) -> u32 {
99 0u32
100 }
101}
102pub struct SampleCountValue(pub u32);
103impl Field for SampleCountValue {}
104impl IsSetSampleCount for SampleCountValue {
105 fn get(self) -> u32 {
106 self.0
107 }
108}
109pub struct MultiviewEmpty;
110impl Field for MultiviewEmpty {}
111pub trait MultiviewIsEmpty {}
112impl MultiviewIsEmpty for MultiviewEmpty {}
113pub trait IsSetMultiview {
114 fn get(self) -> Option<NonZeroU32>;
115}
116impl IsSetMultiview for MultiviewEmpty {
117 fn get(self) -> Option<NonZeroU32> {
118 None
119 }
120}
121pub struct MultiviewValue(pub Option<NonZeroU32>);
122impl Field for MultiviewValue {}
123impl IsSetMultiview for MultiviewValue {
124 fn get(self) -> Option<NonZeroU32> {
125 self.0
126 }
127}
128pub trait State<'a> {
129 type Label: Field;
130 type ColorFormats: Field;
131 type DepthStencil: Field;
132 type SampleCount: Field;
133 type Multiview: Field;
134}
135pub struct Empty;
136impl<'a> State<'a> for Empty {
137 type Label = LabelEmpty;
138 type ColorFormats = ColorFormatsEmpty;
139 type DepthStencil = DepthStencilEmpty;
140 type SampleCount = SampleCountEmpty;
141 type Multiview = MultiviewEmpty;
142}
143pub struct SetLabel<CS>(CS);
144impl<'a, CS: State<'a>> State<'a> for SetLabel<CS> {
145 type Label = LabelValue<'a>;
146 type ColorFormats = CS::ColorFormats;
147 type DepthStencil = CS::DepthStencil;
148 type SampleCount = CS::SampleCount;
149 type Multiview = CS::Multiview;
150}
151pub struct SetColorFormats<CS>(CS);
152impl<'a, CS: State<'a>> State<'a> for SetColorFormats<CS> {
153 type Label = CS::Label;
154 type ColorFormats = ColorFormatsValue<'a>;
155 type DepthStencil = CS::DepthStencil;
156 type SampleCount = CS::SampleCount;
157 type Multiview = CS::Multiview;
158}
159pub struct SetDepthStencil<CS>(CS);
160impl<'a, CS: State<'a>> State<'a> for SetDepthStencil<CS> {
161 type Label = CS::Label;
162 type ColorFormats = CS::ColorFormats;
163 type DepthStencil = DepthStencilValue;
164 type SampleCount = CS::SampleCount;
165 type Multiview = CS::Multiview;
166}
167pub struct SetSampleCount<CS>(CS);
168impl<'a, CS: State<'a>> State<'a> for SetSampleCount<CS> {
169 type Label = CS::Label;
170 type ColorFormats = CS::ColorFormats;
171 type DepthStencil = CS::DepthStencil;
172 type SampleCount = SampleCountValue;
173 type Multiview = CS::Multiview;
174}
175pub struct SetMultiview<CS>(CS);
176impl<'a, CS: State<'a>> State<'a> for SetMultiview<CS> {
177 type Label = CS::Label;
178 type ColorFormats = CS::ColorFormats;
179 type DepthStencil = CS::DepthStencil;
180 type SampleCount = CS::SampleCount;
181 type Multiview = MultiviewValue;
182}
183impl<'a, CS: State<'a>> RenderBundleEncoderDescriptorBuilder<'a, CS> {
184 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::label]. Optional, defaults to `None`.\n"]
185 pub fn label(
186 self,
187 label: wgpu::Label<'a>,
188 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetLabel<CS>>
189 where
190 CS::Label: LabelIsEmpty,
191 {
192 RenderBundleEncoderDescriptorBuilder {
193 label: LabelValue(label),
194 color_formats: self.color_formats,
195 depth_stencil: self.depth_stencil,
196 sample_count: self.sample_count,
197 multiview: self.multiview,
198 }
199 }
200 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::color_formats]. Optional, defaults to [::core::default::Default::default()].\n"]
201 pub fn color_formats(
202 self,
203 color_formats: &'a [Option<wgpu::TextureFormat>],
204 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetColorFormats<CS>>
205 where
206 CS::ColorFormats: ColorFormatsIsEmpty,
207 {
208 RenderBundleEncoderDescriptorBuilder {
209 label: self.label,
210 color_formats: ColorFormatsValue(color_formats),
211 depth_stencil: self.depth_stencil,
212 sample_count: self.sample_count,
213 multiview: self.multiview,
214 }
215 }
216 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::depth_stencil]. Optional, defaults to `None`.\n"]
217 pub fn depth_stencil(
218 self,
219 depth_stencil: impl Nested<wgpu::RenderBundleDepthStencil>,
220 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetDepthStencil<CS>>
221 where
222 CS::DepthStencil: DepthStencilIsEmpty,
223 {
224 RenderBundleEncoderDescriptorBuilder {
225 label: self.label,
226 color_formats: self.color_formats,
227 depth_stencil: DepthStencilValue(Some(Nested::unnest(depth_stencil))),
228 sample_count: self.sample_count,
229 multiview: self.multiview,
230 }
231 }
232 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::depth_stencil]. Optional, defaults to `None`.\n"]
233 pub fn maybe_depth_stencil(
234 self,
235 depth_stencil: impl Nested<Option<wgpu::RenderBundleDepthStencil>>,
236 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetDepthStencil<CS>>
237 where
238 CS::DepthStencil: DepthStencilIsEmpty,
239 {
240 RenderBundleEncoderDescriptorBuilder {
241 label: self.label,
242 color_formats: self.color_formats,
243 depth_stencil: DepthStencilValue(Nested::unnest(depth_stencil)),
244 sample_count: self.sample_count,
245 multiview: self.multiview,
246 }
247 }
248 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::sample_count]. Optional, defaults to `0u32`.\n"]
249 pub fn sample_count(
250 self,
251 sample_count: u32,
252 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetSampleCount<CS>>
253 where
254 CS::SampleCount: SampleCountIsEmpty,
255 {
256 RenderBundleEncoderDescriptorBuilder {
257 label: self.label,
258 color_formats: self.color_formats,
259 depth_stencil: self.depth_stencil,
260 sample_count: SampleCountValue(sample_count),
261 multiview: self.multiview,
262 }
263 }
264 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::multiview]. Optional, defaults to `None`.\n"]
265 pub fn multiview(
266 self,
267 multiview: NonZeroU32,
268 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetMultiview<CS>>
269 where
270 CS::Multiview: MultiviewIsEmpty,
271 {
272 RenderBundleEncoderDescriptorBuilder {
273 label: self.label,
274 color_formats: self.color_formats,
275 depth_stencil: self.depth_stencil,
276 sample_count: self.sample_count,
277 multiview: MultiviewValue(Some(multiview)),
278 }
279 }
280 #[doc = "Setter for [wgpu::RenderBundleEncoderDescriptor::multiview]. Optional, defaults to `None`.\n"]
281 pub fn maybe_multiview(
282 self,
283 multiview: Option<NonZeroU32>,
284 ) -> RenderBundleEncoderDescriptorBuilder<'a, SetMultiview<CS>>
285 where
286 CS::Multiview: MultiviewIsEmpty,
287 {
288 RenderBundleEncoderDescriptorBuilder {
289 label: self.label,
290 color_formats: self.color_formats,
291 depth_stencil: self.depth_stencil,
292 sample_count: self.sample_count,
293 multiview: MultiviewValue(multiview),
294 }
295 }
296}
297pub trait Complete<'a>:
298 State<
299 'a,
300 Label: IsSetLabel<'a>,
301 ColorFormats: IsSetColorFormats<'a>,
302 DepthStencil: IsSetDepthStencil,
303 SampleCount: IsSetSampleCount,
304 Multiview: IsSetMultiview,
305>
306{
307}
308impl<
309 'a,
310 CS: State<
311 'a,
312 Label: IsSetLabel<'a>,
313 ColorFormats: IsSetColorFormats<'a>,
314 DepthStencil: IsSetDepthStencil,
315 SampleCount: IsSetSampleCount,
316 Multiview: IsSetMultiview,
317 >,
318 > Complete<'a> for CS
319{
320}
321impl<'a, CS: Complete<'a>> RenderBundleEncoderDescriptorBuilder<'a, CS> {
322 pub fn build(self) -> wgpu::RenderBundleEncoderDescriptor<'a> {
323 wgpu::RenderBundleEncoderDescriptor {
324 label: IsSetLabel::get(self.label),
325 color_formats: IsSetColorFormats::get(self.color_formats),
326 depth_stencil: IsSetDepthStencil::get(self.depth_stencil),
327 sample_count: IsSetSampleCount::get(self.sample_count),
328 multiview: IsSetMultiview::get(self.multiview),
329 }
330 }
331}
332impl<'a> Nested<wgpu::RenderBundleEncoderDescriptor<'a>>
333 for wgpu::RenderBundleEncoderDescriptor<'a>
334{
335 fn unnest(self) -> wgpu::RenderBundleEncoderDescriptor<'a> {
336 self
337 }
338}
339impl<'a, CS: Complete<'a>> Nested<wgpu::RenderBundleEncoderDescriptor<'a>>
340 for RenderBundleEncoderDescriptorBuilder<'a, CS>
341{
342 fn unnest(self) -> wgpu::RenderBundleEncoderDescriptor<'a> {
343 self.build()
344 }
345}
346#[cfg(test)]
347mod tests {
348 #[allow(unused_imports)]
349 #[allow(unused_imports)]
350 use std::num::NonZeroU32;
351 #[test]
352 pub fn test_default() {
353 assert_eq!(
354 format!(
355 "{:#?}",
356 super::render_bundle_encoder_descriptor(Option::<&str>::None).build()
357 ),
358 format!("{:#?}", wgpu::RenderBundleEncoderDescriptor::default()),
359 );
360 }
361}