pub struct BucketedAtlasAllocator { /* private fields */ }
Expand description

A faster but less precise Shelf-packing dynamic texture atlas allocator, inspired by https://github.com/mapbox/shelf-pack/

Items are accumulated into buckets which are laid out in rows (shelves) of variable height. When allocating we first look for a suitable bucket. If none is found, a new shelf of the desired height is pushed.

Lifetime isn’t tracked at item granularity. Instead, items are grouped into buckets and deallocation happens per bucket when all items of the buckets are removed. When the top-most shelf is empty, it is removed, potentially cascading into garbage-collecting the next shelf, etc.

This allocator works well when there are a lot of small items with similar sizes (typically, glyph atlases).

Implementations§

source§

impl BucketedAtlasAllocator

source

pub fn with_options(size: Size, options: &AllocatorOptions) -> Self

Create an atlas allocator with provided options.

source

pub fn new(size: Size) -> Self

Create an atlas allocator with default options.

source

pub fn clear(&mut self)

source

pub fn size(&self) -> Size

source

pub fn grow(&mut self, new_size: Size)

source

pub fn is_empty(&self) -> bool

source

pub fn allocate(&mut self, requested_size: Size) -> Option<Allocation>

Allocate a rectangle in the atlas.

source

pub fn deallocate(&mut self, id: AllocId)

Deallocate a rectangle in the atlas.

Space is only reclaimed when all items of the same bucket are deallocated.

source

pub fn allocated_space(&self) -> i32

Amount of occupied space in the atlas.

source

pub fn free_space(&self) -> i32

How much space is available for future allocations.

source

pub fn dump_svg(&self, output: &mut dyn Write) -> Result<()>

Dump a visual representation of the atlas in SVG format.

source

pub fn dump_into_svg( &self, rect: Option<&Rectangle>, output: &mut dyn Write ) -> Result<()>

Dump a visual representation of the atlas in SVG, omitting the beginning and end of the SVG document, so that it can be included in a larger document.

If a rectangle is provided, translate and scale the output to fit it.

Trait Implementations§

source§

impl Clone for BucketedAtlasAllocator

source§

fn clone(&self) -> BucketedAtlasAllocator

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere 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> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.