logo
pub unsafe trait Shader {
    type StageRepr;
    type ProgramRepr;
    type UniformBuilderRepr;

    unsafe fn new_stage(
        &mut self,
        ty: StageType,
        src: &str
    ) -> Result<Self::StageRepr, StageError>; unsafe fn new_program(
        &mut self,
        vertex: &Self::StageRepr,
        tess: Option<TessellationStages<'_, Self::StageRepr>>,
        geometry: Option<&Self::StageRepr>,
        fragment: &Self::StageRepr
    ) -> Result<Self::ProgramRepr, ProgramError>; unsafe fn apply_semantics<Sem>(
        program: &mut Self::ProgramRepr
    ) -> Result<Vec<VertexAttribWarning>, ProgramError>
    where
        Sem: Semantics
; unsafe fn new_uniform_builder(
        program: &mut Self::ProgramRepr
    ) -> Result<Self::UniformBuilderRepr, ProgramError>; unsafe fn ask_uniform<T>(
        uniform_builder: &mut Self::UniformBuilderRepr,
        name: &str
    ) -> Result<Uniform<T>, UniformWarning>
    where
        Self: for<'u> Uniformable<'u, T>
; unsafe fn unbound<T>(
        uniform_builder: &mut Self::UniformBuilderRepr
    ) -> Uniform<T>
    where
        Self: for<'u> Uniformable<'u, T>
; }
Expand description

Shader support.

This trait provides several concepts as once, as they all depend on each other:

  • Shader stages.
  • Shader programs.
  • Uniform builders.

The associated type Shader::StageRepr is the backend representation of a shader stage. They are created with Shader::new_stage with a StageType representing the shader stage type that must be created. Because the backend might not support this type of shader stage, it might fail with a StageError.

Required Associated Types

Backend representation of a shader stage.

Backend representation of a shader program.

Backend representation of a uniform builder.

Required Methods

Create a new shader stage of type StageType.

Create a new shader program by combining several shader stages.

The vertex and fragment stages are mandatory. The other ones are optional and then must be inspected to check whether they were provided by the user.

Apply semantics.

This is a very specific operations that happen right after the shader program got successfully created by the backend. This function is responsible in setting whatever might be needed by the backend to allocate, prepare or validate the semantics — i.e. Sem which implements Semantics.

Construct a new uniform builder.

This method must create a uniform builder, which will be used when passed to the user.

Lookup a Uniform.

This method must lookup a Uniform and map it, or return the appropriate error.

Backend representation of an unbound Uniform (i.e. that is inactive in the shader program).

This is a method taking a uniform builder so that the builder can accumulate a state.

Implementors