feat(shaders_lab): per-node preview thumbnails + double-rclick delete node

- DagStep: preview_open flag (default false).
- dag_compile: emit `uniform int u_preview_target` and a series of
  early-return branches at the start of fragColor selection. -1 (default)
  falls through to the real Output-driven fragColor.
- dag_node_previews (new fn): per-node FBO keyed by editor_uid, lazy
  created. Renders each node with preview_open=true to its FBO by
  setting u_preview_target = step index. Texture exposed via
  dag_preview_texture(uid) for ImGui::Image.
- dag_node_editor: small toggle button "[+] preview"/"[-] preview" in
  each non-Output node; when open, ImGui::Image(96x64, V-flipped).
- dag_node_editor: double right-click on hovered node deletes it
  (Output is protected).
- main.cpp: dag_previews_render after Canvas DAG; dag_previews_destroy
  on shutdown.

Single GL program drives both the canvas and all thumbnails — moving
sliders never recompiles, only the topology change does.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-25 02:06:50 +02:00
parent a209afa46b
commit ac65791663
9 changed files with 245 additions and 1 deletions
+12 -1
View File
@@ -11,7 +11,8 @@ std::string compile_dag_to_glsl(const std::vector<DagStep>& pipeline) {
const int n = static_cast<int>(std::min(pipeline.size(), static_cast<size_t>(MAX_NODES)));
std::ostringstream out;
out << "uniform vec4 u_params[16];\n\n";
out << "uniform vec4 u_params[16];\n";
out << "uniform int u_preview_target; // -1 = real Output; >=0 = show out_<i>\n\n";
if (n == 0) {
out << "void main() {\n";
@@ -81,6 +82,16 @@ std::string compile_dag_to_glsl(const std::vector<DagStep>& pipeline) {
last_valid_out = i;
}
// Preview branch: if u_preview_target points to a valid out_<i>, emit it
// and bail out before the Output-driven fragColor.
for (int i = 0; i < n; ++i) {
const DagStep& step = pipeline[static_cast<size_t>(i)];
const DagNodeDef* def = dag_find(step.name);
if (!def) continue;
if (def->kind == DagKind::Output) continue;
out << " if (u_preview_target == " << i << ") { fragColor = out_" << i << "; return; }\n";
}
// Resolve fragColor: if there's an Output node with a connection, use that; else fallback.
auto seed = [&]() { out << " fragColor = vec4(0.04, 0.04, 0.06, 1.0);\n"; };