Crates.io | guillotiere |
lib.rs | guillotiere |
version | 0.6.2 |
source | src |
created_at | 2019-03-29 12:24:34.696557 |
updated_at | 2021-08-10 23:01:48.380993 |
description | A dynamic 2D texture atlas allocator with fast deallocation. |
homepage | |
repository | https://github.com/nical/guillotiere |
max_upload_size | |
id | 124536 |
size | 84,001 |
A dynamic texture atlas allocator with fast deallocation and rectangle coalescing.
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.
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);
Licensed under either of
at your option.