summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/render/shadergraph/qshadergraph.cpp22
-rw-r--r--tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp44
2 files changed, 56 insertions, 10 deletions
diff --git a/src/render/shadergraph/qshadergraph.cpp b/src/render/shadergraph/qshadergraph.cpp
index c2f3c343e..285aff116 100644
--- a/src/render/shadergraph/qshadergraph.cpp
+++ b/src/render/shadergraph/qshadergraph.cpp
@@ -242,16 +242,6 @@ QVector<QShaderGraph::Statement> QShaderGraph::createStatements(const QStringLis
return res;
}();
- const QVector<Edge> enabledEdges = [this, intersectsEnabledLayers] {
- auto res = QVector<Edge>();
- std::copy_if(m_edges.cbegin(), m_edges.cend(),
- std::back_inserter(res),
- [intersectsEnabledLayers] (const Edge &edge) {
- return intersectsEnabledLayers(edge.layers);
- });
- return res;
- }();
-
const QHash<QUuid, Statement> idHash = [enabledNodes] {
auto nextVarId = 0;
auto res = QHash<QUuid, Statement>();
@@ -260,6 +250,18 @@ QVector<QShaderGraph::Statement> QShaderGraph::createStatements(const QStringLis
return res;
}();
+ const QVector<Edge> enabledEdges = [this, intersectsEnabledLayers, &idHash] {
+ auto res = QVector<Edge>();
+ std::copy_if(m_edges.cbegin(), m_edges.cend(),
+ std::back_inserter(res),
+ [intersectsEnabledLayers, &idHash] (const Edge &edge) {
+ return intersectsEnabledLayers(edge.layers)
+ && idHash.contains(edge.sourceNodeUuid)
+ && idHash.contains(edge.targetNodeUuid);
+ });
+ return res;
+ }();
+
auto result = QVector<Statement>();
QVector<Edge> currentEdges = enabledEdges;
QVector<QUuid> currentUuids = [enabledNodes, enabledEdges] {
diff --git a/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp b/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp
index 6336763f5..e21b57577 100644
--- a/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp
+++ b/tests/auto/render/shadergraph/qshadergraph/tst_qshadergraph.cpp
@@ -116,6 +116,7 @@ private slots:
void shouldDealWithEdgesJumpingOverLayers();
void shouldGenerateDifferentStatementsDependingOnActiveLayers();
void shouldDealWithBranchesWithoutOutput();
+ void shouldDiscardEdgesConnectedToDiscardedNodes();
};
void tst_QShaderGraph::shouldHaveEdgeDefaultState()
@@ -816,6 +817,49 @@ void tst_QShaderGraph::shouldDealWithBranchesWithoutOutput()
QCOMPARE(statements, expected);
}
+void tst_QShaderGraph::shouldDiscardEdgesConnectedToDiscardedNodes()
+{
+ // GIVEN
+ const auto input = createNode({
+ createPort(QShaderNodePort::Output, "input")
+ });
+ const auto output = createNode({
+ createPort(QShaderNodePort::Input, "output")
+ });
+ const auto function0 = createNode({
+ createPort(QShaderNodePort::Input, "function0Input"),
+ createPort(QShaderNodePort::Output, "function0Output")
+ }, {"0"});
+ const auto function1 = createNode({
+ createPort(QShaderNodePort::Input, "function1Input"),
+ createPort(QShaderNodePort::Output, "function1Output")
+ }, {"1"});
+
+ const auto graph = [=] {
+ auto res = QShaderGraph();
+ res.addNode(input);
+ res.addNode(function0);
+ res.addNode(function1);
+ res.addNode(output);
+ res.addEdge(createEdge(input.uuid(), "input", function0.uuid(), "function0Input", {"0"}));
+ res.addEdge(createEdge(input.uuid(), "input", function1.uuid(), "function1Input"));
+ res.addEdge(createEdge(function0.uuid(), "function0Output", output.uuid(), "output"));
+ res.addEdge(createEdge(function1.uuid(), "function1Output", output.uuid(), "output"));
+ return res;
+ }();
+
+ // WHEN
+ const auto statements = graph.createStatements({"0"});
+
+ // THEN
+ const auto expected = QVector<QShaderGraph::Statement>()
+ << createStatement(input, {}, {0})
+ << createStatement(function0, {0}, {1})
+ << createStatement(output, {1}, {});
+ dumpStatementsIfNeeded(statements, expected);
+ QCOMPARE(statements, expected);
+}
+
QTEST_MAIN(tst_QShaderGraph)
#include "tst_qshadergraph.moc"