Skip to main content

Shaders

Struct Shaders 

Source
pub struct Shaders {
    pub shader_330: ShaderPair,
    pub shader_110: ShaderPair,
    pub shader_300_es: ShaderPair,
    pub shader_100_es: ShaderPair,
}
Expand description

Contains the shader code for a spritesheet.

Passed to the renderer with SpritesheetBuilder::shaders.

§The GLSL versions

As you might need to include tweaks for every GLSL version, you can provide versions of your shader code for each. However, usually the #version 100/#version 110 and #version 300 es/#version 330 shaders are identical aside from the version string. To make this use-case more ergonomic, you can just leave the version preprocessor line out, and the relevant one is inserted during runtime. Then you can use the same ShaderPair for shader_110 and shader_100, for example.

Additionally: if you don’t include a version preprocessor, precision mediump float; is added to the shader’s OpenGL ES version (in addition to the automatically inserted version preprocessor), as it’s required in OpenGL ES shaders but not desktop OpenGL ones.

As an example, the following shader_300_es code:

void main() {}

Will be modified into the following in an OpenGL ES 3.0 context:

#version 300 es
precision mediump float;
void main() {}

§Example

use fae::{Shaders, SpritesheetBuilder};

// If you want to just change the fragment shaders, create a default Shaders:
let mut shaders = Shaders::default();

// And then apply your changes:
shaders.shader_330.fragment_shader = fragment_shader_code_330.clone();
shaders.shader_300_es.fragment_shader = fragment_shader_code_330;
shaders.shader_110.fragment_shader = fragment_shader_code_110.clone();
shaders.shader_100_es.fragment_shader = fragment_shader_code_110;

// Then you can use the shaders when creating a Spritesheet:
let spritesheet = SpritesheetBuilder::default()
    .shaders(shaders)
    .build(&mut ctx);

Fields§

§shader_330: ShaderPair

The #version 330 version of the shader, for OpenGL 3.3 and above.

§shader_110: ShaderPair

The #version 110 version of the shader, for OpenGL versions before 3.3.

§shader_300_es: ShaderPair

The #version 300 es version of the shader, for OpenGL ES 3.0 and WebGL 2.0.

§shader_100_es: ShaderPair

The #version 100 version of the shader, for OpenGL ES 2.0 and WebGL 1.0.

Trait Implementations§

Source§

impl Clone for Shaders

Source§

fn clone(&self) -> Shaders

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Shaders

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Shaders

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.