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
/// Internal namespace.
mod private
{
use crate::*;
/// A builder for creating a `web_sys::GpuRenderPassDescriptor`.
#[ derive( Clone ) ]
pub struct RenderPassDescriptor< 'a >
{
/// A list of color attachments for the render pass.
/// Each attachment specifies a texture to render into.
color_attachments : Vec< web_sys::GpuRenderPassColorAttachment >,
/// An optional depth-stencil attachment. This is used for depth testing
/// and stencil operations during rendering.
///
/// Defaults to `None`.
depth_stencil_attachment : Option< web_sys::GpuRenderPassDepthStencilAttachment >,
/// An optional label for the render pass. This is useful for debugging
/// and profiling in GPU tools.
///
/// Defaults to `None`.
label : Option< &'a str >,
/// An optional maximum number of draw calls that can be issued
/// within this render pass. This can be used for performance
/// optimization or error checking.
///
/// Defaults to `None`/ 50000000.
max_draw_count : Option< f64 >
}
impl< 'a > RenderPassDescriptor< 'a >
{
/// Creates a new `RenderPassDescriptor` with default values.
pub fn new() -> Self
{
let color_attachments = Vec::new();
let depth_stencil_attachment = None;
let label = None;
let max_draw_count = None;
RenderPassDescriptor
{
color_attachments,
depth_stencil_attachment,
label,
max_draw_count
}
}
/// Adds a color attachment to the descriptor.
pub fn color_attachment
(
mut self,
color_attachment : impl Into< web_sys::GpuRenderPassColorAttachment >
) -> Self
{
self.color_attachments.push( color_attachment.into() );
self
}
/// Sets the depth-stencil attachment for the descriptor.
pub fn depth_stencil_attachment
(
mut self,
depth_stencil_attachment : impl Into< web_sys::GpuRenderPassDepthStencilAttachment >
) -> Self
{
self.depth_stencil_attachment = Some( depth_stencil_attachment.into() );
self
}
/// Sets the debug label for the render pass.
pub fn label( mut self, label : &'a str ) -> Self
{
self.label = Some( label );
self
}
/// Sets the maximum draw count for the render pass.
pub fn max_draw_count( mut self, count : f64 ) -> Self
{
self.max_draw_count = Some( count );
self
}
}
impl From< RenderPassDescriptor< '_ > > for web_sys::GpuRenderPassDescriptor {
fn from( value: RenderPassDescriptor< '_ > ) -> Self
{
let desc = web_sys::GpuRenderPassDescriptor::new( &value.color_attachments.into() );
if let Some( v ) = value.depth_stencil_attachment { desc.set_depth_stencil_attachment( &v ); }
if let Some( v ) = value.label { desc.set_label( v ); }
if let Some( v ) = value.max_draw_count { desc.set_max_draw_count( v ); }
desc
}
}
}
crate::mod_interface!
{
exposed use
{
RenderPassDescriptor
};
}