diff options
author | Nicolas Guichard <nicolas.guichard@kdab.com> | 2020-02-19 12:38:27 +0100 |
---|---|---|
committer | Paul Lemire <paul.lemire@kdab.com> | 2020-02-21 12:47:28 +0000 |
commit | 34369b5e90cfc15d247a09fac8d7d3c4de2f1310 (patch) | |
tree | 0f496981b284b634ba1e74c304e0c13e01c163a3 /src | |
parent | b150901525958f3d6e2a1cef1f49bda24c94a3fd (diff) |
QShaderGraph: don't generate statements with undefined inputs
This fixes the shader generation for graphs like this one:
Function0 ------> Output0
(with unbound input)
Input ------> Function1 ------> Output1
With those graphs, createStatements will not return any statement for
nodes Function0 and Output0.
Change-Id: Iec32aa51623e176b03ae23e580f06d14df80a194
Reviewed-by: Paul Lemire <paul.lemire@kdab.com>
(cherry picked from commit 7981dbfaf371a368fbd69e935768b310f42a0e5a)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/util/qshadergraph.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/gui/util/qshadergraph.cpp b/src/gui/util/qshadergraph.cpp index 779e63b5c2..45bf6429cd 100644 --- a/src/gui/util/qshadergraph.cpp +++ b/src/gui/util/qshadergraph.cpp @@ -123,6 +123,50 @@ namespace } return targetStatement; } + + void removeNodesWithUnboundInputs(QVector<QShaderGraph::Statement> &statements, + const QVector<QShaderGraph::Edge> &allEdges) + { + // A node is invalid if any of its input ports is disconected + // or connected to the output port of another invalid node. + + // Keeps track of the edges from the nodes we know to be valid + // to unvisited nodes + auto currentEdges = QVector<QShaderGraph::Edge>(); + + statements.erase(std::remove_if(statements.begin(), + statements.end(), + [¤tEdges, &allEdges] (const QShaderGraph::Statement &statement) { + const QShaderNode &node = statement.node; + const QVector<QShaderGraph::Edge> outgoing = outgoingEdges(currentEdges, node.uuid()); + const QVector<QShaderNodePort> ports = node.ports(); + + bool allInputsConnected = true; + for (const QShaderNodePort &port : node.ports()) { + if (port.direction == QShaderNodePort::Output) + continue; + + const auto edgeIt = std::find_if(outgoing.cbegin(), + outgoing.cend(), + [&port] (const QShaderGraph::Edge &edge) { + return edge.targetPortName == port.name; + }); + + if (edgeIt != outgoing.cend()) + currentEdges.removeAll(*edgeIt); + else + allInputsConnected = false; + } + + if (allInputsConnected) { + const QVector<QShaderGraph::Edge> incoming = incomingEdges(allEdges, node.uuid()); + currentEdges.append(incoming); + } + + return !allInputsConnected; + }), + statements.end()); + } } QUuid QShaderGraph::Statement::uuid() const Q_DECL_NOTHROW @@ -248,6 +292,9 @@ QVector<QShaderGraph::Statement> QShaderGraph::createStatements(const QStringLis } std::reverse(result.begin(), result.end()); + + removeNodesWithUnboundInputs(result, enabledEdges); + return result; } |