[][src]Struct tetra::graphics::shader::Shader

pub struct Shader { /* fields omitted */ }

A shader program, consisting of a vertex shader and a fragment shader.

This type acts as a lightweight handle to the associated graphics hardware data, and so can be cloned with little overhead.

Vertex Shaders

Vertex shaders take in data via three attributes:

  • a_position - A vec2 representing the position of the vertex in world space.
  • a_uv - A vec2 representing the texture co-ordinates that are associated with the vertex.
  • a_color - A vec4 representing a color to multiply the output by.

Fragment Shaders

Fragment shaders have a single vec4 output called o_color - this should be set to the desired output color for the fragment.

Uniforms

By default, the shader is provided with two uniform variables:

  • u_projection - A mat4 which can be used to translate world space co-ordinates into screen space.
  • u_texture - A sampler2D which can be used to access color data from the currently active texture.

You can also set data into your own uniform variables via the set_uniform method.

Methods

impl Shader[src]

pub fn new<P>(
    ctx: &mut Context,
    vertex_path: P,
    fragment_path: P
) -> Result<Shader> where
    P: AsRef<Path>, 
[src]

Creates a new shader program from the given files.

Errors

If the file could not be read, a TetraError::Io will be returned.

If the shader could not be compiled, a TetraError::OpenGl will be returned.

pub fn vertex<P>(ctx: &mut Context, path: P) -> Result<Shader> where
    P: AsRef<Path>, 
[src]

Creates a new shader program from the given vertex shader file.

The default fragment shader will be used.

Errors

If the file could not be read, a TetraError::Io will be returned.

If the shader could not be compiled, a TetraError::OpenGl will be returned.

pub fn fragment<P>(ctx: &mut Context, path: P) -> Result<Shader> where
    P: AsRef<Path>, 
[src]

Creates a new shader program from the given fragment shader file.

The default vertex shader will be used.

Errors

If the file could not be read, a TetraError::Io will be returned.

If the shader could not be compiled, a TetraError::OpenGl will be returned.

pub fn from_string(
    ctx: &mut Context,
    vertex_shader: &str,
    fragment_shader: &str
) -> Result<Shader>
[src]

Creates a new shader program from the given strings.

Errors

If the shader could not be compiled, a TetraError::OpenGl will be returned.

pub fn set_uniform<V>(&mut self, ctx: &mut Context, name: &str, value: V) where
    V: UniformValue
[src]

Sets the value of the specifed uniform parameter.

Trait Implementations

impl PartialEq<Shader> for Shader[src]

impl Clone for Shader[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl Debug for Shader[src]

Auto Trait Implementations

impl !Send for Shader

impl !Sync for Shader

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<T> Same for T

type Output = T

Should always be Self

impl<SS, SP> SupersetOf for SP where
    SS: SubsetOf<SP>, 

impl<T> SetParameter for T

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
    T: Parameter<Self>, 

Sets value as a parameter of self.