Struct three_d::core::Program

source ·
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

source

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.

source

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.

source

pub fn use_uniform_if_required<T: UniformDataType>(&self, name: &str, data: T)

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

pub fn requires_uniform(&self, name: &str) -> bool

Returns true if this program uses the uniform with the given name.

source

pub fn requires_attribute(&self, name: &str) -> bool

Returns true if this program uses the attribute with the given name.

Trait Implementations§

source§

impl Drop for Program

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> AutoreleaseSafe for T
where T: ?Sized,