Skip to main content

Sampling

Enum Sampling 

Source
pub enum Sampling {
    Linear,
    Nearest,
    Cubic,
    Mipmap,
}
Expand description

How a texture is read between its texels.

Not two samplers. The same argument that keeps tile modes in the shader keeps this there: a sampler baked with a filter would mean one sampler per combination and a descriptor set per draw that used a different one. A linear sampler read exactly at a texel’s center returns that texel and nothing else, so nearest sampling is the coordinate snapped to the nearest center before the read, which is one multiply-floor-divide and no bindings at all.

dart:ui offers four qualities. These are its first two; the other two are mipmapped and bicubic, and neither exists here to select.

Variants§

§

Linear

Blend the texels around the coordinate. The right default: an image drawn at any size but its own is otherwise a mess of hard edges.

§

Nearest

The one texel the coordinate falls in.

What pixel art needs, and what a sprite drawn at exactly its own size wants in order to be certain no neighbor bled in.

§

Cubic

A bicubic reconstruction over the sixteen texels around the coordinate.

What dart:ui calls FilterQuality.high. Sharper than linear under magnification, because the curve through four texels along an axis has a slope where a straight line between two has a corner, and it costs sixteen reads per fragment to say so.

The particular curve is Mitchell-Netravali with B and C both a third, which is what Skia’s high quality has always meant and so what a caller porting from Flutter is expecting. It rings slightly – the weights go a little negative between one and two texels out – and that overshoot is the sharpening, not an error in it.

§

Mipmap

A linear read of the mip level that matches how far the image is being minified, blended with the level either side of it.

What dart:ui calls FilterQuality.medium, and the one quality that answers minification rather than magnification. Drawn at half its size an image read linearly skips every other texel and aliases; read from the level built for that size, every texel of the original contributes.

It needs a texture that was allocated with a chain, since a level that was never made cannot be read. On a texture without one every read lands on the image itself and this is linear – which is a picture that is merely worse rather than wrong, and is what a sampler does with a level it does not have.

Trait Implementations§

Source§

impl Clone for Sampling

Source§

fn clone(&self) -> Self

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 Copy for Sampling

Source§

impl Debug for Sampling

Source§

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

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

impl Default for Sampling

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for Sampling

Source§

impl PartialEq for Sampling

Source§

fn eq(&self, other: &Self) -> 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 Sampling

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