Module luminance::shader::program [] [src]

Shader programs related types and functions.

A shader Program is an object representing several operations. It’s a streaming program that will operate on vertices, vertex patches, primitives and/or fragments.

Note: shader programs don’t have to run on all those objects; they can be ran only on vertices and fragments, for instance.

Creating a shader program is very simple. You need shader Stages representing each step of the processing. Here’s the actual mapping between the shader stage types and the processing unit:

  • Stage<TessellationControlShader>: ran on tessellation parameters ;
  • Stage<TessellationEvaluationShader>: ran on patches ;
  • Stage<VertexShader>: ran on vertices ;
  • Stage<GeometryShader>: ran on primitives ;
  • Stage<FragmentShader>: ran on screen fragments.

You have to provide at least a Stage<VertexShader> and a Stage<FragmentShader>. If you want tessellation processing, you need to provide both a Stage<TessellationControlShader> and a Stage<TessellationEvaluationShader>. If you want primitives processing, you need to add a Stage<GeometryShader>.

In order to customize the behavior of your shader programs, you have access to uniforms. For more details about them, see the documentation for the type Uniform and Uniformable. When creating a new shader program, you have to provide code to declare its uniform interface. The uniform interface refers to a type of your own that will be kept by the shader program and exposed to you when you’ll express the need to update its uniforms. That uniform interface is created via a closure you pass. That closure takes as arguments a ProgramProxy used to retrieve Uniforms from the program being constructed. That pattern, that can be a bit overwhelming at first, is important to keep things safe and functional. Keep in mind that you can make the closure fail, so that you can notify a Uniform lookup failure, for instance.

You can create a Program with its new associated function.

Example

// assume we have a vertex shader `vs` and fragment shader `fs`
let program = Program::new(None, &vs, None, &fs, |get_uni| {
  let resolution: Uniform<[f32; 2]> = try!(get_uni("resolution"));
  let time: Uniform<f32> = try!(get_uni("time"));

  Ok((resolution, time))
});

Structs

Program

A shader program with uniform interface.

ProgramProxy

Program proxy used to map uniforms. When building a Program, as the Program doesn’t exist yet, a ProgramProxy is passed to act as it was the Program.

Enums

ProgramError
UniformWarning

Traits

HasProgram

Trait to implement to provide shader program features.