pub struct FragmentShader { /* private fields */ }Expand description
A Shader generated from a FragmentProgram.
Instances of this class can be obtained from the FragmentProgram::fragment_shader method.
The float uniforms list is initialized to the size expected by the shader and is zero-filled.
Uniforms of float type can then be set by name with
get_uniform_float, get_uniform_vec2,
get_uniform_vec3, get_uniform_vec4,
and related methods. Sampler uniforms are set by calling
set_image_sampler.
A FragmentShader can be re-used, and this is an efficient way to avoid allocating and
re-initializing the uniform buffer and samplers. However, if two FragmentShader objects
with different float uniforms or samplers are required to exist simultaneously, they must be
obtained from two different calls to FragmentProgram::fragment_shader.
A paint draws with the shader as it is when the paint is made, Shader::from(&shader).
Implementations§
Source§impl FragmentShader
impl FragmentShader
Sourcepub fn set_float(&mut self, index: usize, value: f64)
👎Deprecated: Use get_uniform_float, get_uniform_vec2, get_uniform_vec3, get_uniform_vec4, or a related method to set uniforms by name instead. This feature was deprecated after v3.51.0-0.1.pre.
pub fn set_float(&mut self, index: usize, value: f64)
Use get_uniform_float, get_uniform_vec2, get_uniform_vec3, get_uniform_vec4, or a related method to set uniforms by name instead. This feature was deprecated after v3.51.0-0.1.pre.
Sets the float uniform at index to value.
Deprecated: Prefer setting uniforms by name with
get_uniform_float,
get_uniform_vec2,
get_uniform_vec3,
get_uniform_vec4,
get_uniform_mat2,
get_uniform_mat3,
get_uniform_mat4, or their array counterparts such as
get_uniform_float_array. Those methods don’t require
manually computing the index of each uniform and are robust to changes in the order or
layout of uniforms in the fragment program.
The index for each uniform is determined by the order of the uniforms as defined in the
fragment program’s uniform struct, ignoring any images, each counted by its floats packed
tightly. For data types that are composed of multiple floats such as a vec4, more than
one call to set_float is required.
For example, given the following uniforms in a fragment program:
struct Uniforms { uScale: f32, uMagnitude: vec2<f32>, uColor: vec4<f32> }uScale is at index 0, uMagnitude occupies indices 1 and 2, and uColor occupies
indices 3 through 6, wherever WGSL places them in the struct’s bytes.
Any float uniforms that are left uninitialized will default to 0.
§Panics
Where index is past the program’s floats.
Sourcepub fn get_uniform_float(
&self,
name: &str,
index: Option<usize>,
) -> Result<UniformFloatSlot, UniformError>
pub fn get_uniform_float( &self, name: &str, index: Option<usize>, ) -> Result<UniformFloatSlot, UniformError>
Access the float binding for uniform named name with optional offset index, 0 when
None. Example index values: 1 for foo.y, 2 for foo.b.
Sourcepub fn get_uniform_vec2(
&self,
name: &str,
) -> Result<UniformVec2Slot, UniformError>
pub fn get_uniform_vec2( &self, name: &str, ) -> Result<UniformVec2Slot, UniformError>
Access the float binding for a vec2 uniform named name.
Sourcepub fn get_uniform_vec3(
&self,
name: &str,
) -> Result<UniformVec3Slot, UniformError>
pub fn get_uniform_vec3( &self, name: &str, ) -> Result<UniformVec3Slot, UniformError>
Access the float binding for a vec3 uniform named name.
Sourcepub fn get_uniform_vec4(
&self,
name: &str,
) -> Result<UniformVec4Slot, UniformError>
pub fn get_uniform_vec4( &self, name: &str, ) -> Result<UniformVec4Slot, UniformError>
Access the float binding for a vec4 uniform named name.
Sourcepub fn get_uniform_mat2(
&self,
name: &str,
) -> Result<UniformMat2Slot, UniformError>
pub fn get_uniform_mat2( &self, name: &str, ) -> Result<UniformMat2Slot, UniformError>
Access the float binding for a mat2 uniform named name.
Sourcepub fn get_uniform_mat3(
&self,
name: &str,
) -> Result<UniformMat3Slot, UniformError>
pub fn get_uniform_mat3( &self, name: &str, ) -> Result<UniformMat3Slot, UniformError>
Access the float binding for a mat3 uniform named name.
Sourcepub fn get_uniform_mat4(
&self,
name: &str,
) -> Result<UniformMat4Slot, UniformError>
pub fn get_uniform_mat4( &self, name: &str, ) -> Result<UniformMat4Slot, UniformError>
Access the float binding for a mat4 uniform named name.
Sourcepub fn get_uniform_float_array(
&self,
name: &str,
) -> Result<UniformArray<UniformFloatSlot>, UniformError>
pub fn get_uniform_float_array( &self, name: &str, ) -> Result<UniformArray<UniformFloatSlot>, UniformError>
Access the binding for a float array uniform named name.
WGSL keeps no float array in a uniform struct, so a GLSL float uValues[8] is an
array<vec4<f32>, 2>, whose eight floats this reads as eight elements.
Sourcepub fn get_uniform_vec2_array(
&self,
name: &str,
) -> Result<UniformArray<UniformVec2Slot>, UniformError>
pub fn get_uniform_vec2_array( &self, name: &str, ) -> Result<UniformArray<UniformVec2Slot>, UniformError>
Access the binding for a vec2 array uniform named name.
Sourcepub fn get_uniform_vec3_array(
&self,
name: &str,
) -> Result<UniformArray<UniformVec3Slot>, UniformError>
pub fn get_uniform_vec3_array( &self, name: &str, ) -> Result<UniformArray<UniformVec3Slot>, UniformError>
Access the binding for a vec3 array uniform named name.
Sourcepub fn get_uniform_vec4_array(
&self,
name: &str,
) -> Result<UniformArray<UniformVec4Slot>, UniformError>
pub fn get_uniform_vec4_array( &self, name: &str, ) -> Result<UniformArray<UniformVec4Slot>, UniformError>
Access the binding for a vec4 array uniform named name.
Sourcepub fn get_uniform_mat2_array(
&self,
name: &str,
) -> Result<UniformArray<UniformMat2Slot>, UniformError>
pub fn get_uniform_mat2_array( &self, name: &str, ) -> Result<UniformArray<UniformMat2Slot>, UniformError>
Access the binding for a mat2 array uniform named name.
Sourcepub fn get_uniform_mat3_array(
&self,
name: &str,
) -> Result<UniformArray<UniformMat3Slot>, UniformError>
pub fn get_uniform_mat3_array( &self, name: &str, ) -> Result<UniformArray<UniformMat3Slot>, UniformError>
Access the binding for a mat3 array uniform named name.
Sourcepub fn get_uniform_mat4_array(
&self,
name: &str,
) -> Result<UniformArray<UniformMat4Slot>, UniformError>
pub fn get_uniform_mat4_array( &self, name: &str, ) -> Result<UniformArray<UniformMat4Slot>, UniformError>
Access the binding for a mat4 array uniform named name.
Sourcepub fn get_image_sampler(
&self,
name: &str,
) -> Result<ImageSamplerSlot, UniformError>
pub fn get_image_sampler( &self, name: &str, ) -> Result<ImageSamplerSlot, UniformError>
Access the ImageSamplerSlot binding associated with the sampler named name: the
texture’s name in the WGSL, as its pair’s sampler is named after it.
The index provided to set_image_sampler is the index of the
image defined in the fragment program, excluding all non-image uniforms.
Sourcepub fn set_image_sampler(
&mut self,
index: usize,
image: &Image,
filter_quality: FilterQuality,
)
pub fn set_image_sampler( &mut self, index: usize, image: &Image, filter_quality: FilterQuality, )
Sets the sampler uniform at index to image.
The index provided to set_image_sampler is the index of the
image defined in the fragment program, excluding all non-image uniforms.
The filter_quality argument sets the quality level used to sample the image; Flutter’s
default is FilterQuality::None.
All the sampler uniforms that a shader expects must be provided before a paint is made from it.
§Panics
Where index is past the program’s images: “Sampler index out of bounds”.
Trait Implementations§
Source§impl Debug for FragmentShader
impl Debug for FragmentShader
Source§impl From<&FragmentShader> for Shader
The shader as a paint draws it, its floats and images copied now:
ReusableFragmentShader::shader, as Paint.shader takes a FragmentShader.
impl From<&FragmentShader> for Shader
The shader as a paint draws it, its floats and images copied now:
ReusableFragmentShader::shader, as Paint.shader takes a FragmentShader.
§Panics
Where an image is not set, as Dart’s Paint.shader setter throws in a debug build.