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
/// Internal namespace.
mod private
{
use crate::*;
/// A builder for creating a `web_sys::GpuVertexState`.
#[ derive( Clone ) ]
pub struct VertexState< 'a >
{
/// The required shader module containing the vertex shader code.
///
/// This is the compiled representation of the WGSL vertex shader.
module : &'a web_sys::GpuShaderModule,
/// An optional name of the entry point function within the shader module.
///
/// If not specified, the WebGPU implementation will typically look for a
/// default entry point, like "main".
///
/// Defaults to `None`.
entry_point : Option< &'a str >,
/// A list of vertex buffer layouts.
///
/// Each `GpuVertexBufferLayout` describes the memory layout of a single
/// vertex buffer, including its stride and attributes.
buffers : Vec< web_sys::GpuVertexBufferLayout >
}
impl< 'a > VertexState< 'a >
{
/// Creates a new `VertexState` builder with a required shader module.
pub fn new( module : &'a web_sys::GpuShaderModule ) -> Self
{
let entry_point = None;
let buffers = Vec::new();
VertexState
{
module,
entry_point,
buffers
}
}
/// Sets the entry point function name for the vertex shader.
pub fn entry_point( mut self, entry : &'a str ) -> Self
{
self.entry_point = Some( entry );
self
}
/// Adds a vertex buffer layout to the list of buffers.
pub fn buffer( mut self, buffer : &web_sys::GpuVertexBufferLayout ) -> Self
{
self.buffers.push( buffer.clone() );
self
}
}
impl From< VertexState< '_ > > for web_sys::GpuVertexState
{
fn from( value: VertexState< '_ > ) -> Self
{
let state = web_sys::GpuVertexState::new( &value.module );
if let Some( v ) = value.entry_point { state.set_entry_point( v ); }
if !value.buffers.is_empty() { state.set_buffers( &value.buffers.into() ); }
state
}
}
}
crate::mod_interface!
{
exposed use
{
VertexState
};
}