pub struct Shader { /* private fields */ }
Expand description
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.
Implementations§
source§impl Shader
impl Shader
sourcepub fn new<P>(
ctx: &mut Context,
vertex_path: P,
fragment_path: P
) -> Result<Shader>where
P: AsRef<Path>,
pub fn new<P>(
ctx: &mut Context,
vertex_path: P,
fragment_path: P
) -> Result<Shader>where
P: AsRef<Path>,
Creates a new shader program from the given files.
sourcepub fn vertex<P>(ctx: &mut Context, path: P) -> Result<Shader>where
P: AsRef<Path>,
pub fn vertex<P>(ctx: &mut Context, path: P) -> Result<Shader>where
P: AsRef<Path>,
Creates a new shader program from the given vertex shader file.
The default fragment shader will be used.
sourcepub fn fragment<P>(ctx: &mut Context, path: P) -> Result<Shader>where
P: AsRef<Path>,
pub fn fragment<P>(ctx: &mut Context, path: P) -> Result<Shader>where
P: AsRef<Path>,
Creates a new shader program from the given fragment shader file.
The default vertex shader will be used.
sourcepub fn from_string(
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str
) -> Result<Shader>
pub fn from_string(
ctx: &mut Context,
vertex_shader: &str,
fragment_shader: &str
) -> Result<Shader>
Creates a new shader program from the given strings.
sourcepub fn set_uniform<V>(&mut self, ctx: &mut Context, name: &str, value: V)where
V: UniformValue,
pub fn set_uniform<V>(&mut self, ctx: &mut Context, name: &str, value: V)where
V: UniformValue,
Sets the value of the specifed uniform parameter.
Trait Implementations§
impl StructuralPartialEq for Shader
Auto Trait Implementations§
impl RefUnwindSafe for Shader
impl !Send for Shader
impl !Sync for Shader
impl Unpin for Shader
impl UnwindSafe for Shader
Blanket Implementations§
§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> SetParameter for T
impl<T> SetParameter for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).§unsafe fn to_subset_unchecked(&self) -> SS
unsafe fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.