pub struct Program { /* private fields */ }Expand description
A shader program consisting of a programmable vertex shader followed by a programmable fragment shader. Functionality includes transferring per vertex data to the vertex shader (see the use_attribute functionality) and transferring uniform data to both shader stages (see the use_uniform and use_texture functionality) and execute the shader program (see the draw functionality).
Implementations
sourceimpl Program
impl Program
sourcepub fn from_source(
context: &Context,
vertex_shader_source: &str,
fragment_shader_source: &str
) -> ThreeDResult<Program>
pub fn from_source(
context: &Context,
vertex_shader_source: &str,
fragment_shader_source: &str
) -> ThreeDResult<Program>
Creates a new shader program from the given vertex and fragment glsl shader source.
sourcepub fn use_uniform<T: UniformDataType>(
&self,
name: &str,
data: T
) -> ThreeDResult<()>
pub fn use_uniform<T: UniformDataType>(
&self,
name: &str,
data: T
) -> ThreeDResult<()>
Send the given uniform data to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform int if the data is an integer, uniform vec2 if it is of type Vec2 etc.
The uniform variable is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_if_required<T: UniformDataType>(
&self,
name: &str,
data: T
) -> ThreeDResult<()>
pub fn use_uniform_if_required<T: UniformDataType>(
&self,
name: &str,
data: T
) -> ThreeDResult<()>
Calls Self::use_uniform if Self::requires_uniform returns true.
sourcepub fn use_uniform_array<T: UniformDataType>(
&self,
name: &str,
data: &[T]
) -> ThreeDResult<()>
pub fn use_uniform_array<T: UniformDataType>(
&self,
name: &str,
data: &[T]
) -> ThreeDResult<()>
Send the given array of uniform data to this shader program and associate it with the given named variable.
The glsl shader variable must be of same type and length as the data, so if the data is an array of three Vec2, the variable must be uniform vec2[3].
The uniform variable is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_int(&self, name: &str, data: &i32) -> ThreeDResult<()>
pub fn use_uniform_int(&self, name: &str, data: &i32) -> ThreeDResult<()>
Send the given integer value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform int, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_float(&self, name: &str, data: &f32) -> ThreeDResult<()>
pub fn use_uniform_float(&self, name: &str, data: &f32) -> ThreeDResult<()>
Send the given float value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform float, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_vec2(&self, name: &str, data: &Vec2) -> ThreeDResult<()>
pub fn use_uniform_vec2(&self, name: &str, data: &Vec2) -> ThreeDResult<()>
Send the given Vec2 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform vec2, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_vec3(&self, name: &str, data: &Vec3) -> ThreeDResult<()>
pub fn use_uniform_vec3(&self, name: &str, data: &Vec3) -> ThreeDResult<()>
Send the given Vec3 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform vec3, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_vec4(&self, name: &str, data: &Vec4) -> ThreeDResult<()>
pub fn use_uniform_vec4(&self, name: &str, data: &Vec4) -> ThreeDResult<()>
Send the given Vec4 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform vec4, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_quat(&self, name: &str, data: &Quat) -> ThreeDResult<()>
pub fn use_uniform_quat(&self, name: &str, data: &Quat) -> ThreeDResult<()>
Send the given Quat value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform vec4, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_mat2(&self, name: &str, data: &Mat2) -> ThreeDResult<()>
pub fn use_uniform_mat2(&self, name: &str, data: &Mat2) -> ThreeDResult<()>
Send the given Mat2 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform mat2, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_mat3(&self, name: &str, data: &Mat3) -> ThreeDResult<()>
pub fn use_uniform_mat3(&self, name: &str, data: &Mat3) -> ThreeDResult<()>
Send the given Mat3 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform mat3, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_mat4(&self, name: &str, data: &Mat4) -> ThreeDResult<()>
pub fn use_uniform_mat4(&self, name: &str, data: &Mat4) -> ThreeDResult<()>
Send the given Mat4 value to this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform mat4, meaning it is uniformly available across all processing of vertices and fragments.
Errors
Will return an error if the uniform is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_texture(&self, name: &str, texture: &Texture2D) -> ThreeDResult<()>
pub fn use_texture(&self, name: &str, texture: &Texture2D) -> ThreeDResult<()>
Use the given Texture2D in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform sampler2D and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_depth_texture(
&self,
name: &str,
texture: &DepthTargetTexture2D
) -> ThreeDResult<()>
pub fn use_depth_texture(
&self,
name: &str,
texture: &DepthTargetTexture2D
) -> ThreeDResult<()>
Use the given DepthTargetTexture2D in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform sampler2D and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_texture_array(
&self,
name: &str,
texture: &Texture2DArray
) -> ThreeDResult<()>
pub fn use_texture_array(
&self,
name: &str,
texture: &Texture2DArray
) -> ThreeDResult<()>
Use the given texture array in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform sampler2DArray and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_depth_texture_array(
&self,
name: &str,
texture: &DepthTargetTexture2DArray
) -> ThreeDResult<()>
pub fn use_depth_texture_array(
&self,
name: &str,
texture: &DepthTargetTexture2DArray
) -> ThreeDResult<()>
Use the given texture array in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform sampler2DArray and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_texture_cube(
&self,
name: &str,
texture: &TextureCubeMap
) -> ThreeDResult<()>
pub fn use_texture_cube(
&self,
name: &str,
texture: &TextureCubeMap
) -> ThreeDResult<()>
Use the given texture cube map in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform samplerCube and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_depth_texture_cube(
&self,
name: &str,
texture: &DepthTargetTextureCubeMap
) -> ThreeDResult<()>
pub fn use_depth_texture_cube(
&self,
name: &str,
texture: &DepthTargetTextureCubeMap
) -> ThreeDResult<()>
Use the given texture cube map in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform samplerCube and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_texture_3d(
&self,
name: &str,
texture: &Texture3D
) -> ThreeDResult<()>
pub fn use_texture_3d(
&self,
name: &str,
texture: &Texture3D
) -> ThreeDResult<()>
Use the given 3D texture in this shader program and associate it with the given named variable.
The glsl shader variable must be of type uniform sampler3D and can only be accessed in the fragment shader.
Errors
Will return an error if the texture is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_uniform_block(
&self,
name: &str,
buffer: &UniformBuffer
) -> ThreeDResult<()>
pub fn use_uniform_block(
&self,
name: &str,
buffer: &UniformBuffer
) -> ThreeDResult<()>
Use the given UniformBuffer in this shader program and associate it with the given named variable.
sourcepub fn use_vertex_attribute(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
pub fn use_vertex_attribute(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
Uses the given VertexBuffer data in this shader program and associates it with the given named variable. Each value in the buffer is used when rendering one vertex using the Program::draw_arrays or Program::draw_elements methods. Therefore the buffer must contain the same number of values as the number of vertices specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_instance_attribute(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
pub fn use_instance_attribute(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
Uses the given InstanceBuffer data in this shader program and associates it with the given named variable. Each value in the buffer is used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain the same number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_vertex_attribute instead
pub fn use_attribute(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
use use_vertex_attribute instead
Uses the given VertexBuffer in this shader program and associates it with the given named variable. Each value in the buffer is used when rendering one vertex using the Program::draw_arrays or Program::draw_elements methods. Therefore the buffer must contain the same number of values as the number of vertices specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_instance_attribute instead
pub fn use_attribute_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
use use_instance_attribute instead
Uses the given buffer data in this shader program and associates it with the given named variable. Each value in the buffer is used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain the same number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec2(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_vertex_attribute instead and pass in a slice of Vec2 when constructing the VertexBuffer
pub fn use_attribute_vec2(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
use use_vertex_attribute instead and pass in a slice of Vec2 when constructing the VertexBuffer
Uses the given VertexBuffer in this shader program and associates it with the given named variable. Each contiguous 2 values in the buffer are used when rendering one vertex using the Program::draw_arrays or Program::draw_elements methods. Therefore the buffer must contain 2 times the number of values as the number of vertices specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec2_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_instance_attribute instead and pass in a slice of Vec2 when constructing the InstanceBuffer
pub fn use_attribute_vec2_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
use use_instance_attribute instead and pass in a slice of Vec2 when constructing the InstanceBuffer
Uses the given buffer data in this shader program and associates it with the given named variable. Each contiguous 2 values in the buffer are used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain 2 times the number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec3(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_vertex_attribute instead and pass in a slice of Vec3 when constructing the VertexBuffer
pub fn use_attribute_vec3(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
use use_vertex_attribute instead and pass in a slice of Vec3 when constructing the VertexBuffer
Uses the given VertexBuffer in this shader program and associates it with the given named variable. Each contiguous 3 values in the buffer are used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain 3 times the number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec3_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_instance_attribute instead and pass in a slice of Vec3 when constructing the InstanceBuffer
pub fn use_attribute_vec3_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
use use_instance_attribute instead and pass in a slice of Vec3 when constructing the InstanceBuffer
Uses the given buffer data in this shader program and associates it with the given named variable. Each contiguous 3 values in the buffer are used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain 3 times the number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec4(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_vertex_attribute instead and pass in a slice of Vec4 when constructing the VertexBuffer
pub fn use_attribute_vec4(
&self,
name: &str,
buffer: &VertexBuffer
) -> ThreeDResult<()>
use use_vertex_attribute instead and pass in a slice of Vec4 when constructing the VertexBuffer
Uses the given VertexBuffer in this shader program and associates it with the given named variable. Each contiguous 4 values in the buffer are used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain 4 times the number of values as the number of instances specified in those draw calls.
Errors
Will return an error if the attribute is not defined in the shader code or not used. In the latter case the variable is removed by the shader compiler.
sourcepub fn use_attribute_vec4_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
👎 Deprecated: use use_instance_attribute instead and pass in a slice of Vec4 when constructing the InstanceBuffer
pub fn use_attribute_vec4_instanced(
&self,
name: &str,
buffer: &InstanceBuffer
) -> ThreeDResult<()>
use use_instance_attribute instead and pass in a slice of Vec4 when constructing the InstanceBuffer
Uses the given buffer data in this shader program and associates it with the given named variable. Each contiguous 4 values in the buffer are used when rendering one instance using the Program::draw_arrays_instanced or Program::draw_elements_instanced methods. Therefore the buffer must contain 4 times the number of values as the number of instances specified in those draw calls.
sourcepub fn draw_arrays(
&self,
render_states: RenderStates,
viewport: Viewport,
count: u32
) -> ThreeDResult<()>
pub fn draw_arrays(
&self,
render_states: RenderStates,
viewport: Viewport,
count: u32
) -> ThreeDResult<()>
Draws count number of triangles with the given render states and viewport using this shader program.
Requires that all attributes and uniforms have been defined using the use_attribute and use_uniform methods.
Assumes that the data for the three vertices in a triangle is defined contiguous in each vertex buffer.
If you want to use an ElementBuffer, see Program::draw_elements.
sourcepub fn draw_arrays_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
count: u32,
instance_count: u32
) -> ThreeDResult<()>
pub fn draw_arrays_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
count: u32,
instance_count: u32
) -> ThreeDResult<()>
Same as Program::draw_arrays except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_attribute_instanced, Program::use_attribute_vec2_instanced, Program::use_attribute_vec3_instanced and Program::use_attribute_vec4_instanced methods to send unique data for each instance to the shader.
sourcepub fn draw_elements(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer
) -> ThreeDResult<()>
pub fn draw_elements(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer
) -> ThreeDResult<()>
Draws the triangles defined by the given ElementBuffer with the given render states and viewport using this shader program. Requires that all attributes and uniforms have been defined using the use_attribute and use_uniform methods. If you do not want to use an ElementBuffer, see Program::draw_arrays. If you only want to draw a subset of the triangles in the given ElementBuffer, see Program::draw_subset_of_elements.
sourcepub fn draw_subset_of_elements(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
first: u32,
count: u32
) -> ThreeDResult<()>
pub fn draw_subset_of_elements(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
first: u32,
count: u32
) -> ThreeDResult<()>
Draws a subset of the triangles defined by the given ElementBuffer with the given render states and viewport using this shader program. Requires that all attributes and uniforms have been defined using the use_attribute and use_uniform methods. If you do not want to use an ElementBuffer, see Program::draw_arrays.
sourcepub fn draw_elements_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
instance_count: u32
) -> ThreeDResult<()>
pub fn draw_elements_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
instance_count: u32
) -> ThreeDResult<()>
Same as Program::draw_elements except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_attribute_instanced, Program::use_attribute_vec2_instanced, Program::use_attribute_vec3_instanced and Program::use_attribute_vec4_instanced methods to send unique data for each instance to the shader.
sourcepub fn draw_subset_of_elements_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
first: u32,
count: u32,
instance_count: u32
) -> ThreeDResult<()>
pub fn draw_subset_of_elements_instanced(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer,
first: u32,
count: u32,
instance_count: u32
) -> ThreeDResult<()>
Same as Program::draw_subset_of_elements except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_attribute_instanced, Program::use_attribute_vec2_instanced, Program::use_attribute_vec3_instanced and Program::use_attribute_vec4_instanced methods to send unique data for each instance to the shader.
sourcepub fn requires_uniform(&self, name: &str) -> bool
pub fn requires_uniform(&self, name: &str) -> bool
Returns true if this program uses the uniform with the given name.
sourcepub fn requires_attribute(&self, name: &str) -> bool
pub fn requires_attribute(&self, name: &str) -> bool
Returns true if this program uses the attribute with the given name.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Program
impl !Send for Program
impl !Sync for Program
impl Unpin for Program
impl !UnwindSafe for Program
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more