Skip to main content

TextureAtlas

Struct TextureAtlas 

Source
pub struct TextureAtlas {
    pub width: u32,
    pub height: u32,
    /* private fields */
}
Expand description

Dynamic shelf-based texture atlas with LRU eviction.

§Allocation strategy

  1. Check the free-list for a first-fit region large enough.
  2. Walk existing shelves for one that can accommodate the request.
  3. Open a new shelf at the current bottom of the atlas.
  4. 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: u32

Atlas width in pixels.

§height: u32

Atlas height in pixels.

Implementations§

Source§

impl TextureAtlas

Source

pub fn new(width: u32, height: u32) -> Self

Construct a new empty atlas of the given dimensions.

Source

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.

Source

pub fn get(&self, h: AtlasHandle) -> Option<AtlasRect>

Retrieve the pixel rectangle for the given handle, if still live.

Source

pub fn utilization(&self) -> f32

Fraction of the atlas area occupied by live allocations.

Returns a value in [0.0, 1.0].

Source

pub fn resize(&mut self, new_width: u32, new_height: u32)

Discard all allocations and reinitialise with new dimensions.

Any existing handles become invalid. Uploading updated GPU texture data is the caller’s responsibility.

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

impl<T> Upcast<T> for T

Source§

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

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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