pub struct UiImageAtlas { /* private fields */ }Expand description
Resource holding the UI image atlas (GPU texture) and an
AssetUUID → AtlasRect cache mapping each uploaded UI image to its
position inside the atlas.
Registered in [khora_core::Resources] at engine init; the UI agent
allocates the GPU atlas lazily via UiImageAtlas::ensure_atlas and
then borrows it for upload + render through UiImageAtlas::lock_atlas.
Implementations§
Source§impl UiImageAtlas
impl UiImageAtlas
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates an empty resource. The GPU atlas itself is allocated
lazily by ensure_atlas once a device is
available.
Sourcepub fn ensure_atlas(&self, device: &dyn GraphicsDevice) -> bool
pub fn ensure_atlas(&self, device: &dyn GraphicsDevice) -> bool
Allocates the GPU texture atlas if not yet present. Idempotent — safe to call every frame, the actual allocation happens once.
Returns true when the atlas is available after the call,
false if allocation failed.
Sourcepub fn lock_atlas(&self) -> Option<MutexGuard<'_, Option<TextureAtlas>>>
pub fn lock_atlas(&self) -> Option<MutexGuard<'_, Option<TextureAtlas>>>
Locks the GPU atlas for the duration of a frame’s upload + render.
Returns the locked MutexGuard<Option<TextureAtlas>>; callers
dereference twice (guard.as_mut()) to reach the optional
&mut TextureAtlas. The guard is held for the lifetime of the
caller’s local — typically UiAgent::execute for one frame.
Sourcepub fn get_rect(&self, id: &AssetUUID) -> Option<AtlasRect>
pub fn get_rect(&self, id: &AssetUUID) -> Option<AtlasRect>
Returns the AtlasRect previously stored for id, if any.
Sourcepub fn insert_rect(&self, id: AssetUUID, rect: AtlasRect)
pub fn insert_rect(&self, id: AssetUUID, rect: AtlasRect)
Stores rect under id.