pub enum Shader {
Solid(Color),
LinearGradient {
start: Vec2,
end: Vec2,
stops: Vec<GradientStop>,
tile: TileMode,
},
RadialGradient {
center: Vec2,
radius: f32,
stops: Vec<GradientStop>,
tile: TileMode,
},
Image {
slot: u32,
rect: Rect,
alpha: f32,
tile: TileMode,
source: Rect,
tint: Color,
sampling: Sampling,
},
SweepGradient {
center: Vec2,
start_angle: f32,
end_angle: f32,
stops: Vec<GradientStop>,
tile: TileMode,
},
RuntimeEffect {
program: u32,
uniforms: Vec<f32>,
images: Vec<u32>,
},
ConicalGradient {
start_center: Vec2,
start_radius: f32,
end_center: Vec2,
end_radius: f32,
stops: Vec<GradientStop>,
tile: TileMode,
},
}Expand description
What fills a shape.
Variants§
Solid(Color)
LinearGradient
A gradient along the line between two points in user space.
The endpoints travel through the canvas transform with the geometry, so a gradient rotates and scales with the shape it fills rather than staying pinned to the screen.
Fields
stops: Vec<GradientStop>tile: TileModeWhat fills the shape beyond the two endpoints.
A gradient is defined by two points and a shape is rarely exactly
that long, so this is not an edge case: clamping holds the end
colors, repeating tiles the ramp, and decal leaves the outside
empty. Set with Paint::with_tile_mode, the same call an image
uses.
RadialGradient
A gradient outward from a center in user space, reaching its last
stop at radius.
Fields
stops: Vec<GradientStop>tile: TileModeWhat fills the shape beyond radius. See Shader::LinearGradient.
Image
A texture, mapped onto a rectangle in user space.
The rectangle travels through the canvas transform with the geometry, so an image rotates and scales with the shape it fills. It is the region the image covers, not the region drawn: filling a circle with this paint draws a circular piece of the image.
slot indexes the table supplied when the recording is drawn. The
canvas names a slot rather than holding a texture because it records
without touching a device, and a backend texture is not something it can
name. Assigning slots is the caller’s business for now; a registry that
did it for them is a separate piece of design.
Fields
source: RectWhich part of the image to draw, from zero to one in each axis.
The whole image by default. Set it with Paint::with_source, or
with Paint::with_source_pixels if you would rather state it in
texels and hand over the size you uploaded.
sampling: SamplingHow to read between texels. See Paint::with_sampling.
SweepGradient
A gradient around a center in user space, running between two angles in radians, measured counter-clockwise from the positive X axis.
Fields
stops: Vec<GradientStop>RuntimeEffect
A caller’s own fragment program.
The one shader here this renderer did not write. program names one
registered with a context, and uniforms are the floats it reads –
laid out as the program’s own declaration expects, which is a contract
between the caller’s shader and the caller’s code and not something
this renderer can check.
At most RUNTIME_FLOATS of them; the rest are dropped rather than
overflowing into a block that has no room for them.
Fields
images: Vec<u32>A texture slot the program may sample, if it declares one.
The same table an image paint names, so a caller supplies them in the same array beside the recording, in the order the program declares its bindings.
A binding the program declares and this leaves empty reads a
one-pixel opaque white texture – what a solid fill binds, and what
keeps a pipeline’s declared binding satisfied. Beyond
MAX_EFFECT_TEXTURES a caller is asking for a second descriptor
set layout, which would be one layout per program; the ceiling is
what buys a single shared one.
ConicalGradient
A gradient between two circles in user space, reaching its first stop on the first circle and its last on the second.
This is the general form: a radial gradient is the case where the first
circle is a point at the second’s center, and the two-point form is what
dart:ui reaches by giving Gradient.radial a focal point. It is kept
separate from Shader::RadialGradient rather than replacing it,
because the radial case folds its radius into a matrix and solves no
quadratic at all, and paying for the general solve on every ordinary
gradient would be a poor trade on the hardware this targets.
Where no circle in the family passes through a point, nothing is drawn there – which is most of the plane when one circle is far outside the other. That is a property of the two circles rather than of the tile mode, which acts only where the parameter exists.
Implementations§
Source§impl Shader
impl Shader
Sourcepub fn stop_count(&self) -> usize
pub fn stop_count(&self) -> usize
How many color stops this paint carries, or zero where it carries none.
Public because the threshold is: at or below MAX_STOPS a gradient
costs nothing beyond its material, and above it the recorder bakes a
small texture. Neither is visible in the result, so this exists for a
caller who cares about the cost rather than the picture.
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Whether this would draw anything at all.