Struct wgsl_preprocessor::ShaderBuilder
source · [−]pub struct ShaderBuilder {
pub source_string: String,
/* private fields */
}
Expand description
Wraps shader code, changes it and builds it into a wgpu::ShaderModuleDescriptor
.
Fields
source_string: String
String with the current WGSL source. It is marked public for debugging purposes.
Implementations
sourceimpl ShaderBuilder
impl ShaderBuilder
sourcepub fn new(source_path: &str) -> Result<Self, Error>
pub fn new(source_path: &str) -> Result<Self, Error>
Creates a new ShaderBuilder
.
Arguments
source_path
- Path to the root WGSL module. All includes will be relative to the parent directory of the root WGSL module. Code is generated recursively with attention toinclude
anddefine
statements. See “Examples” for more details on include and macro functionality.
sourcepub fn put_constant(&mut self, name: &str, value: impl WGSLType) -> &mut Self
pub fn put_constant(&mut self, name: &str, value: impl WGSLType) -> &mut Self
Performs the WGSL’s parallel to C’s #define
statement.
Arguments
name
- Name of the constant; the string to replace in the code.value
- Value of the constant.
sourcepub fn put_constant_map(
&mut self,
constant_map: &HashMap<&str, impl WGSLType + Copy>
) -> &mut Self
pub fn put_constant_map(
&mut self,
constant_map: &HashMap<&str, impl WGSLType + Copy>
) -> &mut Self
Calls ShaderBuilder::put_constant
for every (key, value) pair in a given HashMap
.
sourcepub fn put_array_definition<'a, T: 'a + WGSLType>(
&'a mut self,
name: &str,
array: &Vec<&T>
) -> &'a mut Self
pub fn put_array_definition<'a, T: 'a + WGSLType>(
&'a mut self,
name: &str,
array: &Vec<&T>
) -> &'a mut Self
sourcepub fn build(&self) -> ShaderModuleDescriptor<'_>
pub fn build(&self) -> ShaderModuleDescriptor<'_>
Builds a wgpu::ShaderModuleDescriptor
from the shader.
The label
member of the built wgpu::ShaderModuleDescriptor
is the name of the shader file without the postfix.
Auto Trait Implementations
impl RefUnwindSafe for ShaderBuilder
impl Send for ShaderBuilder
impl Sync for ShaderBuilder
impl Unpin for ShaderBuilder
impl UnwindSafe for ShaderBuilder
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more