#2d #graphics

guillotiere

A dynamic 2D texture atlas allocator with fast deallocation

14 releases

0.6.2 Aug 10, 2021
0.6.1 May 16, 2021
0.6.0 Aug 7, 2020
0.5.2 Jun 5, 2020
0.3.0 Mar 30, 2019

#23 in Memory management

Download history 16773/week @ 2023-02-17 16043/week @ 2023-02-24 17293/week @ 2023-03-03 15571/week @ 2023-03-10 14234/week @ 2023-03-17 14913/week @ 2023-03-24 15135/week @ 2023-03-31 15203/week @ 2023-04-07 12388/week @ 2023-04-14 13797/week @ 2023-04-21 14781/week @ 2023-04-28 14571/week @ 2023-05-05 13393/week @ 2023-05-12 14639/week @ 2023-05-19 16815/week @ 2023-05-26 16026/week @ 2023-06-02

63,631 downloads per month
Used in 261 crates (6 directly)

MIT/Apache

82KB
1.5K SLoC

Guillotière

crates.io Travis Build Status documentation

A dynamic texture atlas allocator with fast deallocation and rectangle coalescing.

Motivation

The ability to dynamically batch textures together is important for some graphics rendering scenarios (for example WebRender). A challenging aspect of dynamic atlas allocation is the need to coalesce free rectangles after deallocation to defragment the available space. Some atlas allocators perform this task by examining all possible pairs of free rectangles and test if they can be merged, which is prohibitively expensive for real-time applications.

Guillotière solves this problem by internally maintaining a data structure that allows constant time access to neighbor rectangles and greatly speeds up the coalesing operation.

The details of how this works are explained in the AtlasAllocator documentation.

Example

use guillotiere::*;

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

let a = atlas.allocate(size2(100, 1000)).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[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