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
impl TextAtlas
Sourcepub fn new(
device: &Device,
queue: &Queue,
tex_bind_group_layout: &BindGroupLayout,
) -> Self
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)
}Sourcepub fn bind_group(&self) -> &BindGroup
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() }Sourcepub fn page_bind_group(&self, page_idx: u8) -> &BindGroup
pub fn page_bind_group(&self, page_idx: u8) -> &BindGroup
Sourcepub fn page_count(&self) -> usize
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() }Sourcepub fn begin_frame(&mut self) -> TextAtlasFrame<'_>
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(); }Sourcepub fn start_frame(&mut self)
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(); }Sourcepub fn finish_frame(&mut self)
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(); }Sourcepub fn stats(&self) -> TextAtlasStats
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() }Sourcepub fn get_or_rasterize(
&mut self,
device: &Device,
queue: &Queue,
bind_group_layout: &BindGroupLayout,
key: GlyphKey,
font_data: &[u8],
) -> Option<(u8, Glyph)>
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);
}Sourcepub fn get_or_rasterize_pinned(
&mut self,
device: &Device,
queue: &Queue,
bind_group_layout: &BindGroupLayout,
key: GlyphKey,
font_data: &[u8],
) -> Option<(u8, Glyph)>
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);
}Sourcepub fn record_missing_face(&mut self)
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§
impl Freeze for TextAtlas
impl !RefUnwindSafe for TextAtlas
impl Send for TextAtlas
impl Sync for TextAtlas
impl Unpin for TextAtlas
impl !UnwindSafe for TextAtlas
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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