[−][src]Struct tetra::graphics::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.
Data Format
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.
Position data should be output as a vec4
to the built-in gl_Position
variable.
Fragment Shaders
Color data should be output as a vec4
to the first output of the shader. This can be the
built-in gl_FragColor
variable, if you so desire.
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
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::FailedToLoadAsset
will be returned if the files could not be loaded.TetraError::InvalidShader
will be returned if the shader could not be compiled.
pub fn from_vertex_file<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
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidShader
will be returned if the shader could not be compiled.
pub fn from_fragment_file<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
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidShader
will be returned if the shader could not be compiled.
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
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::InvalidShader
will be returned if the shader could not be compiled.
pub fn from_vertex_string<P>(ctx: &mut Context, shader: &str) -> Result<Shader>
[src]
Creates a new shader program from the given vertex shader string.
The default fragment shader will be used.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::InvalidShader
will be returned if the shader could not be compiled.
pub fn from_fragment_string<P>(
ctx: &mut Context,
shader: &str
) -> Result<Shader>
[src]
ctx: &mut Context,
shader: &str
) -> Result<Shader>
Creates a new shader program from the given fragment shader string.
The default vertex shader will be used.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::InvalidShader
will be returned if the shader could not be compiled.
pub fn set_uniform<V>(&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]
impl Debug for Shader
[src]
impl PartialEq<Shader> for Shader
[src]
impl StructuralPartialEq for Shader
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
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, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,