Struct bottomless_pit::shader::Shader
source · pub struct Shader { /* private fields */ }Expand description
An internal representation of an WGSL Shader. Under the hood this creates a new pipeline with or without the support for any extra uniforms. To be utilze the shader it must be added to a material
Implementations§
source§impl Shader
impl Shader
sourcepub fn new<P: AsRef<Path>>(
path: P,
has_uniforms: bool,
engine: &mut Engine
) -> ResourceId<Shader>
pub fn new<P: AsRef<Path>>( path: P, has_uniforms: bool, engine: &mut Engine ) -> ResourceId<Shader>
Attempts to create a shader from a file. This will halt the engine due to resource loading please see the resource module for more information.
Examples found in repository?
examples/ngon.rs (line 30)
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
fn main() {
let mut engine = EngineBuilder::new()
.with_resolution((500, 500))
.remove_vsync()
.set_clear_colour(Colour::BLACK)
.build()
.unwrap();
let data = Time {
time: 0.0,
_pading: 0.0,
_padding2: 0.0,
_padding4: 0.0,
};
let uniform_data = UniformData::new(&engine, &data);
let mouse_shader = Shader::new("examples/sinewaves.wgsl", true, &mut engine);
let regular_material = MaterialBuilder::new()
.set_uniform(&uniform_data)
.set_shader(mouse_shader)
.build(&mut engine);
let pos = Position {
regular_material,
time: 0.0,
};
engine.run(pos);
}More examples
examples/shader.rs (line 18)
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
fn main() {
let mut engine = EngineBuilder::new()
.set_clear_colour(Colour::WHITE)
.build()
.unwrap();
let mouse_shader = Shader::new("examples/mouse.wgsl", true, &mut engine);
let circle_shader = Shader::new("examples/movement.wgsl", true, &mut engine);
let data = MousePos {
x: 0.0,
y: 0.0,
_junk: 0.0,
_padding2: 0.0,
};
let mouse_uniform_data = UniformData::new(&engine, &data);
// On wasm we need this to be 16 bytes aligned so we have added this instead of
// a 0.0_f32
let circle_uniform_data = UniformData::new(&engine, &data);
let mouse_material = MaterialBuilder::new()
.set_shader(mouse_shader)
.set_uniform(&mouse_uniform_data)
.build(&mut engine);
let circle_material = MaterialBuilder::new()
.set_shader(circle_shader)
.set_uniform(&circle_uniform_data)
.build(&mut engine);
let defualt_material = MaterialBuilder::new().build(&mut engine);
let game = ShaderExample {
data,
mouse_material,
circle_material,
defualt_material,
theta: 0.0,
};
engine.run(game);
}sourcepub fn from_btyes(
engine: &mut Engine,
has_uniforms: bool,
bytes: &[u8]
) -> ResourceId<Shader>
pub fn from_btyes( engine: &mut Engine, has_uniforms: bool, bytes: &[u8] ) -> ResourceId<Shader>
Attempts to create a shader from a byte array, this will not halt the engine. See the resource module for more information on this halting behavior.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Shader
impl Send for Shader
impl Sync for Shader
impl Unpin for Shader
impl !UnwindSafe for Shader
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more