Files
fn_registry/cpp/functions/viz/graph_renderer.md
egutierrez 7eef2544ab feat: add C++ ImGui functions for core UI and visualization
Funciones C++/ImGui para dashboards (grid, panel, docking, sidebar, tabs),
visualizaciones (candlestick, gauge, histogram, pie, sparkline, heatmap,
scatter, line, bar, surface3d, kpi, table), grafos (force layout, renderer,
viewport, spatial hash, types) y utilidades (time series buffer, tracy zones,
memory/fps overlay, plot theme).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 00:10:18 +02:00

3.2 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
graph_renderer function cpp viz 1.0.0 impure GraphRenderer* graph_renderer_create(int width, int height, const GraphRendererConfig& config) Renderer GPU de grafos con instanced rendering a FBO, compatible con ImGui::Image para visualizacion de grafos grandes
graph
renderer
opengl
gpu
instanced
fbo
visualization
GraphData_cpp_viz
false error_go_core
imgui
false
cpp/functions/viz/graph_renderer.cpp imgui
name desc
width Ancho del framebuffer en pixels
name desc
height Alto del framebuffer en pixels
name desc
config Configuracion visual: outline width, edge width, edge alpha, color de fondo, fade de aristas por distancia a camara
Handle opaco al renderer. Usar graph_renderer_draw() para obtener texture ID de OpenGL, pasable directamente a ImGui::Image()

graph_renderer

Renderer GPU de grafos basado en OpenGL 3.3 core profile con instanced rendering. Renderiza nodos y aristas de un GraphData a un FBO interno y retorna el texture ID para integracion directa con ImGui::Image().

Funciones del API

// Ciclo de vida
GraphRenderer* graph_renderer_create(int width, int height, const GraphRendererConfig& config = {});
void graph_renderer_destroy(GraphRenderer* r);
void graph_renderer_resize(GraphRenderer* r, int width, int height);

// Renderizado
unsigned int graph_renderer_draw(GraphRenderer* r, const GraphData& graph,
                                  float cam_x, float cam_y, float cam_zoom);

Ejemplo de uso con ImGui

// Inicializacion (una vez)
GraphRenderer* renderer = graph_renderer_create(800, 600);

// En el render loop
ImVec2 panel_size = ImGui::GetContentRegionAvail();
graph_renderer_resize(renderer, (int)panel_size.x, (int)panel_size.y);

unsigned int tex = graph_renderer_draw(renderer, graph_data,
                                        cam_x, cam_y, cam_zoom);

ImGui::Image((ImTextureID)(uintptr_t)tex,
             panel_size,
             ImVec2(0, 1), ImVec2(1, 0)); // flip Y para OpenGL

// Destruccion
graph_renderer_destroy(renderer);

Notas de implementacion

Renderizado de nodos: Instanced rendering con un quad unitario [-0.5, 0.5] expandido por el tamano del nodo. El fragment shader aplica un SDF circular con anti-aliasing via smoothstep y un anillo de outline.

Renderizado de aristas: GL_LINES con datos de posicion y color empaquetados por arista. El ancho se controla con GraphRendererConfig::edge_width.

Transformacion de camara:

tx = -cam_x * zoom + width/2
ty = -cam_y * zoom + height/2
ndc = (screen / viewport) * 2 - 1

Paleta de comunidades: 10 colores ABGR usados cuando node.color == 0, seleccionados por node.community % 10.

Estado GL: Guarda y restaura GL_FRAMEBUFFER_BINDING y GL_VIEWPORT para ser compatible con el render loop de ImGui sin efectos secundarios.

Includes GL: Usa #define GL_GLEXT_PROTOTYPES + <GL/gl.h> + <GL/glext.h>. Si el proyecto carga funciones GL via glad/gl3w, reemplazar estos includes por el loader correspondiente.