fix(dynamic-atlas): use dynamic batch size to prevent glyph clipping at large font sizes#78
Merged
junkdog merged 1 commit intoJan 25, 2026
Conversation
840a5bd to
e4ef1bc
Compare
Owner
|
i like the approach but i think it's better to rescale the offscreen canvas to fit 32 glyphs, to avoid creating too many (tiny) batches. |
Contributor
Author
I will try this approach maybe during weekend. Thanks for pointing direction :) |
… batch size Instead of dynamically reducing batch size when cell height is large, resize the offscreen canvas to always fit 32 glyphs. This avoids creating many small batches which hurts GPU performance. The canvas height is now calculated as: 32 * padded_cell_height For example, with 60px cell height: - Before: batch_size = 1024/60 = 17 glyphs (many small batches) - After: canvas = 32*60 = 1920px (optimal 32-glyph batches) Fixes junkdog#67
e4ef1bc to
efc040d
Compare
Contributor
Author
|
@junkdog Check it now please :) |
Owner
|
looking good, thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #67
The OffscreenCanvas used for glyph rasterization has a fixed height of 1024px. When using larger font sizes (e.g., 30px resulting in ~60px cell height), the previous hardcoded batch size of 32 glyphs would exceed the canvas height (32 × 60px = 1920px > 1024px), causing glyphs beyond the canvas boundary to be clipped/empty.
This was the root cause of characters like
~,-,<,>disappearing at larger font sizes - they appeared late in the ASCII batch and were rendered beyond the canvas boundary.Why
~(tilde) disappearedASCII
~is code 0x7E (126). In the ASCII glyph upload, it's at position 94 (126 - 32). With batch size 32:?)@to_)`to~)Tilde at local position 30 in batch 2 means Y = 30 × 60px = 1800px - well beyond the 1024px canvas!
The fix
Adds
CanvasRasterizer::max_batch_size()which dynamically calculates the maximum batch size based on cell height:This keeps the batch size knowledge encapsulated in the rasterizer where it belongs, and
DynamicFontAtlassimply callsself.rasterizer.max_batch_size()instead of using a hardcoded value.Test plan
upload_pending_glyphswhich also uses dynamic batch size now)