pub trait AsStd430 {
type Output: Std430;
fn as_std430(&self) -> Self::Output;
fn from_std430(value: Self::Output) -> Self;
fn std430_size_static() -> usize { ... }
}
Expand description
Trait implemented for all types that can be turned into std430
values.
This trait can often be #[derive]
’d instead of manually implementing it. Any
struct which contains only fields that also implement AsStd430
can derive
AsStd430
.
Types from the mint crate implement AsStd430
, making them convenient for use
in uniform types. Most Rust geometry crates, like cgmath, nalgebra, and
ultraviolet support mint.
Example
uniform CAMERA {
mat4 view;
mat4 projection;
} camera;
use bevy_crevice::std430::{AsStd430, Std430};
#[derive(AsStd430)]
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_std430 = camera.as_std430();
write_to_gpu_buffer(camera_std430.as_bytes());
Associated Types
Required methods
fn from_std430(value: Self::Output) -> Self
fn from_std430(value: Self::Output) -> Self
Converts from std430
version of self to self.
Provided methods
fn std430_size_static() -> usize
fn std430_size_static() -> usize
Returns the size of the std430
version of this type. Useful for
pre-sizing buffers.