summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-04-02 15:08:50 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-04-02 15:25:12 +0200
commitf3259300bde381b10cb737735fe19b039c969782 (patch)
tree43c70cfe34cbf08947752653e98ccb777c1c9521 /src/render/materialsystem
parent6f7ac29268df048b5f23ad26c47efcbfdfdb3585 (diff)
parent59d26d3e9411150c7ed0fb0cf68d48988c8dbf59 (diff)
Merge branch '5.12' into 5.13
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r--src/render/materialsystem/qshaderprogram.cpp25
-rw-r--r--src/render/materialsystem/qshaderprogram_p.h3
-rw-r--r--src/render/materialsystem/shaderbuilder.cpp44
3 files changed, 21 insertions, 51 deletions
diff --git a/src/render/materialsystem/qshaderprogram.cpp b/src/render/materialsystem/qshaderprogram.cpp
index 0ca8a9947..c4e14ea2c 100644
--- a/src/render/materialsystem/qshaderprogram.cpp
+++ b/src/render/materialsystem/qshaderprogram.cpp
@@ -635,7 +635,7 @@ QShaderProgram::Status QShaderProgram::status() const
return d->m_status;
}
-static QByteArray deincludify(const QString &filePath)
+QByteArray QShaderProgramPrivate::deincludify(const QString &filePath)
{
QFile f(filePath);
if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
@@ -644,20 +644,27 @@ static QByteArray deincludify(const QString &filePath)
}
QByteArray contents = f.readAll();
+ return deincludify(contents, filePath);
+}
+
+QByteArray QShaderProgramPrivate::deincludify(const QByteArray &contents, const QString &filePath)
+{
QByteArrayList lines = contents.split('\n');
const QByteArray includeDirective = QByteArrayLiteral("#pragma include");
for (int i = 0; i < lines.count(); ++i) {
- if (lines[i].startsWith(includeDirective)) {
- QString includeFileName = QFileInfo(filePath).absolutePath()
- + QLatin1Char('/')
- + QString::fromUtf8(lines[i].mid(includeDirective.count() + 1));
+ const auto line = lines[i].simplified();
+ if (line.startsWith(includeDirective)) {
+ const QString includePartialPath = QString::fromUtf8(line.mid(includeDirective.count() + 1));
+
+ QString includePath = QFileInfo(includePartialPath).isAbsolute() ? includePartialPath
+ : QFileInfo(filePath).absolutePath() + QLatin1Char('/') + includePartialPath;
if (qEnvironmentVariableIsSet("QT3D_GLSL100_WORKAROUND")) {
- QString candidate = includeFileName + QLatin1String("100");
+ QString candidate = includePath + QLatin1String("100");
if (QFile::exists(candidate))
- includeFileName = candidate;
+ includePath = candidate;
}
lines.removeAt(i);
- QByteArray includedContents = deincludify(includeFileName);
+ QByteArray includedContents = deincludify(includePath);
lines.insert(i, includedContents);
QString lineDirective = QString(QStringLiteral("#line %1")).arg(i + 2);
lines.insert(i + 1, lineDirective.toUtf8());
@@ -678,7 +685,7 @@ static QByteArray deincludify(const QString &filePath)
QByteArray QShaderProgram::loadSource(const QUrl &sourceUrl)
{
// TO DO: Handle remote path
- return deincludify(Qt3DRender::QUrlHelper::urlToLocalFileOrQrc(sourceUrl));
+ return QShaderProgramPrivate::deincludify(Qt3DRender::QUrlHelper::urlToLocalFileOrQrc(sourceUrl));
}
Qt3DCore::QNodeCreatedChangeBasePtr QShaderProgram::createNodeCreationChange() const
diff --git a/src/render/materialsystem/qshaderprogram_p.h b/src/render/materialsystem/qshaderprogram_p.h
index 92520c3c8..f09b2a30e 100644
--- a/src/render/materialsystem/qshaderprogram_p.h
+++ b/src/render/materialsystem/qshaderprogram_p.h
@@ -75,6 +75,9 @@ public:
void setLog(const QString &log);
void setStatus(QShaderProgram::Status status);
+
+ static QByteArray deincludify(const QByteArray &contents, const QString &filePath);
+ static QByteArray deincludify(const QString &filePath);
};
struct QShaderProgramData
diff --git a/src/render/materialsystem/shaderbuilder.cpp b/src/render/materialsystem/shaderbuilder.cpp
index e0683332f..c1ec7f75a 100644
--- a/src/render/materialsystem/shaderbuilder.cpp
+++ b/src/render/materialsystem/shaderbuilder.cpp
@@ -41,6 +41,7 @@
#include <Qt3DRender/private/qshaderprogrambuilder_p.h>
#include <Qt3DRender/qshaderprogram.h>
+#include <Qt3DRender/private/qshaderprogram_p.h>
#include <Qt3DRender/private/qurlhelper_p.h>
#include <QtGui/private/qshaderformat_p.h>
@@ -234,47 +235,6 @@ bool ShaderBuilder::isShaderCodeDirty(ShaderBuilder::ShaderType type) const
return m_dirtyTypes.contains(type);
}
-static QByteArray deincludify(const QByteArray &contents, const QString &filePath);
-
-static QByteArray deincludify(const QString &filePath)
-{
- QFile f(filePath);
- if (!f.open(QIODevice::ReadOnly | QIODevice::Text)) {
- qWarning() << "Could not read shader source file:" << f.fileName();
- return QByteArray();
- }
-
- QByteArray contents = f.readAll();
- return deincludify(contents, filePath);
-}
-
-static QByteArray deincludify(const QByteArray &contents, const QString &filePath)
-{
- QByteArrayList lines = contents.split('\n');
- const QByteArray includeDirective = QByteArrayLiteral("#pragma include");
- for (int i = 0; i < lines.count(); ++i) {
- const auto line = lines[i].simplified();
- if (line.startsWith(includeDirective)) {
- const QString includePartialPath = QString::fromUtf8(line.mid(includeDirective.count() + 1));
-
- QString includePath = QFileInfo(includePartialPath).isAbsolute() ? includePartialPath
- : QFileInfo(filePath).absolutePath() + QLatin1Char('/') + includePartialPath;
- if (qEnvironmentVariableIsSet("QT3D_GLSL100_WORKAROUND")) {
- QString candidate = includePath + QLatin1String("100");
- if (QFile::exists(candidate))
- includePath = candidate;
- }
- lines.removeAt(i);
- QByteArray includedContents = deincludify(includePath);
- lines.insert(i, includedContents);
- QString lineDirective = QString(QStringLiteral("#line %1")).arg(i + 2);
- lines.insert(i + 1, lineDirective.toUtf8());
- }
- }
-
- return lines.join('\n');
-}
-
void ShaderBuilder::generateCode(ShaderBuilder::ShaderType type)
{
const auto graphPath = QUrlHelper::urlToLocalFileOrQrc(shaderGraph(type));
@@ -308,7 +268,7 @@ void ShaderBuilder::generateCode(ShaderBuilder::ShaderType type)
generator.graph = graph;
const auto code = generator.createShaderCode(m_enabledLayers);
- m_codes.insert(type, deincludify(code, graphPath + QStringLiteral(".glsl")));
+ m_codes.insert(type, QShaderProgramPrivate::deincludify(code, graphPath + QStringLiteral(".glsl")));
m_dirtyTypes.remove(type);
// Send notification to the frontend