Skip to main content

Atlas

Struct Atlas 

Source
pub struct Atlas { /* private fields */ }
Expand description

A square atlas of glyph coverage, and where each glyph landed.

Holds the texels itself rather than a device texture, so that packing can be exercised and reasoned about without a GPU. Whoever owns the device uploads Atlas::texels when Atlas::is_dirty says something changed.

Implementations§

Source§

impl Atlas

Source

pub fn new(size: u32) -> Atlas

An empty atlas of size by size texels.

Source

pub fn with_limit(size: u32, limit: u32) -> Atlas

An atlas that may grow up to limit texels on a side.

A limit below the starting size means it never grows, which is a reasonable thing to ask for and not an error.

Source

pub fn size(&self) -> u32

Source

pub fn texels(&self) -> &[u8] ⓘ

One byte of coverage per texel, row-major from the top.

Source

pub fn is_dirty(&self) -> bool

Whether anything has been added since Atlas::mark_clean.

The upload is the caller’s to make, because only they know which device the texture lives on and when in the frame it is safe to write.

Source

pub fn mark_clean(&mut self)

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn get(&self, key: GlyphKey) -> Option<AtlasRect>

Where a glyph sits, if it is present.

Source

pub fn begin_frame(&mut self)

Begin a new frame, after which glyphs not inserted again are evictable.

Nothing happens here but a counter moving. A caller that never calls it keeps every glyph forever, which is correct rather than a leak: without frame boundaries nothing is stale, and an atlas that filled would be genuinely out of room.

Source

pub fn compactions(&self) -> u64

How many times room has been made by repacking.

Worth reporting because it is the number that says the atlas is too small for the text going through it: a compaction or two as a working set settles is ordinary, and one per frame means every frame is repacking everything.

Source

pub fn growths(&self) -> u64

How many times the atlas has doubled.

Every growth reallocates and repacks everything, so a count that keeps climbing says the atlas started far too small. It settles once the working set fits.

Source

pub fn limit(&self) -> u32

The largest this may grow to.

Source

pub fn insert( &mut self, key: GlyphKey, coverage: &Coverage, ) -> Result<AtlasRect, AtlasError>

Add a glyph, or return where it already is.

Idempotent, so a caller can insert every glyph of every run each frame and pay only for the ones that are new. That is the usage this is for: deciding what is already present is exactly what an atlas is.

Trait Implementations§

Source§

impl Debug for Atlas

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Atlas

§

impl RefUnwindSafe for Atlas

§

impl Send for Atlas

§

impl Sync for Atlas

§

impl Unpin for Atlas

§

impl UnsafeUnpin for Atlas

§

impl UnwindSafe for Atlas

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