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
/// Internal namespace.
mod private
{
use crate::*;
/// A builder for creating a `web_sys::GpuBlendComponent`.
#[ derive( Default, Clone ) ]
pub struct BlendComponent
{
/// The blend factor for the source color.
///
/// This factor is multiplied with the source color (the output of the
/// fragment shader) before the blend operation is applied.
///
/// Defaults to `GpuBlendFactor::One`.
src_factor : Option< web_sys::GpuBlendFactor >,
/// The blend factor for the destination color.
///
/// This factor is multiplied with the destination color (the value already
/// in the render target) before the blend operation is applied.
///
/// Defaults to `GpuBlendFactor::Zero`.
dst_factor : Option< web_sys::GpuBlendFactor >,
/// The blend operation to perform on the source and destination colors.
///
/// This defines how the factored source and destination colors are combined.
/// Common operations include `Add`, `Subtract`, `ReverseSubtract`, etc.
///
/// Defaults to `GpuBlendOperation::Add`.
operation : Option< web_sys::GpuBlendOperation >
}
impl BlendComponent
{
/// Creates a new `BlendComponent` with default values.
pub fn new() -> Self
{
Self::default()
}
/// Sets the source blend factor.
pub fn src_factor( mut self, factor : GpuBlendFactor ) -> Self
{
self.src_factor = Some( factor );
self
}
/// Sets the destination blend factor.
pub fn dst_factor( mut self, factor : GpuBlendFactor ) -> Self
{
self.dst_factor = Some( factor );
self
}
/// Sets the blend operation.
pub fn operation( mut self, operation : GpuBlendOperation ) -> Self
{
self.operation = Some( operation );
self
}
}
impl From< BlendComponent > for web_sys::GpuBlendComponent
{
fn from( value: BlendComponent ) -> Self
{
let c = web_sys::GpuBlendComponent::new();
if let Some( v ) = value.src_factor { c.set_src_factor( v ); }
if let Some( v ) = value.dst_factor { c.set_dst_factor( v ); }
if let Some( v ) = value.operation { c.set_operation( v ); }
c
}
}
/// A builder for creating a `web_sys::GpuBlendState`.
#[ derive( Default, Clone ) ]
pub struct BlendState
{
/// The blending configuration for the alpha channel.
alpha : BlendComponent,
/// The blending configuration for the color channels (red, green, and blue).
color : BlendComponent
}
impl BlendState
{
/// Creates a new `BlendState` with default values.
pub fn new() -> Self
{
Self::default()
}
/// Sets the blending configuration for the alpha channel.
pub fn alpha( mut self, alpha : BlendComponent ) -> Self
{
self.alpha = alpha;
self
}
/// Sets the blending configuration for the color channels.
pub fn color( mut self, color : BlendComponent ) -> Self
{
self.color = color;
self
}
}
impl From< BlendState > for web_sys::GpuBlendState
{
fn from( value: BlendState ) -> Self
{
let state = web_sys::GpuBlendState::new
(
&value.alpha.into(),
&value.color.into()
);
state
}
}
}
crate::mod_interface!
{
exposed use
{
BlendState,
BlendComponent
};
}