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
+55
View File
@@ -0,0 +1,55 @@
---
name: dag_node_previews
kind: function
lang: cpp
domain: gfx
version: "1.0.0"
purity: impure
signature: "void dag_previews_render(const std::vector<DagStep>&, unsigned program, int w, int h); unsigned dag_preview_texture(unsigned editor_uid); void dag_previews_destroy()"
description: "Renderiza un thumbnail por cada DagStep con preview_open=true a un FBO propio (lazy, keyed por editor_uid). Bind del FBO + glUniform1i(u_preview_target, i) + draw del quad. Devuelve la textura via dag_preview_texture para mostrarla con ImGui::Image."
tags: [opengl, fbo, preview, dag, gfx]
uses_functions: [gl_loader_cpp_gfx, gl_framebuffer_cpp_gfx, fullscreen_quad_cpp_gfx, dag_catalog_cpp_gfx]
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: [gl_loader, dag_catalog, gl_framebuffer, fullscreen_quad]
tested: false
tests: []
test_file_path: ""
file_path: "cpp/functions/gfx/dag_node_previews.cpp"
framework: opengl
params:
- name: pipeline
desc: "Pipeline DAG. Solo nodos con preview_open=true generan thumbnail. Output nodes se ignoran."
- name: program
desc: "GL program compilado a partir de compile_dag_to_glsl(pipeline). Debe declarar u_preview_target."
- name: width
desc: "Ancho del thumbnail en pixeles. Default 96."
- name: height
desc: "Alto del thumbnail en pixeles. Default 64."
output: "Cada FBO contiene out_<i> renderizado a width x height. Acceso via dag_preview_texture(uid)."
---
# dag_node_previews
Pipeline para thumbnails por nodo. Reutiliza el program GL del DAG (con un branch al final controlado por u_preview_target) y renderiza N veces a FBOs pequeños keyed por editor_uid del nodo.
No recompila al mover sliders ni al togglear preview — solo cambia el u_preview_target.
## Uso
```cpp
fn::gfx::canvas_render(g_canvas_dag, time, [&](unsigned p) {
fn::gfx::dag_uniforms_apply(g_pipeline, p);
});
fn::gfx::dag_previews_render(g_pipeline, g_canvas_dag.program);
// Luego en el editor del nodo:
unsigned tex = fn::gfx::dag_preview_texture(step.editor_uid);
if (tex) ImGui::Image((ImTextureID)(intptr_t)tex, ImVec2(96, 64));
```
## Recursos
Cada FBO se mantiene en un map estatico hasta llamar `dag_previews_destroy()` en shutdown. No se libera al borrar un nodo (pequena fuga en sesion larga; aceptable para 16 nodos max).