logo

Trait bevy::render::render_resource::std140::AsStd140[]

pub trait AsStd140 {
    type Output: Std140;
    fn as_std140(&self) -> Self::Output;
fn from_std140(val: Self::Output) -> Self; fn std140_size_static() -> usize { ... } }
Expand description

Trait implemented for all types that can be turned into std140 values.

This trait can often be #[derive]’d instead of manually implementing it. Any struct which contains only fields that also implement AsStd140 can derive AsStd140.

Types from the mint crate implement AsStd140, making them convenient for use in uniform types. Most Rust math crates, like cgmath, nalgebra, and ultraviolet support mint.

Example

uniform CAMERA {
    mat4 view;
    mat4 projection;
} camera;
use bevy_crevice::std140::{AsStd140, Std140};

#[derive(AsStd140)]
struct CameraUniform {
    view: mint::ColumnMatrix4<f32>,
    projection: mint::ColumnMatrix4<f32>,
}

let view: mint::ColumnMatrix4<f32> = todo!("your math code here");
let projection: mint::ColumnMatrix4<f32> = todo!("your math code here");

let camera = CameraUniform {
    view,
    projection,
};

let camera_std140 = camera.as_std140();
write_to_gpu_buffer(camera_std140.as_bytes());

Associated Types

The std140 version of this value.

Required methods

Convert this value into the std140 version of itself.

Converts from std140 version of self to self.

Provided methods

Returns the size of the std140 version of this type. Useful for pre-sizing buffers.

Implementations on Foreign Types

Implementors