![]() Instead of extracting an individual sprite per glyph of a text spawn or slice of a nine-patched sprite, add a buffer to store the extracted slice geometry. Fixes #16972 * New struct `ExtractedSlice` to hold sprite slice size, position and atlas info (for text each glyph is a slice). * New resource `ExtractedSlices` that wraps the `ExtractedSlice` buffer. This is a separate resource so it can be used without sprites (with a text material, for example). * New enum `ExtractedSpriteKind` with variants `Single` and `Slices`. `Single` represents a single sprite, `Slices` contains a range into the `ExtractedSlice` buffer. * Only queue a single `ExtractedSprite` for sets of glyphs or slices and push the geometry for each individual slice or glyph into the `ExtractedSlice` buffer. * Modify `ComputedTextureSlices` to return an `ExtractedSlice` iterator instead of `ExtractedSprites`. * Modify `extract_text2d_sprite` to only queue new `ExtractedSprite`s on font changes and otherwise push slices. I don't like the name `ExtractedSpriteKind` much, it's a bit redundant and too haskellish. But although it's exported, it's not something users will interact with most of the time so don't want to overthink it. yellow = this pr, red = main ```cargo run --example many_glyphs --release --features "trace_tracy" -- --no-ui``` <img width="454" alt="many-glyphs" src="https://github.com/user-attachments/assets/711b52c9-2d4d-43c7-b154-e81a69c94dce" /> ```cargo run --example many_text2d --release --features "trace_tracy"``` <img width="415" alt="many-text2d" src="https://github.com/user-attachments/assets/5ea2480a-52e0-4cd0-9f12-07405cf6b8fa" /> * `ExtractedSprite` has a new `kind: ExtractedSpriteKind` field with variants `Single` and `Slices`. - `Single` represents a single sprite. `ExtractedSprite`'s `anchor`, `rect`, `scaling_mode` and `custom_size` fields have been moved into `Single`. - `Slices` contains a range that indexes into a new resource `ExtractedSlices`. Slices are used to draw elements composed from multiple sprites such as text or nine-patched borders. * `ComputedTextureSlices::extract_sprites` has been renamed to `extract_slices`. Its `transform` and `original_entity` parameters have been removed. --------- Co-authored-by: Kristoffer Søholm <k.soeholm@gmail.com> |
||
---|---|---|
.. | ||
src | ||
Cargo.toml | ||
LICENSE-APACHE | ||
LICENSE-MIT | ||
README.md |