refactor(shaders_lab): extraer compile_* a compiler.{h,cpp}

This commit is contained in:
2026-04-28 23:56:33 +02:00
parent f2521bd7d2
commit 0cfaa27ee1
4 changed files with 109 additions and 45 deletions
+21 -45
View File
@@ -19,6 +19,8 @@
#include "core/app_menubar.h"
#include "core/layout_storage.h"
#include "compiler.h"
#include <chrono>
#include <cctype>
#include <cstring>
@@ -27,8 +29,9 @@
#include <utility>
#include <vector>
static fn::gfx::ShaderCanvas g_canvas_code;
static fn::gfx::ShaderCanvas g_canvas_dag;
// Globals: linked extern desde compiler.cpp. NO `static` aqui.
fn::gfx::ShaderCanvas g_canvas_code;
fn::gfx::ShaderCanvas g_canvas_dag;
// Default placeholder so the Code panel does something useful on first launch
// without committing to one specific look.
@@ -47,19 +50,19 @@ void main() {
}
)glsl";
static std::string g_source = CODE_PLACEHOLDER;
static std::string g_code_err;
static int g_code_err_line = -1;
static std::chrono::steady_clock::time_point g_code_last_edit;
static bool g_code_dirty = true;
static std::vector<fn::gfx::UniformDescriptor> g_descs;
static fn::gfx::UniformStore g_store;
std::string g_source = CODE_PLACEHOLDER;
std::string g_code_err;
int g_code_err_line = -1;
std::chrono::steady_clock::time_point g_code_last_edit;
bool g_code_dirty = true;
std::vector<fn::gfx::UniformDescriptor> g_descs;
fn::gfx::UniformStore g_store;
static std::vector<fn::gfx::DagStep> g_pipeline;
static std::string g_dag_glsl;
static std::string g_dag_err;
static int g_dag_err_line = -1;
static bool g_dag_dirty = true;
std::vector<fn::gfx::DagStep> g_pipeline;
std::string g_dag_glsl;
std::string g_dag_err;
int g_dag_err_line = -1;
static bool g_dag_dirty = true; // solo lo usa main.cpp
// ── Panel visibility (toggled from View menu and panel close button) ──────
static bool g_show_code = true;
@@ -84,37 +87,10 @@ static char g_save_desc[256] = "";
static char g_save_tags[128] = "shaders_lab,user";
static std::string g_save_err;
static void compile_code() {
auto r = fn::gfx::compile_fragment(g_source);
if (r.ok) {
g_descs = fn::gfx::parse_uniforms(g_source);
fn::gfx::uniforms_sync(g_store, g_descs);
fn::gfx::canvas_set_program(g_canvas_code, r.program);
g_code_err.clear();
g_code_err_line = -1;
} else {
g_code_err = r.err_msg;
g_code_err_line = r.err_line;
}
}
static void compile_dag() {
g_dag_glsl = fn::gfx::compile_dag_to_glsl(g_pipeline);
auto r = fn::gfx::compile_fragment(g_dag_glsl);
if (r.ok) {
fn::gfx::canvas_set_program(g_canvas_dag, r.program);
g_dag_err.clear();
g_dag_err_line = -1;
} else {
g_dag_err = r.err_msg;
g_dag_err_line = r.err_line;
}
}
static void mark_code_dirty() {
g_code_last_edit = std::chrono::steady_clock::now();
g_code_dirty = true;
}
// compile_code, compile_dag, mark_code_dirty viven en compiler.cpp
using shaders_lab::compile_code;
using shaders_lab::compile_dag;
using shaders_lab::mark_code_dirty;
static void ensure_dag_default() {
if (g_pipeline.empty()) {