Skip to main content

Shader

Enum Shader 

Source
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

§start: Vec2
§end: Vec2
§tile: TileMode

What 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

§center: Vec2
§radius: f32
§tile: TileMode

What 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

§slot: u32
§rect: Rect
§alpha: f32

Scales the sampled color, for drawing an image translucently.

§source: Rect

Which 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.

§tint: Color

Multiplies the sampled color. White changes nothing.

§sampling: Sampling

How 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

§center: Vec2
§start_angle: f32
§end_angle: f32
§tile: TileMode

What fills the directions the arc does not cover.

A sweep of a full turn covers every direction and this changes nothing; it is a partial sweep that has an outside.

§

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

§program: u32
§uniforms: Vec<f32>
§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.

Fields

§start_center: Vec2
§start_radius: f32
§end_center: Vec2
§end_radius: f32
§tile: TileMode

What fills the parameter outside the two circles. See Shader::LinearGradient.

Implementations§

Source§

impl Shader

Source

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.

Source

pub fn is_visible(&self) -> bool

Whether this would draw anything at all.

Trait Implementations§

Source§

impl Clone for Shader

Source§

fn clone(&self) -> Shader

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Shader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Shader

Source§

fn eq(&self, other: &Shader) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Shader

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>