fix(shaders_lab): drop zone no longer eats node/slider input + inline tests
The previous InvisibleButton captured mouse events, so you could drag from the Functions palette into the canvas, but node dragging and slider interaction inside the canvas stopped working. Fix: watch the global drag-drop payload without an explicit target. When the mouse releases LMB over the DAG window with a "DAG_NODE_TYPE" payload active, queue an add at that canvas position. No button, no capture. Tests (compiled standalone with preprocessor defines): - dag_compile: 6/6 asserts (empty, single gen, op chain, multi-source blend, Output-driven fragColor, unconnected-Output fallback). - dag_catalog: 8/8 asserts (uniqueness, per-kind input invariants, exactly one Output, body_glsl present & returns, control param indices valid). Build with: g++ -std=c++17 -Icpp/functions -DDAG_COMPILE_TEST cpp/functions/gfx/dag_compile.cpp cpp/functions/gfx/dag_catalog.cpp -o /tmp/dag_compile_test g++ -std=c++17 -Icpp/functions -DDAG_CATALOG_TEST cpp/functions/gfx/dag_catalog.cpp -o /tmp/dag_catalog_test Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -106,3 +106,83 @@ std::string compile_dag_to_glsl(const std::vector<DagStep>& pipeline) {
|
||||
}
|
||||
|
||||
} // namespace fn::gfx
|
||||
|
||||
#ifdef DAG_COMPILE_TEST
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
static bool contains(const std::string& hay, const std::string& needle) {
|
||||
return hay.find(needle) != std::string::npos;
|
||||
}
|
||||
|
||||
int main() {
|
||||
using namespace fn::gfx;
|
||||
|
||||
// 1. Empty pipeline → seed color
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
assert(contains(s, "fragColor = vec4(0.04"));
|
||||
}
|
||||
|
||||
// 2. Single Gen → fragColor = out_0
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
DagStep g; g.id = "a"; g.name = "plasma";
|
||||
p.push_back(g);
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
assert(contains(s, "vec4 node_0"));
|
||||
assert(contains(s, "vec4 out_0 = node_0("));
|
||||
assert(contains(s, "fragColor = out_0"));
|
||||
}
|
||||
|
||||
// 3. Gen + Op → Op uses out_0 as input a
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
DagStep g; g.id = "a"; g.name = "plasma"; p.push_back(g);
|
||||
DagStep o; o.id = "b"; o.name = "invert"; o.source_ids[0] = "a"; p.push_back(o);
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
assert(contains(s, "out_1 = node_1(out_0, uv)"));
|
||||
assert(contains(s, "fragColor = out_1"));
|
||||
}
|
||||
|
||||
// 4. Blend with multi-source → both inputs resolved
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
DagStep a; a.id = "a"; a.name = "plasma"; p.push_back(a);
|
||||
DagStep b; b.id = "b"; b.name = "solid"; p.push_back(b);
|
||||
DagStep m; m.id = "m"; m.name = "blend_mix";
|
||||
m.source_ids[0] = "a"; m.source_ids[1] = "b";
|
||||
p.push_back(m);
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
assert(contains(s, "out_2 = node_2(out_0, out_1, uv)"));
|
||||
}
|
||||
|
||||
// 5. Output node drives fragColor from its source, not from last index
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
DagStep g1; g1.id = "g1"; g1.name = "plasma"; p.push_back(g1);
|
||||
DagStep g2; g2.id = "g2"; g2.name = "solid"; p.push_back(g2);
|
||||
DagStep o; o.id = "o"; o.name = "output";
|
||||
o.source_ids[0] = "g1"; // connect Output to the plasma (first gen), not last
|
||||
p.push_back(o);
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
// Output must NOT emit a node_2 function
|
||||
assert(!contains(s, "vec4 node_2("));
|
||||
// fragColor must come from out_0 (plasma), not out_1 (solid)
|
||||
assert(contains(s, "fragColor = out_0"));
|
||||
}
|
||||
|
||||
// 6. Output with no connection → seed fallback
|
||||
{
|
||||
std::vector<DagStep> p;
|
||||
DagStep g; g.id = "g"; g.name = "plasma"; p.push_back(g);
|
||||
DagStep o; o.id = "o"; o.name = "output"; p.push_back(o); // no source
|
||||
auto s = compile_dag_to_glsl(p);
|
||||
assert(contains(s, "fragColor = vec4(0.04"));
|
||||
}
|
||||
|
||||
std::printf("dag_compile: 6/6 asserts passed\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user