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.

SubTool thumbnails in the SubTool list, rendered from each SubTool's existing GPU buffers (#43)

islandmed714158dd660c
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 1f9fad36..fc762650 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -310,6 +310,7 @@ void App::shutdown() {
if (refTexture_) gl::DeleteTextures(1, &refTexture_);
gallery_.reset(); // its preview textures need the GL context
thumbs_.clear();
+ clearSubtoolThumbnails();
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplSDL3_Shutdown();
ImGui::DestroyContext();
@@ -1874,6 +1875,8 @@ void App::syncScene() {
}
renderer_.syncScene(scene);
renderer_.syncSplats(doc_.splats, doc_.splatsVersion);
+ if (subtoolPanelShown_) updateSubtoolThumbnails(); // from the buffers just synced (PanelSubTools.cpp)
+ subtoolPanelShown_ = false;
}
void App::setLayerWeight(int index, float weight) {
diff --git a/src/app/App.h b/src/app/App.h
index 361a23ad..c5d5f854 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -12,6 +12,7 @@
#include "app/LightBox.h"
#include "app/Pickers.h"
#include "app/ShellGeometry.h"
+#include "app/SubtoolThumbnails.h"
#include "app/Thumbnails.h"
#include "app/UiLayout.h"
#include "app/UserGuide.h"
@@ -53,6 +54,7 @@
#include <optional>
#include <set>
#include <string>
+#include <unordered_map>
#include <vector>
namespace sf {
@@ -951,6 +953,13 @@ private:
float subtoolClickX_ = 0.0f, subtoolClickY_ = 0.0f;
uint32_t renamingSubtool_ = 0; // SubTool id being renamed inline (0: none)
uint32_t listedActiveSubtool_ = 0; // the list scrolls to the active SubTool when it changes
+ // SubTool thumbnails (#43): rendered from each SubTool's GPU buffers while the SubTools panel shows, one per frame
+ // at most, a change once it has settled (SubtoolThumbnails.h); GL textures by SubTool id.
+ SubtoolThumbnailSchedule subtoolThumbSchedule_;
+ std::unordered_map<uint32_t, unsigned> subtoolThumbs_;
+ bool subtoolPanelShown_ = false; // drawn this frame
+ void updateSubtoolThumbnails(); // after syncScene, GL current
+ void clearSubtoolThumbnails();
bool focusRename_ = false;
char renameBuffer_[128] = "";
// Not-undoable SubTool commands wait for a confirmation popup.
diff --git a/src/app/PanelSubTools.cpp b/src/app/PanelSubTools.cpp
index 27cd9d96..d7c4e778 100644
--- a/src/app/PanelSubTools.cpp
+++ b/src/app/PanelSubTools.cpp
@@ -8,6 +8,7 @@
#include "app/App.h"
#include "app/Theme.h"
#include "core/Multires.h"
+#include "render/GL.h"
#include <cctype>
#include <imgui_internal.h>
@@ -16,6 +17,7 @@
#include <cmath>
#include <cstdio>
#include <string>
+#include <vector>
namespace sf {
@@ -28,6 +30,7 @@ constexpr ImVec4 kListWell = theme::rgb(0x1c1c1f); // the recessed area
constexpr ImVec4 kRowSelected = theme::rgb(0xffffff, 0.09f); // the active row: lighter neutral, plus the accent bar
constexpr ImVec4 kRowHover = theme::rgb(0xffffff, 0.11f);
constexpr ImVec4 kRowPressed = theme::rgb(0xffffff, 0.14f);
+constexpr ImVec4 kThumbWell = theme::rgb(0x000000, 0.22f); // behind a SubTool thumbnail (#43)
const SDL_DialogFileFilter kAppendFilters[] = {
{"Models and projects", "obj;fbx;glb;gltf;ply;stl;GoZ;goz;usda;usd;usdz;sfproj"}, {"All files", "*"}};
@@ -121,7 +124,62 @@ void App::subtoolClickRelease() {
subtoolClickFrame_ = false;
}
+void App::updateSubtoolThumbnails() {
+ // #43: what each SubTool looks like now; the schedule picks at most one to render this frame, from the GPU
+ // buffers syncScene just brought up to date (never a CPU render, never a re-upload: cheap on 30M+ meshes).
+ std::vector<uint32_t> ids;
+ ids.reserve(doc_.subtools.size());
+ const double now = double(SDL_GetTicksNS()) * 1e-9; // (the main loop's clock, as redrawAt_)
+ for (int i = 0; i < doc_.subtoolCount(); ++i) {
+ const SubTool& s = doc_.subtools[size_t(i)];
+ const Mesh& m = doc_.subtoolMesh(i);
+ const UndoStack& undo = i == doc_.activeSubtool ? doc_.undo : s.undo;
+ uint64_t key = undo.revision();
+ for (uint64_t part : {uint64_t(m.triangleCount()), uint64_t(m.vertexCount()), uint64_t(s.visible),
+ uint64_t(s.shading), uint64_t(renderSettings_.matcap + 1), uint64_t(renderSettings_.showPolypaint)})
+ key = key * 1099511628211ull ^ part;
+ subtoolThumbSchedule_.observe(s.id, key, now);
+ ids.push_back(s.id);
+ }
+ for (uint32_t gone : subtoolThumbSchedule_.keepOnly(ids))
+ if (auto it = subtoolThumbs_.find(gone); it != subtoolThumbs_.end()) {
+ gl::DeleteTextures(1, &it->second);
+ subtoolThumbs_.erase(it);
+ }
+ const bool busy = drag_ != Drag::None || strokeFinishing_ || solverBusy() || doc_.sculptor.strokeActive();
+ uint32_t id = 0;
+ double wakeAt = 0.0;
+ if (subtoolThumbSchedule_.due(now, busy, id, wakeAt)) {
+ constexpr int kPixels = 96; // shown at about 34 px: crisp on HiDPI
+ std::vector<uint8_t> rgba;
+ std::string error;
+ if (renderer_.renderSubtoolThumbnail(id, 30.0f, -15.0f, kPixels, renderSettings_, rgba, error)) {
+ unsigned& tex = subtoolThumbs_[id];
+ if (!tex) gl::GenTextures(1, &tex);
+ gl::BindTexture(GL_TEXTURE_2D, tex);
+ gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ gl::PixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ gl::TexImage2D(GL_TEXTURE_2D, 0, GLint(GL_RGBA8), kPixels, kPixels, 0, GL_RGBA, GL_UNSIGNED_BYTE, rgba.data());
+ gl::BindTexture(GL_TEXTURE_2D, 0);
+ }
+ subtoolThumbSchedule_.rendered(id); // (one that couldn't render, e.g. hidden before its first upload, waits for a change)
+ uint32_t next = 0;
+ if (subtoolThumbSchedule_.due(now, busy, next, wakeAt)) wakeAt = now; // another waiting: the next frame
+ }
+ if (wakeAt > 0.0) redrawAt_ = redrawAt_ > 0.0 ? std::min(redrawAt_, wakeAt) : wakeAt;
+}
+
+void App::clearSubtoolThumbnails() {
+ for (auto& [id, tex] : subtoolThumbs_) gl::DeleteTextures(1, &tex);
+ subtoolThumbs_.clear();
+ subtoolThumbSchedule_.keepOnly({});
+}
+
void App::drawSubToolsContents() {
+ subtoolPanelShown_ = true; // its thumbnails keep up while it shows (updateSubtoolThumbnails)
const float scale = uiScale_;
const int count = doc_.subtoolCount();
const int active = doc_.activeSubtool;
@@ -131,7 +189,10 @@ void App::drawSubToolsContents() {
int selectIndex = -1, toggleIndex = -1, deleteIndex = -1, duplicateIndex = -1, renameIndex = -1;
std::string renameTo;
const ImVec2 cellPad(6.0f * scale, 4.0f * scale);
- const float rowH = ImGui::GetTextLineHeight() + 2.0f * cellPad.y;
+ // Each row starts with the SubTool's thumbnail (#43); the text is centred on its height.
+ const float thumb = 30.0f * scale, lineH = ImGui::GetTextLineHeight();
+ const float innerH = std::max(lineH, thumb), textDy = (innerH - lineH) * 0.5f;
+ const float rowH = innerH + 2.0f * cellPad.y;
const float listH = rowH * float(std::min(count, kListRows)) + 2.0f;
ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, cellPad);
// The list sits in a recessed well, no outline. The active row is a lighter neutral with the accent only as the
@@ -159,7 +220,10 @@ void App::drawSubToolsContents() {
ImGui::PushID(int(s.id));
ImGui::TableNextRow(ImGuiTableRowFlags_None, rowH);
ImGui::TableSetColumnIndex(0);
+ const ImVec2 thumbAt = ImGui::GetCursorScreenPos();
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + thumb + 6.0f * scale);
if (renamingSubtool_ == s.id) {
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
ImGui::SetNextItemWidth(-1);
if (focusRename_) {
ImGui::SetKeyboardFocusHere();
@@ -178,11 +242,14 @@ void App::drawSubToolsContents() {
}
} else {
if (!s.visible) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
+ ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.0f, 0.5f));
if (ImGui::Selectable(s.name.c_str(), isActive,
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap |
- ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_NoAutoClosePopups) &&
+ ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_NoAutoClosePopups,
+ ImVec2(0.0f, innerH)) &&
!isActive)
selectIndex = i;
+ ImGui::PopStyleVar();
if (!s.visible) ImGui::PopStyleColor();
if (isActive) {
const ImVec2 r0 = ImGui::GetItemRectMin(), r1 = ImGui::GetItemRectMax();
@@ -216,19 +283,35 @@ void App::drawSubToolsContents() {
listedActiveSubtool_ = s.id;
}
}
+ {
+ // The thumbnail, or a quiet placeholder until it's rendered (updateSubtoolThumbnails).
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImVec2 t1(thumbAt.x + thumb, thumbAt.y + thumb);
+ dl->AddRectFilled(thumbAt, t1, ImGui::ColorConvertFloat4ToU32(kThumbWell), 3.0f * scale);
+ const auto tex = subtoolThumbs_.find(s.id);
+ if (tex != subtoolThumbs_.end() && tex->second)
+ dl->AddImageRounded(ImTextureID(tex->second), thumbAt, t1, ImVec2(0, 0), ImVec2(1, 1),
+ IM_COL32(255, 255, 255, s.visible ? 255 : 110), 3.0f * scale);
+ else
+ dl->AddCircle(ImVec2(thumbAt.x + thumb * 0.5f, thumbAt.y + thumb * 0.5f), thumb * 0.28f,
+ ImGui::GetColorU32(style.Colors[ImGuiCol_TextDisabled]), 0, 1.0f * scale);
+ }
ImGui::TableSetColumnIndex(1);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
if (const std::string sdiv = subdivLevelText(doc_.subtoolMesh(i)); !sdiv.empty()) {
ImVec4 col = style.Colors[isActive ? ImGuiCol_Text : ImGuiCol_TextDisabled];
if (isActive) col.w *= 0.75f;
ImGui::TextColored(col, "%s", sdiv.c_str());
}
ImGui::TableSetColumnIndex(2);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
const std::string tris = shortCount(doc_.subtoolMesh(i).triangleCount());
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + ImGui::GetContentRegionAvail().x - ImGui::CalcTextSize(tris.c_str()).x);
ImVec4 trisCol = style.Colors[isActive ? ImGuiCol_Text : ImGuiCol_TextDisabled];
if (isActive) trisCol.w *= 0.75f; // readable on the highlight
ImGui::TextColored(trisCol, "%s", tris.c_str());
ImGui::TableSetColumnIndex(3);
+ ImGui::SetCursorPosY(ImGui::GetCursorPosY() + textDy);
const ImVec2 eyePos = ImGui::GetCursorScreenPos();
const ImVec2 eyeSize(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeight());
if (ImGui::InvisibleButton(("##eye " + s.name).c_str(), eyeSize)) toggleIndex = i;
diff --git a/src/app/SubtoolThumbnails.h b/src/app/SubtoolThumbnails.h
new file mode 100644
index 00000000..2785655b
--- /dev/null
+++ b/src/app/SubtoolThumbnails.h
@@ -0,0 +1,86 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// When the SubTool panel's thumbnails (#43) are rendered: one SubTool at a time, a new one at once, a changed one
+// once it has settled (not every frame of a stroke), nothing while the app is busy with the mesh. The render itself
+// draws the SubTool's existing GPU buffers (Renderer::renderSubtoolThumbnail); this is only the bookkeeping, pure so
+// it can be unit tested.
+#pragma once
+
+#include <cstdint>
+#include <unordered_map>
+#include <vector>
+
+namespace sf {
+
+class SubtoolThumbnailSchedule {
+public:
+ static constexpr double kSettleSeconds = 0.5; // a change waits this long without another before its render
+
+ // SubTool `id` looks like `key` now (anything that changes when it does: its undo revision, size, visibility).
+ void observe(uint32_t id, uint64_t key, double now) {
+ Item& it = items_[id];
+ if (it.seen != key || !it.observed) {
+ it.seen = key;
+ it.seenAt = now;
+ it.observed = true;
+ }
+ }
+ // The SubTool to render now, if any: one never rendered first, else the change that settled longest ago; none
+ // while `busy` (a stroke or a background job owns the mesh). `wakeAt` gets when the next one is due (0: none
+ // waiting), so a loop that sleeps when idle can come back for it.
+ bool due(double now, bool busy, uint32_t& id, double& wakeAt) const {
+ wakeAt = 0.0;
+ bool found = false, fresh = false;
+ double oldest = 0.0;
+ for (const auto& [i, it] : items_) {
+ if (it.rendered && it.shown == it.seen) continue;
+ const double at = it.rendered ? it.seenAt + kSettleSeconds : it.seenAt;
+ if (busy || at > now) {
+ const double when = busy ? now + kSettleSeconds : at;
+ wakeAt = wakeAt == 0.0 ? when : (when < wakeAt ? when : wakeAt);
+ continue;
+ }
+ const bool isFresh = !it.rendered;
+ if (!found || (isFresh && !fresh) || (isFresh == fresh && at < oldest)) {
+ found = true;
+ fresh = isFresh;
+ oldest = at;
+ id = i;
+ }
+ }
+ return found;
+ }
+ // SubTool `id` was rendered as it was last observed (or couldn't be: it is tried again when it changes).
+ void rendered(uint32_t id) {
+ auto found = items_.find(id);
+ if (found == items_.end()) return;
+ found->second.shown = found->second.seen;
+ found->second.rendered = true;
+ }
+ // Forgets the SubTools not in `ids` (deleted, or a new scene); returns them, so their textures can go.
+ std::vector<uint32_t> keepOnly(const std::vector<uint32_t>& ids) {
+ std::vector<uint32_t> gone;
+ for (auto it = items_.begin(); it != items_.end();) {
+ bool keep = false;
+ for (uint32_t i : ids) keep = keep || i == it->first;
+ if (keep) {
+ ++it;
+ } else {
+ gone.push_back(it->first);
+ it = items_.erase(it);
+ }
+ }
+ return gone;
+ }
+
+private:
+ struct Item {
+ uint64_t seen = 0, shown = 0;
+ double seenAt = 0.0;
+ bool observed = false, rendered = false;
+ };
+ std::unordered_map<uint32_t, Item> items_;
+};
+
+} // namespace sf
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index a01845ea..7b734d45 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -59,7 +59,7 @@
// background_r / background_g / background_b (the flat colour, 0-255), subtool_shading (0 Scene, 1 Smooth, 2 Flat),
// custom_matcaps (MatCaps loaded from images), material_custom (1 when the view uses
// one), matcap_files (images in the library's MatCaps folder),
-// subtools (count), active_subtool (index, 0 = top), visible_subtools,
+// subtools (count), subtool_thumbnails (SubTool panel thumbnails rendered), active_subtool (index, 0 = top), visible_subtools,
// extract_preview (1 while an Extract preview waits for Accept), open_edges (edges of
// the active SubTool with one triangle: 0 = watertight),
// edited_subtools (SubTools with undo history), user_brushes (brushes in the
@@ -525,6 +525,11 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "guide_hits") return double(app_.guide_.searchHits());
const Document& doc = app_.doc_;
if (name == "subtools") return double(doc.subtoolCount());
+ if (name == "subtool_thumbnails") { // SubTool panel thumbnails rendered (#43)
+ double n = 0.0;
+ for (const auto& [id, tex] : app_.subtoolThumbs_) n += tex ? 1.0 : 0.0;
+ return n;
+ }
if (name == "active_subtool") return double(doc.activeSubtool);
if (name == "extract_preview") return doc.extractPreviewCurrent() ? 1.0 : 0.0;
if (name == "open_edges") {
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index fa137360..083f4c58 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -2935,5 +2935,45 @@ bool Renderer::renderMeshThumbnail(Mesh& mesh, const Camera& camera, int size, c
return ok;
}
+bool Renderer::renderSubtoolThumbnail(uint32_t id, float yaw, float pitch, int size, const RenderSettings& settings,
+ std::vector<uint8_t>& rgba, std::string& error) {
+ const MeshSlot* s = nullptr;
+ for (const MeshSlot& slot : slots_)
+ if (slot.id == id) s = &slot;
+ if (!s || s->fresh || s->outOfMemory || (!s->micro && s->drawnTriangles == 0) || !s->box.valid()) return false;
+ constexpr GLenum kFramebufferBinding = 0x8CA6, kViewport = 0x0BA2;
+ GLint fbo = 0, viewport[4] = {};
+ gl::GetIntegerv(kFramebufferBinding, &fbo);
+ gl::GetIntegerv(kViewport, viewport);
+
+ Camera camera;
+ camera.aspect = 1.0f;
+ camera.yaw = glm::radians(yaw);
+ camera.pitch = glm::radians(pitch);
+ camera.frame(s->box);
+ camera.distance *= 0.6f; // (frame leaves room around the model for the view; a thumbnail fills its tile)
+ RenderSettings thumb = settings;
+ thumb.showMask = thumb.showPolygroups = thumb.wireframe = false;
+ thumb.dimInactive = false;
+ constexpr size_t kProxyTriangles = size_t(1) << 20; // a big mesh: its lighter proxy, where current, is plenty at this size
+ thumb.motionProxy = s->drawnTriangles >= kProxyTriangles;
+ bool flat = false;
+ for (const DrawItem& item : drawList_)
+ if (item.id == id) flat = item.flat;
+ std::vector<DrawItem> scene;
+ scene.swap(drawList_);
+ drawList_.push_back({id, false, flat}); // (not active: no ghost, draft or mask on it)
+ const bool proxyUsed = proxyUsed_;
+ thumbnailPass_ = true;
+ const bool ok = renderToImage(camera, size, size, thumb, rgba, error);
+ thumbnailPass_ = false;
+ proxyUsed_ = proxyUsed; // (what the view drew decides which proxies sync keeps current)
+ drawList_.swap(scene);
+
+ gl::BindFramebuffer(GL_FRAMEBUFFER, GLuint(fbo));
+ gl::Viewport(viewport[0], viewport[1], viewport[2], viewport[3]);
+ return ok;
+}
+
} // namespace sf
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index 7ec35cbb..2ee0a7c0 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -176,6 +176,13 @@ public:
// top-down RGBA8 image with a transparent background. Keeps the caller's framebuffer and viewport.
bool renderMeshThumbnail(Mesh& mesh, const Camera& camera, int size, const RenderSettings& settings,
std::vector<uint8_t>& rgba, std::string& error);
+ // SubTool thumbnails (#43): SubTool `id` alone as last synced, from the GPU buffers it already has (nothing
+ // uploaded, so it stays cheap on 30M+ meshes: those draw their motion proxy where built), framed from the
+ // angle `yaw`, `pitch` (degrees) into a `size` x `size` top-down RGBA8 image with a transparent background.
+ // False when the SubTool has no drawn slot (hidden, not synced yet, out of GPU memory). Keeps the caller's
+ // framebuffer and viewport.
+ bool renderSubtoolThumbnail(uint32_t id, float yaw, float pitch, int size, const RenderSettings& settings,
+ std::vector<uint8_t>& rgba, std::string& error);
private:
void drawSplats(const glm::mat4& view, const glm::mat4& proj, int fbWidth, int fbHeight, float opacity);
diff --git a/tests/test_subtool_thumbnails.cpp b/tests/test_subtool_thumbnails.cpp
new file mode 100644
index 00000000..b9696526
--- /dev/null
+++ b/tests/test_subtool_thumbnails.cpp
@@ -0,0 +1,66 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// When SubTool thumbnails (#43) are rendered: a new SubTool at once, a change once it has settled, one at a time,
+// nothing while busy, and deleted SubTools forgotten.
+#include "TestHarness.h"
+
+#include "app/SubtoolThumbnails.h"
+
+using namespace sf;
+
+TEST(subtool_thumbnails_new_ones_render_at_once) {
+ SubtoolThumbnailSchedule s;
+ s.observe(1, 100, 0.0);
+ s.observe(2, 200, 0.0);
+ uint32_t id = 0;
+ double wake = 0.0;
+ CHECK(!s.due(0.0, true, id, wake)); // busy: nothing, but come back
+ CHECK(wake > 0.0);
+ CHECK(s.due(0.0, false, id, wake));
+ const uint32_t first = id;
+ s.rendered(first);
+ CHECK(s.due(0.0, false, id, wake) && id != first); // the other one, the next frame
+ s.rendered(id);
+ CHECK(!s.due(0.0, false, id, wake));
+ CHECK(wake == 0.0); // nothing waiting: the loop may sleep
+}
+
+TEST(subtool_thumbnails_changes_wait_to_settle) {
+ SubtoolThumbnailSchedule s;
+ uint32_t id = 0;
+ double wake = 0.0;
+ s.observe(7, 1, 0.0);
+ CHECK(s.due(0.0, false, id, wake) && id == 7);
+ s.rendered(7);
+ // A stroke changes it every frame: no render until it stops changing for a while.
+ for (int f = 1; f <= 30; ++f) {
+ s.observe(7, uint64_t(1 + f), f * 0.016);
+ CHECK(!s.due(f * 0.016, false, id, wake));
+ CHECK(wake > f * 0.016);
+ }
+ const double last = 30 * 0.016;
+ s.observe(7, 31, last + 0.1); // the same key: still waiting from the last change
+ CHECK(!s.due(last + 0.1, false, id, wake));
+ CHECK(s.due(last + SubtoolThumbnailSchedule::kSettleSeconds + 0.01, false, id, wake) && id == 7);
+ s.rendered(7);
+ CHECK(!s.due(10.0, false, id, wake));
+}
+
+TEST(subtool_thumbnails_forget_deleted) {
+ SubtoolThumbnailSchedule s;
+ s.observe(1, 1, 0.0);
+ s.observe(2, 1, 0.0);
+ s.observe(3, 1, 0.0);
+ const std::vector<uint32_t> gone = s.keepOnly({1, 3});
+ CHECK(gone.size() == 1 && gone[0] == 2);
+ uint32_t id = 0;
+ double wake = 0.0;
+ int rendered = 0;
+ while (s.due(0.0, false, id, wake)) {
+ CHECK(id != 2);
+ s.rendered(id);
+ ++rendered;
+ }
+ CHECK(rendered == 2);
+}