summaryrefslogtreecommitdiffstats
path: root/src/gui/util
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-03-29 10:54:43 +0100
committerSean Harmer <sean.harmer@kdab.com>2019-04-10 09:52:50 +0000
commit60181f13a35b05bce664ba5f6cfa7a9d6ae2dc7d (patch)
tree8140cf0425e4608b78516f619fb188720d7e1ba1 /src/gui/util
parent7c74048e94257c5cdc367c3144dc0e26adf06a56 (diff)
QShaderGenerator: fix substitution for attributes on GL2/ES2
GL2/ES2 expect it to be attribute and not in like later versions of OpenGL. Task-number: QTBUG-74829 Change-Id: Iddd22386ed315d6e6843d8225e49a4b73b6ad9ba Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/gui/util')
-rw-r--r--src/gui/util/qshaderformat.cpp17
-rw-r--r--src/gui/util/qshaderformat_p.h13
-rw-r--r--src/gui/util/qshadergenerator.cpp5
-rw-r--r--src/gui/util/qshadernodesloader.cpp11
4 files changed, 44 insertions, 2 deletions
diff --git a/src/gui/util/qshaderformat.cpp b/src/gui/util/qshaderformat.cpp
index 373bfb9e7e..e4e3718199 100644
--- a/src/gui/util/qshaderformat.cpp
+++ b/src/gui/util/qshaderformat.cpp
@@ -43,6 +43,7 @@ QT_BEGIN_NAMESPACE
QShaderFormat::QShaderFormat() Q_DECL_NOTHROW
: m_api(NoApi)
+ , m_shaderType(Fragment)
{
}
@@ -106,6 +107,9 @@ bool QShaderFormat::supports(const QShaderFormat &other) const Q_DECL_NOTHROW
if (m_version < other.m_version)
return false;
+ if (m_shaderType != other.m_shaderType)
+ return false;
+
const auto containsAllExtensionsFromOther = std::includes(m_extensions.constBegin(),
m_extensions.constEnd(),
other.m_extensions.constBegin(),
@@ -119,12 +123,23 @@ bool QShaderFormat::supports(const QShaderFormat &other) const Q_DECL_NOTHROW
return true;
}
+QShaderFormat::ShaderType QShaderFormat::shaderType() const Q_DECL_NOTHROW
+{
+ return m_shaderType;
+}
+
+void QShaderFormat::setShaderType(QShaderFormat::ShaderType shaderType) Q_DECL_NOTHROW
+{
+ m_shaderType = shaderType;
+}
+
bool operator==(const QShaderFormat &lhs, const QShaderFormat &rhs) Q_DECL_NOTHROW
{
return lhs.api() == rhs.api()
&& lhs.version() == rhs.version()
&& lhs.extensions() == rhs.extensions()
- && lhs.vendor() == rhs.vendor();
+ && lhs.vendor() == rhs.vendor()
+ && lhs.shaderType() == rhs.shaderType();
}
QT_END_NAMESPACE
diff --git a/src/gui/util/qshaderformat_p.h b/src/gui/util/qshaderformat_p.h
index 064c2364a7..8d5e83bd22 100644
--- a/src/gui/util/qshaderformat_p.h
+++ b/src/gui/util/qshaderformat_p.h
@@ -69,6 +69,15 @@ public:
OpenGLES
};
+ enum ShaderType : int {
+ Vertex = 0,
+ TessellationControl,
+ TessellationEvaluation,
+ Geometry,
+ Fragment,
+ Compute
+ };
+
Q_GUI_EXPORT QShaderFormat() Q_DECL_NOTHROW;
Q_GUI_EXPORT Api api() const Q_DECL_NOTHROW;
@@ -86,11 +95,15 @@ public:
Q_GUI_EXPORT bool isValid() const Q_DECL_NOTHROW;
Q_GUI_EXPORT bool supports(const QShaderFormat &other) const Q_DECL_NOTHROW;
+ Q_GUI_EXPORT ShaderType shaderType() const Q_DECL_NOTHROW;
+ Q_GUI_EXPORT void setShaderType(ShaderType shaderType) Q_DECL_NOTHROW;
+
private:
Api m_api;
QVersionNumber m_version;
QStringList m_extensions;
QString m_vendor;
+ ShaderType m_shaderType;
};
Q_GUI_EXPORT bool operator==(const QShaderFormat &lhs, const QShaderFormat &rhs) Q_DECL_NOTHROW;
diff --git a/src/gui/util/qshadergenerator.cpp b/src/gui/util/qshadergenerator.cpp
index 60cf5a2fc5..9d2cc387e0 100644
--- a/src/gui/util/qshadergenerator.cpp
+++ b/src/gui/util/qshadergenerator.cpp
@@ -56,7 +56,10 @@ namespace
case QShaderLanguage::Const:
return "const";
case QShaderLanguage::Input:
- return "varying";
+ if (format.shaderType() == QShaderFormat::Vertex)
+ return "attribute";
+ else
+ return "varying";
case QShaderLanguage::Output:
return ""; // Although fragment shaders for <=2 only have fixed outputs
case QShaderLanguage::Uniform:
diff --git a/src/gui/util/qshadernodesloader.cpp b/src/gui/util/qshadernodesloader.cpp
index 9badbb94df..5369e8bd4c 100644
--- a/src/gui/util/qshadernodesloader.cpp
+++ b/src/gui/util/qshadernodesloader.cpp
@@ -251,6 +251,17 @@ void QShaderNodesLoader::load(const QJsonObject &prototypesObject)
break;
}
+ // We default out to a Fragment ShaderType if nothing is specified
+ // as that was the initial behavior we introduced
+ const QString shaderType = formatObject.value(QStringLiteral("shaderType")).toString();
+ format.setShaderType(shaderType == QStringLiteral("Fragment") ? QShaderFormat::Fragment
+ : shaderType == QStringLiteral("Vertex") ? QShaderFormat::Vertex
+ : shaderType == QStringLiteral("TessellationControl") ? QShaderFormat::TessellationControl
+ : shaderType == QStringLiteral("TessellationEvaluation") ? QShaderFormat::TessellationEvaluation
+ : shaderType == QStringLiteral("Geometry") ? QShaderFormat::Geometry
+ : shaderType == QStringLiteral("Compute") ? QShaderFormat::Compute
+ : QShaderFormat::Fragment);
+
const QByteArray substitution = substitutionValue.toString().toUtf8();
const QJsonValue snippetsValue = ruleObject.value(QStringLiteral("headerSnippets"));