1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/// Internal namespace.
mod private
{
use crate::*;
/// A builder for creating a `web_sys::GpuPrimitiveState`.
#[ derive( Default, Clone ) ]
pub struct PrimitiveState
{
/// The face culling mode.
///
/// Culling is a performance optimization that discards primitives facing away
/// from the camera. This field specifies whether to cull the front face, the back face,
/// or to disable culling entirely.
///
/// Defaults to `None`.
cull_mode : Option< GpuCullMode >,
/// The winding order that defines a "front-facing" primitive.
///
/// This is used in conjunction with `cull_mode` to determine which primitives
/// to discard. `Ccw` (counter-clockwise) is the standard for right-handed coordinate systems.
///
/// Defaults to `GpuFrontFace::Ccw`.
front_face : Option< GpuFrontFace >,
/// The primitive topology.
///
/// This specifies how the vertex data is assembled into primitives. Common
/// options include `TriangleList`, `PointList`, and `LineList`.
///
/// Defaults to `GpuPrimitiveTopology::TriangleList`.
topology : Option< GpuPrimitiveTopology >,
/// The index format for strip primitive topologies.
///
/// This is required when the `topology` is `LineStrip` or `TriangleStrip` to
/// specify the data type of the indices.
strip_index_format : Option< GpuIndexFormat >,
/// A flag to enable or disable unclipped depth.
///
/// When `true`, depth values are not clamped to the `[0, 1]` range, which
/// can be useful for certain rendering techniques like shadow mapping.
///
/// Defaults to `false`.
unclipped_depth : Option< bool >
}
impl PrimitiveState
{
/// Creates a new `PrimitiveState` with default values.
pub fn new() -> Self
{
Self::default()
}
/// Sets the cull mode to `None`, disabling culling.
pub fn cull_none( mut self ) -> Self
{
self.cull_mode = Some( GpuCullMode::None );
self
}
/// Sets the cull mode to `Front`, culling front-facing primitives.
pub fn cull_front( mut self ) -> Self
{
self.cull_mode = Some( GpuCullMode::Front );
self
}
/// Sets the cull mode to `Back`, culling back-facing primitives.
pub fn cull_back( mut self ) -> Self
{
self.cull_mode = Some( GpuCullMode::Back );
self
}
/// Sets the front face winding order to `Cw` (clockwise).
pub fn cw( mut self ) -> Self
{
self.front_face = Some( GpuFrontFace::Cw );
self
}
/// Enables unclipped depth.
///
/// This is a convenience method that sets `unclipped_depth` to `Some(true)`.
pub fn unclipped_depth( mut self ) -> Self
{
self.unclipped_depth = Some( true );
self
}
/// Sets the primitive topology.
pub fn topology( mut self, topology : GpuPrimitiveTopology ) -> Self
{
self.topology = Some( topology );
self
}
/// Sets the topology to `PointList`.
///
/// This is a convenience method for a common topology.
pub fn points( mut self ) -> Self
{
self.topology = Some( GpuPrimitiveTopology::PointList );
self
}
/// Sets the topology to `LineList`.
pub fn lines( mut self ) -> Self
{
self.topology = Some( GpuPrimitiveTopology::LineList );
self
}
/// Sets the topology to `TriangleList`.
pub fn triangles( mut self ) -> Self
{
self.topology = Some( GpuPrimitiveTopology::TriangleList );
self
}
/// Sets the topology to `LineStrip`.
pub fn line_strip( mut self ) -> Self
{
self.topology = Some( GpuPrimitiveTopology::LineStrip );
self
}
/// Sets the topology to `TriangleStrip`.
pub fn triangle_strip( mut self ) -> Self
{
self.topology = Some( GpuPrimitiveTopology::TriangleStrip );
self
}
}
impl From< PrimitiveState > for web_sys::GpuPrimitiveState
{
fn from( value: PrimitiveState ) -> Self
{
let state = web_sys::GpuPrimitiveState::new();
if let Some( v ) = value.cull_mode { state.set_cull_mode( v ); }
if let Some( v ) = value.front_face { state.set_front_face( v ); }
if let Some( v ) = value.topology { state.set_topology( v ); }
if let Some( v ) = value.strip_index_format { state.set_strip_index_format( v ); }
if let Some( v ) = value.unclipped_depth { state.set_unclipped_depth( v ); }
state
}
}
}
crate::mod_interface!
{
exposed use
{
PrimitiveState
};
}