Text sections with the same font should be batched together #9278
Labels
A-Text
Rendering and layout for characters
A-UI
Graphical user interfaces, styles, layouts, and widgets
C-Code-Quality
A section of code that is hard to understand or change
C-Performance
A change motivated by improving speed, memory usage or compile times
D-Trivial
Nice and easy! A great choice to get started with Bevy
What problem does this solve or what need does it fill?
Consider the following example:
Which has output:
Text glyphs are stored in
TextLayoutInfo
in the fieldglyphs: Vec<PositionedGlyph>
. These glyphs are stored in the natural reading order left to right, line after line from top to bottom.In the example, the glyphs are all using the default font. But because it uses 3 different font sizes (10, 30 and 50) the text pipeline will generate three texture atlases, one for each font size. During the UI extraction schedule, the glyphs are added to the
ExtractedUiNodes
buffer in order "OneTwoThreeOneTwoThree" and so on. Then inprepare_ui_nodes
glyphs that are adjacent in the buffer and from the sameTextureAtlas
are batched together. This generates thirty batches, ten with the glyphs for "One", ten for "Two" and ten for "Three".Instead, we should be ordering the glyphs by
TextureAtlas
which would reduce the number of batches generated down to just three, one batch for the ten "One"s, one for the ten "Two"s and one for the ten "Three"s.What solution would you like?
Remove the
TextureAtlas
handle and section information fromPostionedGlyph
. Store the TextureAtlas handle in a second list (maybe in a smallvec since most text blocks don't have many text sections) per section. Then sort this second list by atlas handle.The text was updated successfully, but these errors were encountered: