pub struct TextureAtlas {
pub width: u32,
pub height: u32,
/* private fields */
}Expand description
Dynamic shelf-based texture atlas with LRU eviction.
§Allocation strategy
- Check the free-list for a first-fit region large enough.
- Walk existing shelves for one that can accommodate the request.
- Open a new shelf at the current bottom of the atlas.
- If all of the above fail, evict the LRU handle and retry once.
§Eviction
Evicted regions are pushed onto the free-list; they are re-used on the next allocation attempt. The atlas never compacts its shelf layout.
Fields§
§width: u32Atlas width in pixels.
height: u32Atlas height in pixels.
Implementations§
Source§impl TextureAtlas
impl TextureAtlas
Sourcepub fn new(width: u32, height: u32) -> Self
pub fn new(width: u32, height: u32) -> Self
Construct a new empty atlas of the given dimensions.
Sourcepub fn insert(&mut self, w: u32, h: u32) -> Option<AtlasHandle>
pub fn insert(&mut self, w: u32, h: u32) -> Option<AtlasHandle>
Insert a rectangle of size w × h into the atlas.
Returns an AtlasHandle on success, or None if the rectangle is
larger than the atlas or all eviction attempts were exhausted.
Sourcepub fn get(&self, h: AtlasHandle) -> Option<AtlasRect>
pub fn get(&self, h: AtlasHandle) -> Option<AtlasRect>
Retrieve the pixel rectangle for the given handle, if still live.
Sourcepub fn utilization(&self) -> f32
pub fn utilization(&self) -> f32
Fraction of the atlas area occupied by live allocations.
Returns a value in [0.0, 1.0].
Auto Trait Implementations§
impl Freeze for TextureAtlas
impl RefUnwindSafe for TextureAtlas
impl Send for TextureAtlas
impl Sync for TextureAtlas
impl Unpin for TextureAtlas
impl UnsafeUnpin for TextureAtlas
impl UnwindSafe for TextureAtlas
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
Mutably borrows from an owned value. Read more