[−][src]Struct tetra::graphics::shader::Shader
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
- Avec2
representing the position of the vertex in world space.a_uv
- Avec2
representing the texture co-ordinates that are associated with the vertex.a_color
- Avec4
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
- Amat4
which can be used to translate world space co-ordinates into screen space.u_texture
- Asampler2D
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]
ctx: &mut Context,
vertex_path: P,
fragment_path: P
) -> Result<Shader> where
P: AsRef<Path>,
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]
P: AsRef<Path>,
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]
P: AsRef<Path>,
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]
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str
) -> Result<Shader>
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]
V: UniformValue,
Sets the value of the specifed uniform parameter.
Trait Implementations
impl Clone for Shader
[src]
fn clone(&self) -> Shader
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl PartialEq<Shader> for Shader
[src]
impl Debug for Shader
[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Same for T
type Output = T
Should always be Self
impl<SS, SP> SupersetOf for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
fn to_subset(&self) -> Option<SS>
fn is_in_subset(&self) -> bool
unsafe fn to_subset_unchecked(&self) -> SS
fn from_subset(element: &SS) -> SP
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
Sets value
as a parameter of self
.