Struct TextAtlas

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

Multi-page GPU glyph atlas with LRU eviction.

The atlas allocates one 1024-square RGBA8 page eagerly and grows to MAX_ATLAS_PAGES. Pinned pages cannot be reset during a frame. Unpinned eviction clears an entire least-recently-used page, not an individual glyph.

§Examples

use ailloli_ui_render_wgpu::text::TextAtlas;
let _: usize = std::mem::size_of::<TextAtlas>();

Implementations§

Source§

impl TextAtlas

Source

pub fn new( device: &Device, queue: &Queue, tex_bind_group_layout: &BindGroupLayout, ) -> Self

Creates an atlas, sampler, and the mandatory first 1024-square page.

The supplied bind-group layout must contain a filterable 2D texture at binding 0 and a filtering sampler at binding 1.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn create(device: &wgpu::Device, queue: &wgpu::Queue,
    layout: &wgpu::BindGroupLayout) -> TextAtlas {
    TextAtlas::new(device, queue, layout)
}
Source

pub fn bind_group(&self) -> &BindGroup

Page 0 bind group (always allocated; legacy renderer path).

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn binding(atlas: &TextAtlas) -> &wgpu::BindGroup { atlas.bind_group() }
Source

pub fn page_bind_group(&self, page_idx: u8) -> &BindGroup

Bind group for the given atlas page index.

§Panics

Panics if page_idx >= page_count().

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn first(atlas: &TextAtlas) -> &wgpu::BindGroup { atlas.page_bind_group(0) }
Source

pub fn page_count(&self) -> usize

Returns the number of allocated pages, always in 1..=MAX_ATLAS_PAGES.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn pages(atlas: &TextAtlas) -> usize { atlas.page_count() }
Source

pub fn begin_frame(&mut self) -> TextAtlasFrame<'_>

Starts a frame and returns a guard that unpins pages on drop.

Calling this discards the previous frame’s counters and pins, so guards must not conceptually overlap.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn frame(atlas: &mut TextAtlas) { let _guard = atlas.begin_frame(); }
Source

pub fn start_frame(&mut self)

Resets per-frame counters and clears all page pins.

Prefer Self::begin_frame when scoped access is practical.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn start(atlas: &mut TextAtlas) { atlas.start_frame(); }
Source

pub fn finish_frame(&mut self)

Clears page pins without changing counters, glyphs, or allocations.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn finish(atlas: &mut TextAtlas) { atlas.finish_frame(); }
Source

pub fn stats(&self) -> TextAtlasStats

Returns current frame counters with a live page-count snapshot.

§Examples
use ailloli_ui_render_wgpu::text::{TextAtlas, TextAtlasStats};
fn stats(atlas: &TextAtlas) -> TextAtlasStats { atlas.stats() }
Source

pub fn get_or_rasterize( &mut self, device: &Device, queue: &Queue, bind_group_layout: &BindGroupLayout, key: GlyphKey, font_data: &[u8], ) -> Option<(u8, Glyph)>

Looks up or rasterizes a glyph without protecting its page from eviction.

Returns (page_index, metrics) or None on raster/allocation failure. Use Self::get_or_rasterize_pinned during frame preparation.

§Examples
use ailloli_ui_render_wgpu::text::{GlyphKey, TextAtlas};
fn lookup(atlas: &mut TextAtlas, device: &wgpu::Device, queue: &wgpu::Queue,
    layout: &wgpu::BindGroupLayout, key: GlyphKey, font: &[u8]) {
    let _ = atlas.get_or_rasterize(device, queue, layout, key, font);
}
Source

pub fn get_or_rasterize_pinned( &mut self, device: &Device, queue: &Queue, bind_group_layout: &BindGroupLayout, key: GlyphKey, font_data: &[u8], ) -> Option<(u8, Glyph)>

Looks up or rasterizes a glyph and pins its page for the current frame.

If every page is pinned and full, returns None and increments both evictions_blocked and glyphs_skipped.

§Examples
use ailloli_ui_render_wgpu::text::{GlyphKey, TextAtlas};
fn lookup(atlas: &mut TextAtlas, device: &wgpu::Device, queue: &wgpu::Queue,
    layout: &wgpu::BindGroupLayout, key: GlyphKey, font: &[u8]) {
    let _ = atlas.get_or_rasterize_pinned(device, queue, layout, key, font);
}
Source

pub fn record_missing_face(&mut self)

Saturating-increments the missing-face/skip counter.

§Examples
use ailloli_ui_render_wgpu::text::TextAtlas;
fn missing(atlas: &mut TextAtlas) { atlas.record_missing_face(); }

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
§

impl<T> Downcast<T> for T

§

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> Upcast<T> for T

§

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

§

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

§

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

§

impl<T> WasmNotSend for T
where T: Send,

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

impl<T> WasmNotSync for T
where T: Sync,