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§
source§impl Program
impl Program
sourcepub fn from_source(
context: &Context,
vertex_shader_source: &str,
fragment_shader_source: &str
) -> Result<Self, CoreError>
pub fn from_source( context: &Context, vertex_shader_source: &str, fragment_shader_source: &str ) -> Result<Self, CoreError>
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)
pub fn use_uniform<T: UniformDataType>(&self, name: &str, data: T)
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.
§Panic
Will panic if the uniform is not defined or not used in the shader code. 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)
pub fn use_uniform_if_required<T: UniformDataType>(&self, name: &str, data: T)
Calls Self::use_uniform if Self::requires_uniform returns true.
sourcepub fn use_uniform_array<T: UniformDataType>(&self, name: &str, data: &[T])
pub fn use_uniform_array<T: UniformDataType>(&self, name: &str, data: &[T])
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.
§Panic
Will panic 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)
pub fn use_texture(&self, name: &str, texture: &Texture2D)
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.
§Panic
Will panic 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: &DepthTexture2D)
pub fn use_depth_texture(&self, name: &str, texture: &DepthTexture2D)
Use the given DepthTexture2D 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.
§Panic
Will panic 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)
pub fn use_texture_array(&self, name: &str, texture: &Texture2DArray)
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.
§Panic
Will panic 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: &DepthTexture2DArray)
pub fn use_depth_texture_array(&self, name: &str, texture: &DepthTexture2DArray)
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.
§Panic
Will panic 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)
pub fn use_texture_cube(&self, name: &str, texture: &TextureCubeMap)
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.
§Panic
Will panic 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: &DepthTextureCubeMap)
pub fn use_depth_texture_cube(&self, name: &str, texture: &DepthTextureCubeMap)
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.
§Panic
Will panic 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)
pub fn use_texture_3d(&self, name: &str, texture: &Texture3D)
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.
§Panic
Will panic 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_raw_texture(&self, name: &str, target: u32, id: Texture)
pub fn use_raw_texture(&self, name: &str, target: u32, id: Texture)
Use this function if you want to use a texture which was created using low-level context calls and not using the functionality in the texture module. This function is only needed in special cases for example if you have a special source of texture data.
sourcepub fn use_uniform_block(&self, name: &str, buffer: &UniformBuffer)
pub fn use_uniform_block(&self, name: &str, buffer: &UniformBuffer)
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)
pub fn use_vertex_attribute(&self, name: &str, buffer: &VertexBuffer)
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.
§Panic
Will panic 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)
pub fn use_instance_attribute(&self, name: &str, buffer: &InstanceBuffer)
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.
§Panic
Will panic 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 draw_arrays(
&self,
render_states: RenderStates,
viewport: Viewport,
count: u32
)
pub fn draw_arrays( &self, render_states: RenderStates, viewport: Viewport, count: u32 )
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
)
pub fn draw_arrays_instanced( &self, render_states: RenderStates, viewport: Viewport, count: u32, instance_count: u32 )
Same as Program::draw_arrays except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_instance_attribute, method to send unique data for each instance to the shader.
sourcepub fn draw_elements(
&self,
render_states: RenderStates,
viewport: Viewport,
element_buffer: &ElementBuffer
)
pub fn draw_elements( &self, render_states: RenderStates, viewport: Viewport, element_buffer: &ElementBuffer )
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
)
pub fn draw_subset_of_elements( &self, render_states: RenderStates, viewport: Viewport, element_buffer: &ElementBuffer, first: u32, count: u32 )
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
)
pub fn draw_elements_instanced( &self, render_states: RenderStates, viewport: Viewport, element_buffer: &ElementBuffer, instance_count: u32 )
Same as Program::draw_elements except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_instance_attribute method 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
)
pub fn draw_subset_of_elements_instanced( &self, render_states: RenderStates, viewport: Viewport, element_buffer: &ElementBuffer, first: u32, count: u32, instance_count: u32 )
Same as Program::draw_subset_of_elements except it renders ‘instance_count’ instances of the same set of triangles. Use the Program::use_instance_attribute method 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.