Files
fn_registry/cpp/functions/gfx/dag_node_previews.md
T
egutierrez ab3115ce99 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>
2026-04-25 02:06:50 +02:00

2.3 KiB

name, kind, lang, domain, version, purity, signature, description, tags, uses_functions, uses_types, returns, returns_optional, error_type, imports, tested, tests, test_file_path, file_path, framework, params, output
name kind lang domain version purity signature description tags uses_functions uses_types returns returns_optional error_type imports tested tests test_file_path file_path framework params output
dag_node_previews function cpp gfx 1.0.0 impure 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() 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.
opengl
fbo
preview
dag
gfx
gl_loader_cpp_gfx
gl_framebuffer_cpp_gfx
fullscreen_quad_cpp_gfx
dag_catalog_cpp_gfx
false error_go_core
gl_loader
dag_catalog
gl_framebuffer
fullscreen_quad
false
cpp/functions/gfx/dag_node_previews.cpp opengl
name desc
pipeline Pipeline DAG. Solo nodos con preview_open=true generan thumbnail. Output nodes se ignoran.
name desc
program GL program compilado a partir de compile_dag_to_glsl(pipeline). Debe declarar u_preview_target.
name desc
width Ancho del thumbnail en pixeles. Default 96.
name desc
height Alto del thumbnail en pixeles. Default 64.
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

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).