a9045d45a0
Dos primitivas del pipeline de shaders_lab que ya estaban en uso pero sin indexar al registry: - code_to_generator_cpp_gfx (function, pure) Traduce un fragment shader GLSL escrito a mano (modo Code, con void main() + fragColor = ...) en un body de DAG Gen + DagControl[]. Cada uniform anotado se convierte en un control; el body usa el parametro uv y reemplaza fragColor= por return. Empaqueta uniforms en vec4 (4 x n_uniforms). - shaderlab_db_cpp_gfx (function, impure) CRUD persistente para generators custom de shaders_lab via sqlite3. Guarda el GLSL original, el body traducido para el DAG, los DagControl y los param_defaults en una BD local (shaders_lab.db). Soporta open(:memory:) para tests. Ambas se indexan ahora en registry.db y son reusables fuera de shaders_lab si en el futuro hay otra app que componga DAGs de shaders.
40 lines
1.6 KiB
C++
40 lines
1.6 KiB
C++
#pragma once
|
||
#include "gfx/dag_types.h"
|
||
#include <string>
|
||
#include <vector>
|
||
|
||
namespace fn::gfx {
|
||
|
||
// Result of translating a Code-mode GLSL fragment shader into a DAG generator
|
||
// body. `body_template` carries `__BASE__` placeholders that the body_glsl
|
||
// lambda substitutes for the node's vec4 base index at compile time.
|
||
struct CodeToGeneratorResult {
|
||
bool ok = false;
|
||
std::string err;
|
||
|
||
std::string body_template; // body with __BASE__ tokens
|
||
int param_count = 0; // size of step.params (4 × n_uniforms)
|
||
std::vector<float> param_defaults;
|
||
std::vector<std::string> param_names;
|
||
std::vector<DagControl> controls;
|
||
};
|
||
|
||
// Translate a Code-mode GLSL source (with `void main()` + `fragColor = ...;`)
|
||
// into a DAG Gen body + controls. Each annotated uniform becomes a DagControl;
|
||
// the body uses `uv` from the function parameter (any local `vec2 uv = ...;`
|
||
// line is stripped). Returns ok=false with err set on parse / unsupported-type
|
||
// errors. Pure: no I/O.
|
||
//
|
||
// Layout: each uniform claims one vec4 (4 floats), wasting unused components
|
||
// to keep the float→vec4 mapping trivial. Total floats = 4 × num_uniforms.
|
||
CodeToGeneratorResult code_to_generator(const std::string& source);
|
||
|
||
// Wrap a translation result into a DagNodeDef ready for dag_register_node().
|
||
// kind = Gen, num_inputs = 0, is_builtin = false.
|
||
DagNodeDef make_generator_def(const std::string& name,
|
||
const std::string& label,
|
||
const std::string& desc,
|
||
const CodeToGeneratorResult& tr);
|
||
|
||
} // namespace fn::gfx
|