Leaf-batched BVH draw commands

When a BVH leaf passes the frustum test, emit a single glMultiDrawElements
record covering the leaf's entire index range instead of one per object.
Leaves are contiguous in the EBO after reorderEbo, so the range is just
[first_object.index_offset, sum(index_count)]. Cuts draw calls by ~8x
(BVH_MAX_LEAF_SIZE) and shifts the bottleneck from CPU/driver per-draw
overhead toward GPU vertex throughput.

Per-object features (selection highlight, per-vertex color, object_id
picking) are unchanged — they operate on vertex attributes, not draw
state. Future per-object hide/override will use SSBO lookups sampled
by object_id in the fragment shader.

Slight overdraw from skipping per-object frustum tests within a leaf is
negligible given median-split BVH tightness and spare tri throughput.

Also adds visible_objects_ counter so stats still report true object
counts (not leaf counts), plus leaf_draws/model_draws breakdown in the
per-second frame log.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-04-12 19:17:44 +10:00
parent 36fa53122a
commit 8c8ef5c32b
2 changed files with 28 additions and 13 deletions
+1
View File
@@ -201,6 +201,7 @@ private:
};
std::vector<ModelDrawCmd> frame_draw_cmds_;
uint32_t visible_triangles_ = 0;
uint32_t visible_objects_ = 0;
// Camera
QVector3D camera_target_{0, 0, 0};