Debian Codegraph @

third_party/rust/etagere/README.md

raw
1 # Étagère
2
3 <p align="center">
4 <a href="https://crates.io/crates/etagere">
5 <img src="https://img.shields.io/crates/v/etagere.svg" alt="crates.io">
6 </a>
7 <a href="https://docs.rs/etagere">
8 <img src="https://docs.rs/etagere/badge.svg" alt="documentation">
9 </a>
10
11 </p>
12
13 A dynamic texture atlas allocator using the shelf packing algorithm.
14
15 ## Motivation
16
17 The ability to dynamically batch textures together is important for some graphics rendering scenarios (for example [WebRender](https://github.com/servo/webrender)).
18
19 The shelf packing algorithm works very well when there is a high number of items with similar sizes, for example for dynamic glyph atlases.
20
21 See also [guillotière](https://github.com/nical/guillotiere), another dynamic atlas allocator based on a different algorithm, with different packing and performance characteristics.
22
23 ## Example
24
25 ```rust
26 use etagere::*;
27
28 let mut atlas = AtlasAllocator::new(size2(1000, 1000));
29
30 let a = atlas.allocate(size2(100, 1000)).unwrap();
31 let b = atlas.allocate(size2(900, 200)).unwrap();
32
33 atlas.deallocate(a.id);
34
35 let c = atlas.allocate(size2(300, 200)).unwrap();
36
37 assert_eq!(c.rectangle, atlas.get(c.id));
38
39 atlas.deallocate(c.id);
40 atlas.deallocate(b.id);
41 ```
42
43 ## License
44
45 Licensed under either of
46
47 * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
48 * MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
49
50 at your option.
51