Skip to main content

quickgpu/builders/
multisample_state_builder.rs

1// The code in this file is generated by a script. Do not edit it directly.
2//
3
4pub use super::super::Nested;
5pub use std::{borrow::Cow, num::NonZeroU32, ops::Range};
6pub trait Field {}
7pub trait IsOptional {}
8#[doc = "\nBuilder for [`wgpu::MultisampleState`]\n        \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n  - [count](MultisampleStateBuilder::count) Optional, defaults to `1`\n  - [mask](MultisampleStateBuilder::mask) Optional, defaults to `!0`\n  - [alpha_to_coverage_enabled](MultisampleStateBuilder::alpha_to_coverage_enabled) Optional, defaults to `false`\n"]
9pub struct MultisampleStateBuilder<CS: State> {
10    count: CS::Count,
11    mask: CS::Mask,
12    alpha_to_coverage_enabled: CS::AlphaToCoverageEnabled,
13}
14impl MultisampleStateBuilder<Empty> {
15    pub fn new() -> MultisampleStateBuilder<Empty> {
16        MultisampleStateBuilder {
17            count: CountEmpty,
18            mask: MaskEmpty,
19            alpha_to_coverage_enabled: AlphaToCoverageEnabledEmpty,
20        }
21    }
22}
23#[doc = "\nReturns [MultisampleStateBuilder] for building [`wgpu::MultisampleState`]\n        \nSet all required fields and any optional fields, then call `build()`.\n\nBuilder field setters:\n  - [count](MultisampleStateBuilder::count) Optional, defaults to `1`\n  - [mask](MultisampleStateBuilder::mask) Optional, defaults to `!0`\n  - [alpha_to_coverage_enabled](MultisampleStateBuilder::alpha_to_coverage_enabled) Optional, defaults to `false`\n"]
24pub fn multisample_state() -> MultisampleStateBuilder<Empty> {
25    MultisampleStateBuilder::new()
26}
27pub struct CountEmpty;
28impl Field for CountEmpty {}
29pub trait CountIsEmpty {}
30impl CountIsEmpty for CountEmpty {}
31pub trait IsSetCount {
32    fn get(self) -> u32;
33}
34impl IsSetCount for CountEmpty {
35    fn get(self) -> u32 {
36        1
37    }
38}
39pub struct CountValue(pub u32);
40impl Field for CountValue {}
41impl IsSetCount for CountValue {
42    fn get(self) -> u32 {
43        self.0
44    }
45}
46pub struct MaskEmpty;
47impl Field for MaskEmpty {}
48pub trait MaskIsEmpty {}
49impl MaskIsEmpty for MaskEmpty {}
50pub trait IsSetMask {
51    fn get(self) -> u64;
52}
53impl IsSetMask for MaskEmpty {
54    fn get(self) -> u64 {
55        !0
56    }
57}
58pub struct MaskValue(pub u64);
59impl Field for MaskValue {}
60impl IsSetMask for MaskValue {
61    fn get(self) -> u64 {
62        self.0
63    }
64}
65pub struct AlphaToCoverageEnabledEmpty;
66impl Field for AlphaToCoverageEnabledEmpty {}
67pub trait AlphaToCoverageEnabledIsEmpty {}
68impl AlphaToCoverageEnabledIsEmpty for AlphaToCoverageEnabledEmpty {}
69pub trait IsSetAlphaToCoverageEnabled {
70    fn get(self) -> bool;
71}
72impl IsSetAlphaToCoverageEnabled for AlphaToCoverageEnabledEmpty {
73    fn get(self) -> bool {
74        false
75    }
76}
77pub struct AlphaToCoverageEnabledValue(pub bool);
78impl Field for AlphaToCoverageEnabledValue {}
79impl IsSetAlphaToCoverageEnabled for AlphaToCoverageEnabledValue {
80    fn get(self) -> bool {
81        self.0
82    }
83}
84pub trait State {
85    type Count: Field;
86    type Mask: Field;
87    type AlphaToCoverageEnabled: Field;
88}
89pub struct Empty;
90impl State for Empty {
91    type Count = CountEmpty;
92    type Mask = MaskEmpty;
93    type AlphaToCoverageEnabled = AlphaToCoverageEnabledEmpty;
94}
95pub struct SetCount<CS>(CS);
96impl<CS: State> State for SetCount<CS> {
97    type Count = CountValue;
98    type Mask = CS::Mask;
99    type AlphaToCoverageEnabled = CS::AlphaToCoverageEnabled;
100}
101pub struct SetMask<CS>(CS);
102impl<CS: State> State for SetMask<CS> {
103    type Count = CS::Count;
104    type Mask = MaskValue;
105    type AlphaToCoverageEnabled = CS::AlphaToCoverageEnabled;
106}
107pub struct SetAlphaToCoverageEnabled<CS>(CS);
108impl<CS: State> State for SetAlphaToCoverageEnabled<CS> {
109    type Count = CS::Count;
110    type Mask = CS::Mask;
111    type AlphaToCoverageEnabled = AlphaToCoverageEnabledValue;
112}
113impl<CS: State> MultisampleStateBuilder<CS> {
114    #[doc = "Setter for [wgpu::MultisampleState::count]. Optional, defaults to `1`.\n"]
115    pub fn count(self, count: u32) -> MultisampleStateBuilder<SetCount<CS>>
116    where
117        CS::Count: CountIsEmpty,
118    {
119        MultisampleStateBuilder {
120            count: CountValue(count),
121            mask: self.mask,
122            alpha_to_coverage_enabled: self.alpha_to_coverage_enabled,
123        }
124    }
125    #[doc = "Setter for [wgpu::MultisampleState::mask]. Optional, defaults to `!0`.\n"]
126    pub fn mask(self, mask: u64) -> MultisampleStateBuilder<SetMask<CS>>
127    where
128        CS::Mask: MaskIsEmpty,
129    {
130        MultisampleStateBuilder {
131            count: self.count,
132            mask: MaskValue(mask),
133            alpha_to_coverage_enabled: self.alpha_to_coverage_enabled,
134        }
135    }
136    #[doc = "Setter for [wgpu::MultisampleState::alpha_to_coverage_enabled]. Optional, defaults to `false`.\n"]
137    pub fn alpha_to_coverage_enabled(
138        self,
139        alpha_to_coverage_enabled: bool,
140    ) -> MultisampleStateBuilder<SetAlphaToCoverageEnabled<CS>>
141    where
142        CS::AlphaToCoverageEnabled: AlphaToCoverageEnabledIsEmpty,
143    {
144        MultisampleStateBuilder {
145            count: self.count,
146            mask: self.mask,
147            alpha_to_coverage_enabled: AlphaToCoverageEnabledValue(alpha_to_coverage_enabled),
148        }
149    }
150}
151pub trait Complete:
152    State<Count: IsSetCount, Mask: IsSetMask, AlphaToCoverageEnabled: IsSetAlphaToCoverageEnabled>
153{
154}
155impl<
156        CS: State<
157            Count: IsSetCount,
158            Mask: IsSetMask,
159            AlphaToCoverageEnabled: IsSetAlphaToCoverageEnabled,
160        >,
161    > Complete for CS
162{
163}
164impl<CS: Complete> MultisampleStateBuilder<CS> {
165    pub fn build(self) -> wgpu::MultisampleState {
166        wgpu::MultisampleState {
167            count: IsSetCount::get(self.count),
168            mask: IsSetMask::get(self.mask),
169            alpha_to_coverage_enabled: IsSetAlphaToCoverageEnabled::get(
170                self.alpha_to_coverage_enabled,
171            ),
172        }
173    }
174}
175impl Nested<wgpu::MultisampleState> for wgpu::MultisampleState {
176    fn unnest(self) -> wgpu::MultisampleState {
177        self
178    }
179}
180impl<CS: Complete> Nested<wgpu::MultisampleState> for MultisampleStateBuilder<CS> {
181    fn unnest(self) -> wgpu::MultisampleState {
182        self.build()
183    }
184}
185#[cfg(test)]
186mod tests {
187    #[allow(unused_imports)]
188    #[allow(unused_imports)]
189    use std::num::NonZeroU32;
190    #[test]
191    pub fn test_default() {
192        assert_eq!(
193            format!("{:#?}", super::multisample_state().build()),
194            format!("{:#?}", wgpu::MultisampleState::default()),
195        );
196    }
197}