Repository navigation
feat: upload tilemap and text vertices only when they change - #66
Draft
maurocristy87 wants to merge 1 commit into
Draft
maurocristy87 wants to merge 1 commit into
maurocristy87 wants to merge 1 commit into
Conversation
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Rendering
Vertex buffers per render data —
TilemapRendererandTextRendererno longer share a single pair of buffers re-uploaded on every draw. Each render data owns its position and texture buffers, kept in aWeakMapkeyed by the render data, so drawing the same tilemap chunk or text again (every frame, or once per camera) reuses the vertices already on the GPU. The attributes are bound on every draw, since consecutive draws of the same renderer now use different buffers.Vertices are regenerated only when their inputs change — the inputs are compared by value against a snapshot taken when the vertices were generated:
Float64Array, so Tiled ids carrying the flip flags in their high bits are stored exactly.No per-frame allocation for the vertices — they are written into scratch
Float32Arrays that grow only when needed, and uploaded withsubarrayinstead of wrapping a newFloat32Arrayon every draw.GPU memory is released when the render data is collected — a
FinalizationRegistrydeletes the buffers of a render data once it is garbage collected. The release happens whenever the browser collects, not right when the entity is removed.Texts with nothing to draw — a text whose layout produces no glyph returns without drawing, like an empty tilemap pass, instead of issuing a draw call with zero vertices.
Measurements
bufferDatacalls per frame in a static scene, before and after:demos/dev, tilemapdemos/dev, textAnimated tiles, runtime tile edits, text content, font size and alignment changes upload once and go back to zero. Screenshots of the test scene match the previous renderer in every step, on WebGL2 and on the legacy WebGL1 path.