#2d #id #etagere

etagere

Dynamic 2D texture atlas allocation using the shelf packing algorithm

16 releases

0.2.15 Jan 21, 2025
0.2.13 Jun 17, 2024
0.2.10 Nov 17, 2023
0.2.8 Jul 4, 2023
0.2.1 Nov 26, 2020

#22 in Images

Download history 13600/week @ 2024-12-06 15334/week @ 2024-12-13 11450/week @ 2024-12-20 10506/week @ 2024-12-27 19733/week @ 2025-01-03 24082/week @ 2025-01-10 23020/week @ 2025-01-17 21052/week @ 2025-01-24 22039/week @ 2025-01-31 21326/week @ 2025-02-07 19584/week @ 2025-02-14 23578/week @ 2025-02-21 20727/week @ 2025-02-28 21588/week @ 2025-03-07 23277/week @ 2025-03-14 18289/week @ 2025-03-21

87,412 downloads per month
Used in 100 crates (23 directly)

MIT/Apache

91KB
2K SLoC

Étagère

crates.io documentation

A dynamic texture atlas allocator using the shelf packing algorithm.

Motivation

The ability to dynamically batch textures together is important for some graphics rendering scenarios (for example WebRender).

The shelf packing algorithm works very well when there is a high number of items with similar sizes, for example for dynamic glyph atlases.

See also guillotière, another dynamic atlas allocator based on a different algorithm, with different packing and performance characteristics.

Example

use etagere::*;

let mut atlas = AtlasAllocator::new(size2(1000, 1000));

let a = atlas.allocate(size2(100, 100)).unwrap();
let b = atlas.allocate(size2(900, 200)).unwrap();

atlas.deallocate(a.id);

let c = atlas.allocate(size2(300, 200)).unwrap();

assert_eq!(c.rectangle, atlas.get(c.id));

atlas.deallocate(c.id);
atlas.deallocate(b.id);

License

Licensed under either of

at your option.

Dependencies

~0.6–0.8MB
~19K SLoC