diff options
-rw-r--r-- | src/gui/util/qshadergenerator.cpp | 21 | ||||
-rw-r--r-- | tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp | 13 |
2 files changed, 26 insertions, 8 deletions
diff --git a/src/gui/util/qshadergenerator.cpp b/src/gui/util/qshadergenerator.cpp index 5d6a05e2a0..52bd275cf7 100644 --- a/src/gui/util/qshadergenerator.cpp +++ b/src/gui/util/qshadergenerator.cpp @@ -41,6 +41,22 @@ QT_BEGIN_NAMESPACE +namespace +{ + QByteArray replaceParameters(const QByteArray &original, const QShaderNode &node) + { + auto result = original; + + for (const auto ¶meterName : node.parameterNames()) { + const auto placeholder = QByteArray(QByteArrayLiteral("$") + parameterName.toUtf8()); + const auto value = node.parameter(parameterName).toString().toUtf8(); + result.replace(placeholder, value); + } + + return result; + } +} + QByteArray QShaderGenerator::createShaderCode() const { auto code = QByteArrayList(); @@ -67,7 +83,7 @@ QByteArray QShaderGenerator::createShaderCode() const for (const auto &node : graph.nodes()) { for (const auto &snippet : node.rule(format).headerSnippets) { - code << snippet; + code << replaceParameters(snippet, node); } } @@ -93,7 +109,8 @@ QByteArray QShaderGenerator::createShaderCode() const const auto variable = QByteArray(QByteArrayLiteral("v") + QByteArray::number(variableIndex)); line.replace(placeholder, variable); } - code << QByteArrayLiteral(" ") + line; + + code << QByteArrayLiteral(" ") + replaceParameters(line, node); } code << QByteArrayLiteral("}"); diff --git a/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp b/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp index 655bc94f2c..f64d9458f9 100644 --- a/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp +++ b/tests/auto/gui/util/qshadergenerator/tst_qshadergenerator.cpp @@ -77,12 +77,13 @@ namespace auto graph = QShaderGraph(); auto worldPosition = createNode({ - createPort(QShaderNodePort::Output, "worldPosition") + createPort(QShaderNodePort::Output, "value") }); - worldPosition.addRule(openGLES2, QShaderNode::Rule("highp vec3 $worldPosition = worldPosition;", - QByteArrayList() << "varying highp vec3 worldPosition;")); - worldPosition.addRule(openGL3, QShaderNode::Rule("vec3 $worldPosition = worldPosition;", - QByteArrayList() << "in vec3 worldPosition;")); + worldPosition.setParameter("name", "worldPosition"); + worldPosition.addRule(openGLES2, QShaderNode::Rule("highp vec3 $value = $name;", + QByteArrayList() << "varying highp vec3 $name;")); + worldPosition.addRule(openGL3, QShaderNode::Rule("vec3 $value = $name;", + QByteArrayList() << "in vec3 $name;")); auto texture = createNode({ createPort(QShaderNodePort::Output, "texture") @@ -163,7 +164,7 @@ namespace graph.addEdge(createEdge(texture.uuid(), "texture", sampleTexture.uuid(), "sampler")); graph.addEdge(createEdge(texCoord.uuid(), "texCoord", sampleTexture.uuid(), "coord")); - graph.addEdge(createEdge(worldPosition.uuid(), "worldPosition", lightFunction.uuid(), "position")); + graph.addEdge(createEdge(worldPosition.uuid(), "value", lightFunction.uuid(), "position")); graph.addEdge(createEdge(sampleTexture.uuid(), "color", lightFunction.uuid(), "baseColor")); graph.addEdge(createEdge(lightIntensity.uuid(), "lightIntensity", lightFunction.uuid(), "lightIntensity")); |