[][src]Trait crevice::std140::AsStd140

pub trait AsStd140 {
    type Std140Type: Std140;
    fn as_std140(&self) -> Self::Std140Type;

    fn std140_size(&self) -> usize { ... }
}

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 geometry crates, like cgmath, nalgebra, and ultraviolet support mint.

Example

uniform CAMERA {
    mat4 view;
    mat4 projection;
} camera;
use cgmath::prelude::*;
use cgmath::{Matrix4, Deg, perspective};
use crevice::std140::{AsStd140, Std140};

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

let camera = CameraUniform {
    view: Matrix4::identity().into(),
    projection: perspective(Deg(60.0), 16.0/9.0, 0.01, 100.0).into(),
};

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

Associated Types

type Std140Type: Std140

The std140 version of this value.

Loading content...

Required methods

fn as_std140(&self) -> Self::Std140Type

Convert this value into the std140 version of itself.

Loading content...

Provided methods

fn std140_size(&self) -> usize

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

Loading content...

Implementations on Foreign Types

impl AsStd140 for Vector2<f32>[src]

type Std140Type = Vec2

impl AsStd140 for Vector3<f32>[src]

type Std140Type = Vec3

impl AsStd140 for Vector4<f32>[src]

type Std140Type = Vec4

impl AsStd140 for ColumnMatrix2<f32>[src]

type Std140Type = Mat2

impl AsStd140 for ColumnMatrix3<f32>[src]

type Std140Type = Mat3

impl AsStd140 for ColumnMatrix4<f32>[src]

type Std140Type = Mat4

Loading content...

Implementors

impl<T> AsStd140 for T where
    T: Std140
[src]

type Std140Type = Self

impl<T: AsStd140> AsStd140 for DynamicUniform<T>[src]

Loading content...