pub struct UniformData { /* private fields */ }
Expand description

UniformData contains the byte data of any struct that implements ShaderType which can be derived. This data needs to be added to a Material upon creation.

Implementations§

source§

impl UniformData

source

pub fn new<T: ShaderType + WriteInto>(engine: &Engine, data: &T) -> Self

Examples found in repository?
examples/ngon.rs (line 28)
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
Hide additional examples
examples/shader.rs (line 29)
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);
}

Trait Implementations§

source§

impl Debug for UniformData

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSync for T
where T: Sync,