Continually merge texture atlas pages #4252
Merged
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.
When atlas pages are created beyond a certain threshold determined by the webgl maximum texture units, the 4 largest and most used atlas pages are merged (eg. 512x512 -> 1024x1024). This continues to happen up to a maximum of 4096x4096 (16mb). The merging happens in a microtask so the current render cycle finishes as changing the texture would result in corrupted rendering. Atlas pages 1024x1024 and above are all immutable intentionally to avoid uploading large texture more than once.
The canvas rendering works with merged atlas pages but no maximum page count is enforced so if the atlas is only used by a canvas rendering, no merging occurs.
Fixes #4243
Fixes #4245 - webgl texture capacity will typically hit before this happens which is very hard to actually hit even in the demo
Fixes #4246
Here's an example of a 2048x2048 texture atlas page after running the CJK test button.
There's also another CJK test button which helps stress test the renderer: