#2d #graphics

guillotiere

A dynamic 2D texture atlas allocator with fast deallocation

13 releases

new 0.6.1 May 16, 2021
0.6.0 Aug 7, 2020
0.5.2 Jun 5, 2020
0.5.1 Feb 27, 2020
0.3.0 Mar 30, 2019

#221 in Graphics APIs

Download history 5483/week @ 2021-01-21 4742/week @ 2021-01-28 4586/week @ 2021-02-04 4071/week @ 2021-02-11 4346/week @ 2021-02-18 4154/week @ 2021-02-25 4973/week @ 2021-03-04 4646/week @ 2021-03-11 4379/week @ 2021-03-18 5547/week @ 2021-03-25 4557/week @ 2021-04-01 5787/week @ 2021-04-08 4544/week @ 2021-04-15 4395/week @ 2021-04-22 5342/week @ 2021-04-29 4062/week @ 2021-05-06

20,409 downloads per month
Used in 60 crates (3 directly)

MIT/Apache

81KB
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

~570–800KB
~19K SLoC