diff options
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r-- | src/render/materialsystem/qshaderimage.cpp | 25 | ||||
-rw-r--r-- | src/render/materialsystem/qshaderprogrambuilder.cpp | 5 | ||||
-rw-r--r-- | src/render/materialsystem/qshaderprogrambuilder.h | 2 | ||||
-rw-r--r-- | src/render/materialsystem/shader.cpp | 71 | ||||
-rw-r--r-- | src/render/materialsystem/shader_p.h | 26 |
5 files changed, 114 insertions, 15 deletions
diff --git a/src/render/materialsystem/qshaderimage.cpp b/src/render/materialsystem/qshaderimage.cpp index f2ce04c3d..508cf44f2 100644 --- a/src/render/materialsystem/qshaderimage.cpp +++ b/src/render/materialsystem/qshaderimage.cpp @@ -342,7 +342,7 @@ QShaderImagePrivate::~QShaderImagePrivate() */ /*! - \qmlproperty Qt3DRender::QShaderImage::mipLevel + \qmlproperty int Qt3D.Render::ShaderImage::mipLevel Holds which mipLevel out of the referenced texture should be used for the ShaderImage. @@ -351,7 +351,7 @@ QShaderImagePrivate::~QShaderImagePrivate() */ /*! - \qmlproperty Qt3DRender::QShaderImage::layer + \qmlproperty int Qt3D.Render::ShaderImage::layer Holds which layer out of the referenced texture should be used for the ShaderImage. This property does nothing if \a layered is set to true or if @@ -365,11 +365,11 @@ QShaderImagePrivate::~QShaderImagePrivate() cubeMapFace = layer - (cubeMapLayer * 6) \endcode - \default 0 + Default value is 0. */ /*! - * \qmlproperty Qt3DRender::QShaderImage::layered + * \qmlproperty bool Qt3D.Render::ShaderImage::layered If set to true, if the referenced texture is a one-dimensional array, two-dimensional array, three-dimensional, cube map, cube map array, or @@ -377,21 +377,28 @@ QShaderImagePrivate::~QShaderImagePrivate() for all layers. If set to false, only the single layer specified by the \a layer property will be bound. - \default false + Default value is \c false. */ /*! - \qmlproperty Qt3DRender::QShaderImage::access + \qmlproperty enumeration Qt3D.Render::ShaderImage::access Specifies the type of access we want to allow from our shader instances to the image. If a shader tries to write or read from an image that has incompatible access, the behavior is undefined. - \default ShaderImage.ReadWrite + \value ShaderImage.ReadOnly + Read-only access. + \value ShaderImage.WriteOnly + Write-only access. + \value ShaderImage.ReadWrite + Read-write access. + + Default value is ShaderImage.ReadWrite. */ /*! - \qmlproperty Qt3DRender::QShaderImage::format + \qmlproperty enumeration Qt3D.Render::ShaderImage::format Specifies the image format, which is essentially important when storing values in the ShaderImage from a shader. @@ -407,7 +414,7 @@ QShaderImagePrivate::~QShaderImagePrivate() By default Qt3D will try to set the image format to match that of the referenced texture. - \default ShaderImage.Automatic + Default value is ShaderImage.Automatic. */ /*! diff --git a/src/render/materialsystem/qshaderprogrambuilder.cpp b/src/render/materialsystem/qshaderprogrambuilder.cpp index 6613661d1..7f98fbf5e 100644 --- a/src/render/materialsystem/qshaderprogrambuilder.cpp +++ b/src/render/materialsystem/qshaderprogrambuilder.cpp @@ -135,6 +135,11 @@ QShaderProgramBuilder::QShaderProgramBuilder(QShaderProgramBuilderPrivate &dd, Q { } +// TODO Unused remove in Qt6 +void QShaderProgramBuilder::sceneChangeEvent(const Qt3DCore::QSceneChangePtr &) +{ +} + /*! \qmlproperty string ShaderProgramBuilder::shaderProgram diff --git a/src/render/materialsystem/qshaderprogrambuilder.h b/src/render/materialsystem/qshaderprogrambuilder.h index 5dc6b54ff..48e189c8c 100644 --- a/src/render/materialsystem/qshaderprogrambuilder.h +++ b/src/render/materialsystem/qshaderprogrambuilder.h @@ -117,6 +117,8 @@ Q_SIGNALS: protected: explicit QShaderProgramBuilder(QShaderProgramBuilderPrivate &dd, Qt3DCore::QNode *parent = nullptr); + // TODO Unused remove in Qt6 + void sceneChangeEvent(const Qt3DCore::QSceneChangePtr &change) override; private: Q_DECLARE_PRIVATE(QShaderProgramBuilder) diff --git a/src/render/materialsystem/shader.cpp b/src/render/materialsystem/shader.cpp index 58709b37e..0d4b5edba 100644 --- a/src/render/materialsystem/shader.cpp +++ b/src/render/materialsystem/shader.cpp @@ -57,11 +57,35 @@ 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) , m_isLoaded(false) , m_dna(0) + , m_oldDna(0) , m_graphicsContext(nullptr) , m_status(QShaderProgram::NotReady) , m_requiresFrontendSync(false) @@ -243,13 +267,13 @@ void Shader::prepareUniforms(ShaderParameterPack &pack) { const PackUniformHash &values = pack.uniforms(); - auto it = values.cbegin(); - const auto end = values.cend(); + auto it = values.keys.cbegin(); + const auto end = values.keys.cend(); while (it != end) { // Find if there's a uniform with the same name id for (const ShaderUniform &uniform : qAsConst(m_uniforms)) { - if (uniform.m_nameId == it.key()) { + if (uniform.m_nameId == *it) { pack.setSubmissionUniform(uniform); break; } @@ -307,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]); @@ -393,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; |