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
/// Internal namespace.
mod private
{
use crate::*;
/// A builder-style struct for creating a `GpuShaderModule`.
pub struct ShaderModule< 'a >
{
/// The source code of the shader, typically written in WGSL.
code : &'a str,
/// An optional label for debugging and identification purposes.
label : Option< &'a str >
}
impl< 'a > ShaderModule< 'a >
{
/// Creates a new `ShaderModule` instance with a given shader source code.
pub fn new( code : &'a str ) -> Self
{
let label = None;
ShaderModule
{
code,
label
}
}
/// Sets an optional label for the shader module.
pub fn label( mut self, label : &'a str ) -> Self
{
self.label = Some( label );
self
}
/// Creates the `GpuShaderModule` using the configured properties.
pub fn create( self, device : &web_sys::GpuDevice ) -> web_sys::GpuShaderModule
{
let desc = web_sys::GpuShaderModuleDescriptor::new( &self.code );
if let Some( v ) = self.label { desc.set_label( v ); }
let shader = device.create_shader_module( &desc );
shader
}
}
/// A convenience function to create a `GpuShaderModule` with just the code.
pub fn create( device : &web_sys::GpuDevice, code : &str ) -> web_sys::GpuShaderModule
{
ShaderModule::new( code ).create( device )
}
}
crate::mod_interface!
{
own use
{
create
};
exposed use
{
ShaderModule
};
}