-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uncouple DynamicTextureAtlasBuilder
from assets
#13717
Conversation
Remove the dependency of `DynamicTextureAtlasBuilder::add_texture` to `bevy_asset`, by directly passing the `Image` of the atlas to mutate, instead of passing separate `Assets<Image>` and `Handle<Image>` for the function to do the lookup by itself. The lookup can be done from the caller, and this allows using the builder in contexts where the `Image` is not stored inside `Assets`. Clean-up a bit the font atlas files by introducing a `PlacedGlyph` type storing the `GlyphId` and its `SubpixelOffset`, which were otherwise always both passed as function parameters and the pair used as key in hash maps.
@brandon-reinhart I'd appreciate your opinions here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me.
The |
I've updated the migration guide, but one or both of you may have suggestions on how to improve this. |
Migration guide looks good to me, thanks @alice-i-cecile! |
Objective
Remove some unnecessary coupling between
DynamicTextureAtlasBuilder
andbevy_asset
.Solution
Remove the dependency of
DynamicTextureAtlasBuilder::add_texture
tobevy_asset
, by directly passing theImage
of the atlas to mutate, instead of passing separateAssets<Image>
andHandle<Image>
for the function to do the lookup by itself. The lookup can be done from the caller, and this allows using the builder in contexts where theImage
is not stored insideAssets
.Clean-up a bit the font atlas files by introducing a
PlacedGlyph
type storing theGlyphId
and itsSubpixelOffset
, which were otherwise always both passed as function parameters and the pair used as key in hash maps.Testing
There's no change in behavior.
Changelog
PlacedGlyph
type aggregating aGlyphId
and aSubpixelOffset
. That type is now used as parameter in a few text atlas APIs, instead of passing individual values.Migration Guide
glyph_id
andsubpixel_offset
of a few text atlas APIs by a singleplace_glyph: PlacedGlyph
parameter trivially combining the two.DynamicTextureAtlasBuilder::add_texture
now takes a&mut Image
, rather than aHandle<Image>
. To access this, fetch the underlying image usingAssets<Image>::get_mut
.