[][src]Module fna3d::mojo

MojoShader types and some helpers

This module has some helpers in addition to the original items.

Effect

Effect is an abstraction over shaders in XNA. It's actually not so good but we have to stick with it if we use FNA3D.

For compiling fx_2_0 on macOS Catalina, see this repository.

Column-major

MojoShader uses column-major matrices, where position vectors are considered as column vectors.

FNA is using row-major matrices while MojoShader is column-major. If you're using a row-major framework, you have to transpose your matrix when you set it to the projection matrix of MojoShader.

Example

Orthographic projection matrix loading:

use std::path::Path;

/// SpriteEffect.fxb with orthographic projection matrix
pub fn load_2d_shader(
    device: &fna3d::Device,
    shader_path: impl AsRef<Path>,
) -> fna3d::mojo::Result<(*mut fna3d::Effect, *mut fna3d::mojo::Effect)> {
    let (effect, effect_data) = fna3d::mojo::from_file(device, shader_path)?;
    let mat = fna3d::mojo::orthographic_off_center(0.0, 1280.0, 720.0, 0.0, 1.0, 0.0);
    let name = std::ffi::CString::new("MatrixTransform").unwrap();
    unsafe {
        assert!(fna3d::mojo::set_param(effect_data, &name, &mat));
    }
    Ok((effect, effect_data))
}

SpriteEffect.fxb could be used for the shader_path.

Dispose

crate::Effect loaded with a helper in this modules have to be disposed with Device::add_dispose_effect. Then crate::mojo::Effect is also disposed.

Enums

LoadShaderError

Functions

find_param

Tries to find a shader parameter with name

from_bytes

Helper for loading shader. Be sure to set projection matrix after loading!

from_file

Helper for loading shader. Be sure to set projection matrix after loading!

orthographic_off_center

Column-major orthographic matrix

set_param

Returns true if the parameter is found

Type Definitions

Effect
EffectParam
EffectStateChanges
EffectTechnique
Result