perf: skip renderer for chunks with empty mesh

Pure-air chunks (above terrain) and chunks where every face culls
produce a zero-length mesh from ChunkMesher.Build(). Previously
InstallResult still allocated a real ChunkRenderer (VBO + VAO) and
registered a zero-vertex draw call. With RenderDistanceVertical=2 and
a player at surface Y, the topmost vertical layer is typically all
pure air -- roughly H*H = ~289 wasted renderers per spawn.

The chunk still gets added to _ready so SpawnReady, dirty-marking and
unload bookkeeping continue to work; DrawAll's iteration over the
renderer dictionary naturally skips entries that don't exist.
This commit is contained in:
2026-06-01 13:44:51 +02:00
parent 2c95c7831a
commit d1c8c22705
2 changed files with 47 additions and 1 deletions

View File

@@ -210,8 +210,15 @@ public sealed class ChunkStreamer : IDisposable
if (this._renderers.TryGetValue(result.Pos, out IChunkRenderer? old))
{
old.Dispose();
this._renderers.Remove(result.Pos);
}
// Skip renderer allocation for empty meshes (pure-air chunks above
// terrain, or chunks whose every face culls). The chunk still counts
// as ready — DrawAll's iteration over _renderers naturally no-ops.
if (result.Mesh.Length > 0)
{
this._renderers[result.Pos] = this._rendererFactory(result.Mesh);
}
this._renderers[result.Pos] = this._rendererFactory(result.Mesh);
this._ready.Add(result.Pos);
this._dirty.Remove(result.Pos);