quickgpu/builders/
render_pass_depth_stencil_attachment_builder.rs1pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::RenderPassDepthStencilAttachment`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [view](RenderPassDepthStencilAttachmentBuilder::view) Required\n - [depth_ops](RenderPassDepthStencilAttachmentBuilder::depth_ops) Optional, defaults to `None`\n - [stencil_ops](RenderPassDepthStencilAttachmentBuilder::stencil_ops) Optional, defaults to `None`\n"]
9pub struct RenderPassDepthStencilAttachmentBuilder<'tex, CS: State<'tex>> {
10 view: CS::View,
11 depth_ops: CS::DepthOps,
12 stencil_ops: CS::StencilOps,
13}
14impl<'tex> RenderPassDepthStencilAttachmentBuilder<'tex, Empty> {
15 pub fn new() -> RenderPassDepthStencilAttachmentBuilder<'tex, Empty> {
16 RenderPassDepthStencilAttachmentBuilder {
17 view: ViewEmpty,
18 depth_ops: DepthOpsEmpty,
19 stencil_ops: StencilOpsEmpty,
20 }
21 }
22}
23#[doc = "\nReturns [RenderPassDepthStencilAttachmentBuilder] for building [`wgpu::RenderPassDepthStencilAttachment`]\n \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n - [view](RenderPassDepthStencilAttachmentBuilder::view) Required\n - [depth_ops](RenderPassDepthStencilAttachmentBuilder::depth_ops) Optional, defaults to `None`\n - [stencil_ops](RenderPassDepthStencilAttachmentBuilder::stencil_ops) Optional, defaults to `None`\n"]
24pub fn render_pass_depth_stencil_attachment<'tex>(
25) -> RenderPassDepthStencilAttachmentBuilder<'tex, Empty> {
26 RenderPassDepthStencilAttachmentBuilder::new()
27}
28pub struct ViewEmpty;
29impl Field for ViewEmpty {}
30pub trait ViewIsEmpty {}
31impl ViewIsEmpty for ViewEmpty {}
32pub trait IsSetView<'tex> {
33 fn get(self) -> &'tex wgpu::TextureView;
34}
35pub struct ViewValue<'tex>(pub &'tex wgpu::TextureView);
36impl<'tex> Field for ViewValue<'tex> {}
37impl<'tex> IsSetView<'tex> for ViewValue<'tex> {
38 fn get(self) -> &'tex wgpu::TextureView {
39 self.0
40 }
41}
42pub struct DepthOpsEmpty;
43impl Field for DepthOpsEmpty {}
44pub trait DepthOpsIsEmpty {}
45impl DepthOpsIsEmpty for DepthOpsEmpty {}
46pub trait IsSetDepthOps {
47 fn get(self) -> Option<wgpu::Operations<f32>>;
48}
49impl IsSetDepthOps for DepthOpsEmpty {
50 fn get(self) -> Option<wgpu::Operations<f32>> {
51 None
52 }
53}
54pub struct DepthOpsValue(pub Option<wgpu::Operations<f32>>);
55impl Field for DepthOpsValue {}
56impl IsSetDepthOps for DepthOpsValue {
57 fn get(self) -> Option<wgpu::Operations<f32>> {
58 self.0
59 }
60}
61pub struct StencilOpsEmpty;
62impl Field for StencilOpsEmpty {}
63pub trait StencilOpsIsEmpty {}
64impl StencilOpsIsEmpty for StencilOpsEmpty {}
65pub trait IsSetStencilOps {
66 fn get(self) -> Option<wgpu::Operations<u32>>;
67}
68impl IsSetStencilOps for StencilOpsEmpty {
69 fn get(self) -> Option<wgpu::Operations<u32>> {
70 None
71 }
72}
73pub struct StencilOpsValue(pub Option<wgpu::Operations<u32>>);
74impl Field for StencilOpsValue {}
75impl IsSetStencilOps for StencilOpsValue {
76 fn get(self) -> Option<wgpu::Operations<u32>> {
77 self.0
78 }
79}
80pub trait State<'tex> {
81 type View: Field;
82 type DepthOps: Field;
83 type StencilOps: Field;
84}
85pub struct Empty;
86impl<'tex> State<'tex> for Empty {
87 type View = ViewEmpty;
88 type DepthOps = DepthOpsEmpty;
89 type StencilOps = StencilOpsEmpty;
90}
91pub struct SetView<CS>(CS);
92impl<'tex, CS: State<'tex>> State<'tex> for SetView<CS> {
93 type View = ViewValue<'tex>;
94 type DepthOps = CS::DepthOps;
95 type StencilOps = CS::StencilOps;
96}
97pub struct SetDepthOps<CS>(CS);
98impl<'tex, CS: State<'tex>> State<'tex> for SetDepthOps<CS> {
99 type View = CS::View;
100 type DepthOps = DepthOpsValue;
101 type StencilOps = CS::StencilOps;
102}
103pub struct SetStencilOps<CS>(CS);
104impl<'tex, CS: State<'tex>> State<'tex> for SetStencilOps<CS> {
105 type View = CS::View;
106 type DepthOps = CS::DepthOps;
107 type StencilOps = StencilOpsValue;
108}
109impl<'tex, CS: State<'tex>> RenderPassDepthStencilAttachmentBuilder<'tex, CS> {
110 #[doc = "Setter for [wgpu::RenderPassDepthStencilAttachment::view]. Required.\n"]
111 pub fn view(
112 self,
113 view: &'tex wgpu::TextureView,
114 ) -> RenderPassDepthStencilAttachmentBuilder<'tex, SetView<CS>>
115 where
116 CS::View: ViewIsEmpty,
117 {
118 RenderPassDepthStencilAttachmentBuilder {
119 view: ViewValue(view),
120 depth_ops: self.depth_ops,
121 stencil_ops: self.stencil_ops,
122 }
123 }
124 #[doc = "Setter for [wgpu::RenderPassDepthStencilAttachment::depth_ops]. Optional, defaults to `None`.\n"]
125 pub fn depth_ops(
126 self,
127 depth_ops: impl Nested<wgpu::Operations<f32>>,
128 ) -> RenderPassDepthStencilAttachmentBuilder<'tex, SetDepthOps<CS>>
129 where
130 CS::DepthOps: DepthOpsIsEmpty,
131 {
132 RenderPassDepthStencilAttachmentBuilder {
133 view: self.view,
134 depth_ops: DepthOpsValue(Some(Nested::unnest(depth_ops))),
135 stencil_ops: self.stencil_ops,
136 }
137 }
138 #[doc = "Setter for [wgpu::RenderPassDepthStencilAttachment::depth_ops]. Optional, defaults to `None`.\n"]
139 pub fn maybe_depth_ops(
140 self,
141 depth_ops: impl Nested<Option<wgpu::Operations<f32>>>,
142 ) -> RenderPassDepthStencilAttachmentBuilder<'tex, SetDepthOps<CS>>
143 where
144 CS::DepthOps: DepthOpsIsEmpty,
145 {
146 RenderPassDepthStencilAttachmentBuilder {
147 view: self.view,
148 depth_ops: DepthOpsValue(Nested::unnest(depth_ops)),
149 stencil_ops: self.stencil_ops,
150 }
151 }
152 #[doc = "Setter for [wgpu::RenderPassDepthStencilAttachment::stencil_ops]. Optional, defaults to `None`.\n"]
153 pub fn stencil_ops(
154 self,
155 stencil_ops: impl Nested<wgpu::Operations<u32>>,
156 ) -> RenderPassDepthStencilAttachmentBuilder<'tex, SetStencilOps<CS>>
157 where
158 CS::StencilOps: StencilOpsIsEmpty,
159 {
160 RenderPassDepthStencilAttachmentBuilder {
161 view: self.view,
162 depth_ops: self.depth_ops,
163 stencil_ops: StencilOpsValue(Some(Nested::unnest(stencil_ops))),
164 }
165 }
166 #[doc = "Setter for [wgpu::RenderPassDepthStencilAttachment::stencil_ops]. Optional, defaults to `None`.\n"]
167 pub fn maybe_stencil_ops(
168 self,
169 stencil_ops: impl Nested<Option<wgpu::Operations<u32>>>,
170 ) -> RenderPassDepthStencilAttachmentBuilder<'tex, SetStencilOps<CS>>
171 where
172 CS::StencilOps: StencilOpsIsEmpty,
173 {
174 RenderPassDepthStencilAttachmentBuilder {
175 view: self.view,
176 depth_ops: self.depth_ops,
177 stencil_ops: StencilOpsValue(Nested::unnest(stencil_ops)),
178 }
179 }
180}
181pub trait Complete<'tex>:
182 State<'tex, View: IsSetView<'tex>, DepthOps: IsSetDepthOps, StencilOps: IsSetStencilOps>
183{
184}
185impl<
186 'tex,
187 CS: State<'tex, View: IsSetView<'tex>, DepthOps: IsSetDepthOps, StencilOps: IsSetStencilOps>,
188 > Complete<'tex> for CS
189{
190}
191impl<'tex, CS: Complete<'tex>> RenderPassDepthStencilAttachmentBuilder<'tex, CS> {
192 pub fn build(self) -> wgpu::RenderPassDepthStencilAttachment<'tex> {
193 wgpu::RenderPassDepthStencilAttachment {
194 view: IsSetView::get(self.view),
195 depth_ops: IsSetDepthOps::get(self.depth_ops),
196 stencil_ops: IsSetStencilOps::get(self.stencil_ops),
197 }
198 }
199}
200impl<'tex> Nested<wgpu::RenderPassDepthStencilAttachment<'tex>>
201 for wgpu::RenderPassDepthStencilAttachment<'tex>
202{
203 fn unnest(self) -> wgpu::RenderPassDepthStencilAttachment<'tex> {
204 self
205 }
206}
207impl<'tex, CS: Complete<'tex>> Nested<wgpu::RenderPassDepthStencilAttachment<'tex>>
208 for RenderPassDepthStencilAttachmentBuilder<'tex, CS>
209{
210 fn unnest(self) -> wgpu::RenderPassDepthStencilAttachment<'tex> {
211 self.build()
212 }
213}
214#[cfg(test)]
215mod tests {
216 #[allow(unused_imports)]
217 #[allow(unused_imports)]
218 use std::num::NonZeroU32;
219 #[test]
220 pub fn test_default() {
221 assert_eq!(
222 format!("{:#?}", super::IsSetDepthOps::get(super::DepthOpsEmpty)),
223 format!("{:#?}", Option::<wgpu::Operations<f32>>::default()),
224 );
225 assert_eq!(
226 format!("{:#?}", super::IsSetStencilOps::get(super::StencilOpsEmpty)),
227 format!("{:#?}", Option::<wgpu::Operations<u32>>::default()),
228 );
229 }
230}