create font atlas that can contains fonts of any size (#3592)
# Objective - Bevy currently panics when displaying text with a *very* big font size (with font size greater than 400, the glyph would have a width or height greater than 512) ``` thread 'main' panicked at 'Fatal error when processing text: failed to add glyph to newly-created atlas GlyphId(514).', crates/bevy_ui/src/widget/text.rs:118:21 ``` ## Solution - Create font atlas that scales up with the size of the glyphs
This commit is contained in:
parent
cc4062ec43
commit
a16ffe6239
@ -76,10 +76,18 @@ impl FontAtlasSet {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
if !font_atlases.iter_mut().any(add_char_to_font_atlas) {
|
if !font_atlases.iter_mut().any(add_char_to_font_atlas) {
|
||||||
|
// Find the largest dimension of the glyph, either its width or its height
|
||||||
|
let glyph_max_size: u32 = glyph_texture
|
||||||
|
.texture_descriptor
|
||||||
|
.size
|
||||||
|
.height
|
||||||
|
.max(glyph_texture.texture_descriptor.size.width);
|
||||||
|
// Pick the higher of 512 or the smallest power of 2 greater than glyph_max_size
|
||||||
|
let containing = (1u32 << (32 - glyph_max_size.leading_zeros())).max(512) as f32;
|
||||||
font_atlases.push(FontAtlas::new(
|
font_atlases.push(FontAtlas::new(
|
||||||
textures,
|
textures,
|
||||||
texture_atlases,
|
texture_atlases,
|
||||||
Vec2::new(512.0, 512.0),
|
Vec2::new(containing, containing),
|
||||||
));
|
));
|
||||||
if !font_atlases.last_mut().unwrap().add_glyph(
|
if !font_atlases.last_mut().unwrap().add_glyph(
|
||||||
textures,
|
textures,
|
||||||
|
Loading…
Reference in New Issue
Block a user