summaryrefslogtreecommitdiffstats
path: root/src/render/materialsystem
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-12-07 03:03:08 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2019-12-07 03:03:09 +0100
commit4505f5acbc346a0cea6ccf5e7d02c75c6e3ca4cb (patch)
treeeeee8e91d896bd35cce2fe8d3051862e40585f44 /src/render/materialsystem
parent3d1063fce2ada72d740f5f7c7888533da8794753 (diff)
parent3019497559328d2fd0c0c9548f512fba9fe1f94e (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r--src/render/materialsystem/shader.cpp64
-rw-r--r--src/render/materialsystem/shader_p.h26
2 files changed, 87 insertions, 3 deletions
diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp
index 300a71b84..0d4b5edba 100644
--- a/src/render/materialsystem/shader.cpp
+++ b/src/render/materialsystem/shader.cpp
@@ -57,6 +57,29 @@ using namespace Qt3DCore;
namespace Qt3DRender {
namespace Render {
+const int Shader::modelMatrixNameId = StringToInt::lookupId(QLatin1String("modelMatrix"));
+const int Shader::viewMatrixNameId = StringToInt::lookupId(QLatin1String("viewMatrix"));
+const int Shader::projectionMatrixNameId = StringToInt::lookupId(QLatin1String("projectionMatrix"));
+const int Shader::modelViewMatrixNameId = StringToInt::lookupId(QLatin1String("modelView"));
+const int Shader::viewProjectionMatrixNameId = StringToInt::lookupId(QLatin1String("viewProjectionMatrix"));
+const int Shader::modelViewProjectionNameId = StringToInt::lookupId(QLatin1String("modelViewProjection"));
+const int Shader::mvpNameId = StringToInt::lookupId(QLatin1String("mvp"));
+const int Shader::inverseModelMatrixNameId = StringToInt::lookupId(QLatin1String("inverseModelMatrix"));
+const int Shader::inverseViewMatrixNameId = StringToInt::lookupId(QLatin1String("inverseViewMatrix"));
+const int Shader::inverseProjectionMatrixNameId = StringToInt::lookupId(QLatin1String("inverseProjectionMatrix"));
+const int Shader::inverseModelViewNameId = StringToInt::lookupId(QLatin1String("inverseModelView"));
+const int Shader::inverseViewProjectionMatrixNameId = StringToInt::lookupId(QLatin1String("inverseViewProjectionMatrix"));
+const int Shader::inverseModelViewProjectionNameId = StringToInt::lookupId(QLatin1String("inverseModelViewProjection"));
+const int Shader::modelNormalMatrixNameId = StringToInt::lookupId(QLatin1String("modelNormalMatrix"));
+const int Shader::modelViewNormalNameId = StringToInt::lookupId(QLatin1String("modelViewNormal"));
+const int Shader::viewportMatrixNameId = StringToInt::lookupId(QLatin1String("viewportMatrix"));
+const int Shader::inverseViewportMatrixNameId = StringToInt::lookupId(QLatin1String("inverseViewportMatrix"));
+const int Shader::aspectRatioNameId = StringToInt::lookupId(QLatin1String("aspectRatio"));
+const int Shader::exposureNameId = StringToInt::lookupId(QLatin1String("exposure"));
+const int Shader::gammaNameId = StringToInt::lookupId(QLatin1String("gamma"));
+const int Shader::timeNameId = StringToInt::lookupId(QLatin1String("time"));
+const int Shader::eyePositionNameId = StringToInt::lookupId(QLatin1String("eyePosition"));
+const int Shader::skinningPaletteNameId = StringToInt::lookupId(QLatin1String("skinningPalette[0]"));
Shader::Shader()
: BackendNode(ReadWrite)
@@ -308,13 +331,47 @@ void Shader::initializeUniforms(const QVector<ShaderUniform> &uniformsDescriptio
{
m_uniforms = uniformsDescription;
m_uniformsNames.resize(uniformsDescription.size());
- m_uniformsNamesIds.resize(uniformsDescription.size());
+ m_uniformsNamesIds.reserve(uniformsDescription.size());
+ m_standardUniformNamesIds.reserve(5);
QHash<QString, ShaderUniform> activeUniformsInDefaultBlock;
+ static const QVector<int> standardUniformNameIds = {
+ modelMatrixNameId,
+ viewMatrixNameId,
+ projectionMatrixNameId,
+ modelViewMatrixNameId,
+ viewProjectionMatrixNameId,
+ modelViewProjectionNameId,
+ mvpNameId,
+ inverseModelMatrixNameId,
+ inverseViewMatrixNameId,
+ inverseProjectionMatrixNameId,
+ inverseModelViewNameId,
+ inverseViewProjectionMatrixNameId,
+ inverseModelViewProjectionNameId,
+ modelNormalMatrixNameId,
+ modelViewNormalNameId,
+ viewportMatrixNameId,
+ inverseViewportMatrixNameId,
+ aspectRatioNameId,
+ exposureNameId,
+ gammaNameId,
+ timeNameId,
+ eyePositionNameId,
+ skinningPaletteNameId,
+ };
+
for (int i = 0, m = uniformsDescription.size(); i < m; i++) {
m_uniformsNames[i] = m_uniforms[i].m_name;
- m_uniforms[i].m_nameId = StringToInt::lookupId(m_uniformsNames[i]);
- m_uniformsNamesIds[i] = m_uniforms[i].m_nameId;
+ const int nameId = StringToInt::lookupId(m_uniformsNames[i]);
+ m_uniforms[i].m_nameId = nameId;
+
+ // Is the uniform a Qt3D "Standard" uniform or a user defined one?
+ if (standardUniformNameIds.contains(nameId))
+ m_standardUniformNamesIds.push_back(nameId);
+ else
+ m_uniformsNamesIds.push_back(nameId);
+
if (uniformsDescription[i].m_blockIndex == -1) { // Uniform is in default block
qCDebug(Shaders) << "Active Uniform in Default Block " << uniformsDescription[i].m_name << uniformsDescription[i].m_blockIndex;
activeUniformsInDefaultBlock.insert(uniformsDescription[i].m_name, uniformsDescription[i]);
@@ -394,6 +451,7 @@ void Shader::initializeFromReference(const Shader &other)
{
Q_ASSERT(m_dna == other.m_dna);
m_uniformsNamesIds = other.m_uniformsNamesIds;
+ m_standardUniformNamesIds = other.m_standardUniformNamesIds;
m_uniformsNames = other.m_uniformsNames;
m_uniforms = other.m_uniforms;
m_attributesNames = other.m_attributesNames;
diff --git a/src/render/materialsystem/shader_p.h b/src/render/materialsystem/shader_p.h
index 1c9731e50..4c5bc5ea1 100644
--- a/src/render/materialsystem/shader_p.h
+++ b/src/render/materialsystem/shader_p.h
@@ -75,6 +75,30 @@ typedef uint ProgramDNA;
class Q_AUTOTEST_EXPORT Shader : public BackendNode
{
public:
+ static const int modelMatrixNameId;
+ static const int viewMatrixNameId;
+ static const int projectionMatrixNameId;
+ static const int modelViewMatrixNameId;
+ static const int viewProjectionMatrixNameId;
+ static const int modelViewProjectionNameId;
+ static const int mvpNameId;
+ static const int inverseModelMatrixNameId;
+ static const int inverseViewMatrixNameId;
+ static const int inverseProjectionMatrixNameId;
+ static const int inverseModelViewNameId;
+ static const int inverseViewProjectionMatrixNameId;
+ static const int inverseModelViewProjectionNameId;
+ static const int modelNormalMatrixNameId;
+ static const int modelViewNormalNameId;
+ static const int viewportMatrixNameId;
+ static const int inverseViewportMatrixNameId;
+ static const int aspectRatioNameId;
+ static const int exposureNameId;
+ static const int gammaNameId;
+ static const int timeNameId;
+ static const int eyePositionNameId;
+ static const int skinningPaletteNameId;
+
Shader();
~Shader();
@@ -88,6 +112,7 @@ public:
const QHash<QString, int> fragOutputs() const;
inline QVector<int> uniformsNamesIds() const { return m_uniformsNamesIds; }
+ inline QVector<int> standardUniformNameIds() const { return m_standardUniformNamesIds; }
inline QVector<int> uniformBlockNamesIds() const { return m_uniformBlockNamesIds; }
inline QVector<int> storageBlockNamesIds() const { return m_shaderStorageBlockNamesIds; }
inline QVector<int> attributeNamesIds() const { return m_attributeNamesIds; }
@@ -128,6 +153,7 @@ public:
private:
QVector<QString> m_uniformsNames;
QVector<int> m_uniformsNamesIds;
+ QVector<int> m_standardUniformNamesIds;
QVector<ShaderUniform> m_uniforms;
QVector<QString> m_attributesNames;