Expand description
§GPU buffer batching – merges per-tile geometry into per-page draw calls
The batch module is the CPU-side counterpart to the tile atlas
(crate::gpu::tile_atlas). Where the atlas packs textures into
shared GPU pages, this module packs geometry into shared vertex and
index buffers so that every tile sharing an atlas page can be drawn
with a single draw_indexed call.
§Tile batches (build_tile_batches)
Each visible tile is a textured quad (4 vertices, 6 indices). The
builder looks up the tile’s AtlasRegion,
computes the world-space quad corners (camera-relative, f32), remaps
the UVs into the atlas sub-rectangle, and appends the vertices and
indices into a per-page accumulator. After iterating all visible tiles,
each non-empty page accumulator is uploaded as a single vertex + index
buffer pair (TileBatch).
The renderer issues one draw_indexed per non-empty page, binding the
page’s atlas texture. This reduces draw calls from N (one per tile) to
P (one per atlas page, typically 1-2).
§Terrain batches (build_terrain_batches)
Same grouping strategy, but the input is TerrainMeshData instead of
tile quads. Each terrain mesh has its own vertex count and index list;
the builder rebases indices and remaps UVs identically to tiles.
§Vector batches (build_vector_batch)
Vector layers are already pre-tessellated by the engine into a single
VectorMeshData per layer. This function converts the f64 world
positions to camera-relative f32 and uploads a single vertex + index
buffer pair. No atlas grouping is needed because vector geometry is
not textured.
§Memory pattern
Tile and vector batch buffers are now cached across frames using
invalidation-driven cache keys. Tile batches are keyed by the
visible tile set (target/actual pairs), quantised camera origin, and
active projection. Vector batches are keyed by layer vertex/index
counts and quantised camera origin. When the key matches the
previous frame, existing GPU buffers are reused without any
allocation or upload. When the key differs (e.g. camera movement
or tile set change), new buffers are created with
BufferUsages::VERTEX / INDEX and the cache is updated.
Terrain batches (for the legacy CPU-displaced fallback path) and
hillshade batches remain per-frame temporaries because the shared-grid
terrain path handles its own caching through SharedTerrainGridMesh
and CachedHeightTexture.
Structs§
- Circle
Batch Entry - GPU buffers for a circle layer rendered via SDF quads.
- Fill
Batch Entry - GPU buffers for a dedicated fill layer.
- Fill
Extrusion Batch Entry - GPU buffers for a single fill-extrusion layer’s tessellated mesh.
- Fill
Pattern Batch Entry - GPU buffers for a single patterned fill layer.
- Heatmap
Batch Entry - GPU buffers for a heatmap layer.
- Hillshade
Batch - GPU buffers for all terrain hillshade overlay meshes that share a single atlas page.
- Line
Batch Entry - GPU buffers for a single line layer’s tessellated mesh with dash data.
- Line
Pattern Batch Entry - GPU buffers for a single patterned line layer.
- Symbol
Batch Entry - Prepared GPU buffers for one symbol batch.
- Terrain
Batch - GPU buffers for all terrain meshes that share a single atlas page.
- Tile
Batch - GPU buffers for all flat tile quads that share a single atlas page.
- Tile
Page Batches - Per-page tile draw buffers split by depth behavior.
- Vector
Batch Entry - GPU buffers for a single vector layer’s tessellated mesh.
Functions§
- build_
circle_ batch - Build a circle batch from engine circle instance data.
- build_
fill_ batch - Build a fill batch entry from engine-tessellated mesh data.
- build_
fill_ extrusion_ batch - Build a fill-extrusion batch entry from engine-tessellated mesh data.
- build_
fill_ pattern_ batch - Build a fill-pattern batch entry from engine mesh data.
- build_
heatmap_ batch - Build a heatmap batch from engine heatmap point data.
- build_
hillshade_ batches - Build terrain hillshade batches grouped by the dedicated hillshade atlas.
- build_
line_ batch - Build a line batch entry from engine-tessellated mesh data.
- build_
line_ pattern_ batch - Build a line-pattern batch entry from engine mesh data.
- build_
placeholder_ batches - Build a single merged
VectorBatchEntrycontaining quads for all loading placeholders. - build_
symbol_ batch - Build a symbol batch from placed symbols and a populated glyph atlas.
- build_
terrain_ batches - Build terrain batches grouped by atlas page.
- build_
tile_ batches - Build tile batches grouped by atlas page.
- build_
vector_ batch - Build a vector batch entry from engine-tessellated mesh data.