Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Coarse levels: UI test values coarse_clusters / coarse_pending; coarse_lod.sfui checks the edited clusters pend during a stroke and are coarse again after it

islandmeda29428f3f3c8
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 7251fa87..ab9240eb 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -988,6 +988,11 @@ double Demo::query(const std::string& name, bool& known) const {
app_.benchmarkDrawMs(0);
return double(app_.renderer_.lastDrawnTriangles());
}
+ if (name == "coarse_clusters") { // the 3D view drawn once more now: the clusters it drew at a coarse level
+ app_.benchmarkDrawMs(0);
+ return double(app_.renderer_.coarseDrawnClusters());
+ }
+ if (name == "coarse_pending") return double(app_.renderer_.coarsePendingClusters()); // edited, levels not updated yet
if (name == "panel_drag_scrolls") return double(ui::DragScrolls()); // #100: drags that scrolled a panel
if (name == "panel_drag_scroll_y") return double(ui::DragScrollY()); // that panel's scroll after the last one
if (name == "drag_cursor") return double(dragCursor_); // the system cursor during the last button_drag (#88)
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index f37e9325..1d30519a 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -2967,6 +2967,7 @@ void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, con
: glm::vec4(0.0f, 0.0f, float(targetWidth), float(targetHeight));
frameCull_ = CullView::from(view, proj);
lastDrawn_ = 0;
+ lastCoarseClusters_ = 0;
gl::Enable(GL_DEPTH_TEST);
gl::DepthFunc(GL_LEQUAL);
if (drawList_.empty() || !settings.showMesh) {
@@ -3295,6 +3296,12 @@ void Renderer::uploadCoarsePoints(MeshSlot& s) {
gl::BufferData(GL_ARRAY_BUFFER, GLsizeiptr(packed.size() * sizeof(PackedVertex)), packed.data(), GL_STATIC_DRAW);
}
+size_t Renderer::coarsePendingClusters() const {
+ size_t n = 0;
+ for (const MeshSlot& s : slots_) n += s.coarsePending.size();
+ return n;
+}
+
void Renderer::markCoarseDirty(MeshSlot& s, uint32_t c) {
if (!s.coarse || c >= s.coarseDirty.size()) return;
s.coarseEdited = true;
@@ -3458,6 +3465,8 @@ void Renderer::drawSlot(const MeshSlot& s, bool active, bool flat, const RenderS
std::fprintf(stderr, "coarse lod: not drawn (per-triangle %d, wireframe %d, drawn %zu, budget %zu)\n", int(perTriangle),
int(active && settings.wireframe), s.drawnTriangles, budget);
if (coarse) cullCoarse(s, frameCull_, budget);
+ else coarseClusters_.clear();
+ lastCoarseClusters_ += coarseClusters_.size();
else cull(s, frameCull_, settings.motionProxy && coarseAllowed);
// The back faces left in clusters along the silhouette: the GPU skips them too when they can't show.
if (cullBackfaces_ || xrayCull_) gl::Enable(GL_CULL_FACE);
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index 489097e0..64780992 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -250,6 +250,10 @@ public:
size_t microPendingShading() const;
// Triangles the last draw() sent to the GPU (after culling), for the benchmark.
size_t lastDrawnTriangles() const { return lastDrawn_; }
+ // Coarse levels (tests): the clusters the last frame drew at a coarse level, and the edited clusters whose levels
+ // are still to be updated (drawn in full until then).
+ size_t coarseDrawnClusters() const { return lastCoarseClusters_; }
+ size_t coarsePendingClusters() const;
// The last syncScene left motion proxies to build (a few milliseconds of them a frame; the rest draw in full).
bool proxiesPending() const { return proxyPending_; }
// Build stale motion proxies on still frames too (after a stroke, so the next orbit starts with them), at a
@@ -478,6 +482,7 @@ private:
// (coarseClusters_, coarseLevel_), the finest that fits.
void cullCoarse(const MeshSlot& s, const CullView& view, size_t budget);
std::vector<uint32_t> coarseClusters_;
+ size_t lastCoarseClusters_ = 0;
std::vector<uint8_t> coarseLevel_;
void drawSlot(const MeshSlot& s, bool active, bool flat, const RenderSettings& settings);
enum class DrawPart { Triangles, Lines, Proxy };
diff --git a/tests/ui/coarse_lod.sfui b/tests/ui/coarse_lod.sfui
index 1b88e557..fa1e7e79 100644
--- a/tests/ui/coarse_lod.sfui
+++ b/tests/ui/coarse_lod.sfui
@@ -15,11 +15,20 @@ wait 0.6
expect_value drawn_triangles <= 40000
shot coarse-turned
-# A stroke: the clusters it moved draw in full while it runs; the levels are updated after it.
+# A stroke: the clusters it moved draw in full while it runs (pending); after it their levels are updated and every
+# cluster is coarse again, the budget held. (Unit test coarse_levels_follow_edits checks the updated cells' points.)
camera 0 0
wait 0.6
-drag_path 0.42 0.45 0.58 0.45 0.58 0.55
+remember coarse_clusters before
+expect_value coarse_pending == 0
+stroke 0.42 0.45 0.58 0.55 0.6 hold
+expect_value coarse_pending > 0
+expect_value coarse_clusters < $before
+shot coarse-during-stroke
+release
wait 0.6
+expect_value coarse_pending == 0
+expect_value coarse_clusters == $before
expect_value drawn_triangles <= 40000
shot coarse-after-stroke