Material

Trait Material 

Source
pub trait Material:
    Send
    + Sync
    + 'static {
    const TEXTURE_COUNT: u32;
    const DATA_SIZE: u32;

    // Required methods
    fn object_key(&self) -> u64;
    fn to_textures<'a>(&'a self, slice: &mut [Option<&'a TextureHandle>]);
    fn to_data(&self, slice: &mut [u8]);
}
Expand description

Interface that all materials must use.

The material will provide a set of textures, and a pile of bytes. It will then, as part of the material bind group, present the following abi:

§CpuDriven Profile

  • A uniform binding with:
    • The data provided, with padding up to 16 byte alignment.
    • A u32 bitflag telling which textures are null. To check if texture N is enabled, do (texture_bitflag >> N) & 0x1 == 1.
  • One Texture2D binding per texture, provided in the order given. If given a None, will bind a null texture (1x1 texture with a (0, 0, 0, 255) pixel).

§GpuDriven Profile

  • A material array indexed by the material index. Each material has:
    • One u32 per texture. If this value is 0, the texture doesn’t exist. If this value is non-zero, subtract one and index into the texture array to ge thte texture.
    • Padding to 16 byte alignemnet.
    • The data provided by the material.

Required Associated Constants§

Source

const TEXTURE_COUNT: u32

The texture count that will be provided to to_textures.

Source

const DATA_SIZE: u32

The amount of data that will be provided to to_data.

Required Methods§

Source

fn object_key(&self) -> u64

u64 key that determine’s an object’s archetype. When you query for objects from the object manager, you must provide this key to get all objects with this key.

Source

fn to_textures<'a>(&'a self, slice: &mut [Option<&'a TextureHandle>])

Fill up the given slice with textures.

Source

fn to_data(&self, slice: &mut [u8])

Fill up the given slice with binary material data. This can be whatever data a shader expects.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§