diff options
author | Sean Harmer <sean.harmer@kdab.com> | 2018-02-15 12:44:27 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2018-02-15 20:59:03 +0000 |
commit | 6e82860f19bb28744c0d7f6ccc88ca89b187e3ce (patch) | |
tree | 1c8682d5bf06a0a03cefc3da5e3918056de78a04 /src/render/materialsystem | |
parent | 0bbccd492532786adc6816b992b85b4fdf162842 (diff) | |
parent | e1d1a59eb04f8b17582571275073a6cfa10e9e32 (diff) |
Merge remote-tracking branch 'origin/5.10' into 5.11
Conflicts:
src/animation/doc/src/qt3danimation-module.qdoc
src/render/backend/abstractrenderer_p.h
src/render/backend/buffervisitor_p.h
src/render/backend/renderer.cpp
src/render/backend/renderer_p.h
src/render/backend/triangleboundingvolume_p.h
src/render/backend/trianglesextractor_p.h
src/render/frontend/sphere_p.h
src/render/jobs/calcboundingvolumejob.cpp
src/render/jobs/job_common_p.h
src/render/jobs/pickboundingvolumejob.cpp
src/render/jobs/pickboundingvolumejob_p.h
src/render/jobs/pickboundingvolumeutils.cpp
src/render/jobs/renderviewjobutils_p.h
tests/auto/render/boundingsphere/tst_boundingsphere.cpp
tests/auto/render/commons/testrenderer.h
tests/auto/render/raycasting/tst_raycasting.cpp
tests/auto/render/render.pro
tests/auto/render/renderer/tst_renderer.cpp
Change-Id: I76633bc5a5a065e5f9ea62cc16563377e5c693a3
Diffstat (limited to 'src/render/materialsystem')
-rw-r--r-- | src/render/materialsystem/qparameter.cpp | 27 | ||||
-rw-r--r-- | src/render/materialsystem/shadercache.cpp | 18 | ||||
-rw-r--r-- | src/render/materialsystem/shadercache_p.h | 2 | ||||
-rw-r--r-- | src/render/materialsystem/shaderdata.cpp | 10 | ||||
-rw-r--r-- | src/render/materialsystem/shaderdata_p.h | 10 |
5 files changed, 47 insertions, 20 deletions
diff --git a/src/render/materialsystem/qparameter.cpp b/src/render/materialsystem/qparameter.cpp index b9bfa44e7..2b2dd29d5 100644 --- a/src/render/materialsystem/qparameter.cpp +++ b/src/render/materialsystem/qparameter.cpp @@ -179,13 +179,30 @@ QParameterPrivate::QParameterPrivate() { } +namespace { + +/*! \internal */ +inline QVariant toBackendValue(const QVariant &v) +{ + if (auto nodeValue = v.value<Qt3DCore::QNode*>()) + return QVariant::fromValue(nodeValue->id()); + return v; +} + +} // anonymous + void QParameterPrivate::setValue(const QVariant &v) { - Qt3DCore::QNode *nodeValue = v.value<Qt3DCore::QNode *>(); - if (nodeValue != nullptr) - m_backendValue = QVariant::fromValue(nodeValue->id()); - else - m_backendValue = v; + if (v.type() == QVariant::List) { + QSequentialIterable iterable = v.value<QSequentialIterable>(); + QVariantList variants; + variants.reserve(iterable.size()); + for (const auto &v : iterable) + variants.append(toBackendValue(v)); + m_backendValue = variants; + } else { + m_backendValue = toBackendValue(v); + } m_value = v; } diff --git a/src/render/materialsystem/shadercache.cpp b/src/render/materialsystem/shadercache.cpp index 4ddf26799..ce29622ad 100644 --- a/src/render/materialsystem/shadercache.cpp +++ b/src/render/materialsystem/shadercache.cpp @@ -62,18 +62,28 @@ ShaderCache::~ShaderCache() * * \return A pointer to the shader program if it is cached, nullptr otherwise */ -QOpenGLShaderProgram *ShaderCache::getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId) +QOpenGLShaderProgram *ShaderCache::getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, bool *wasPresent) { - auto shaderProgram = m_programHash.value(dna, nullptr); - if (shaderProgram) { + auto shaderProgram = m_programHash.constFind(dna); + + // Some callers may wish to differentiate between a result of null due to + // not having anything in the cache and a result of null due to the cache + // containing a program the shaders of which failed to compile. + if (wasPresent) + *wasPresent = shaderProgram != m_programHash.constEnd(); + + if (shaderProgram != m_programHash.constEnd()) { // Ensure we store the fact that shaderPeerId references this shader QMutexLocker lock(&m_refsMutex); QVector<Qt3DCore::QNodeId> &programRefs = m_programRefs[dna]; auto it = std::lower_bound(programRefs.begin(), programRefs.end(), shaderPeerId); if (*it != shaderPeerId) programRefs.insert(it, shaderPeerId); + + return *shaderProgram; } - return shaderProgram; + + return nullptr; } /*! diff --git a/src/render/materialsystem/shadercache_p.h b/src/render/materialsystem/shadercache_p.h index 24a55876e..bda629ee5 100644 --- a/src/render/materialsystem/shadercache_p.h +++ b/src/render/materialsystem/shadercache_p.h @@ -71,7 +71,7 @@ class QT3DRENDERSHARED_PRIVATE_EXPORT ShaderCache public: ~ShaderCache(); - QOpenGLShaderProgram *getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId); + QOpenGLShaderProgram *getShaderProgramAndAddRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, bool *wasPresent = nullptr); void insert(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId, QOpenGLShaderProgram *program); void removeRef(ProgramDNA dna, Qt3DCore::QNodeId shaderPeerId); void purge(); diff --git a/src/render/materialsystem/shaderdata.cpp b/src/render/materialsystem/shaderdata.cpp index fec1e66ac..de423c3c2 100644 --- a/src/render/materialsystem/shaderdata.cpp +++ b/src/render/materialsystem/shaderdata.cpp @@ -171,7 +171,7 @@ void ShaderData::cleanup(NodeManagers *managers) m_updatedShaderData.clear(); } -QVariant ShaderData::getTransformedProperty(const QString &name, const QMatrix4x4 &viewMatrix) +QVariant ShaderData::getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix) { // Note protecting m_worldMatrix at this point as we assume all world updates // have been performed when reaching this point @@ -180,11 +180,11 @@ QVariant ShaderData::getTransformedProperty(const QString &name, const QMatrix4x const TransformType transformType = it.value(); switch (transformType) { case ModelToEye: - return QVariant::fromValue(viewMatrix * m_worldMatrix * m_originalProperties.value(name).value<QVector3D>()); + return QVariant::fromValue(viewMatrix * m_worldMatrix * Vector3D(m_originalProperties.value(name).value<QVector3D>())); case ModelToWorld: - return QVariant::fromValue(m_worldMatrix * m_originalProperties.value(it.key()).value<QVector3D>()); + return QVariant::fromValue(m_worldMatrix * Vector3D(m_originalProperties.value(it.key()).value<QVector3D>())); case ModelToWorldDirection: - return QVariant::fromValue((m_worldMatrix * QVector4D(m_originalProperties.value(it.key()).value<QVector3D>(), 0.0f)).toVector3D()); + return QVariant::fromValue(Vector3D(m_worldMatrix * Vector4D(m_originalProperties.value(it.key()).value<QVector3D>(), 0.0f))); case NoTransform: break; } @@ -193,7 +193,7 @@ QVariant ShaderData::getTransformedProperty(const QString &name, const QMatrix4x } // Called by FramePreparationJob or by RenderView when dealing with lights -void ShaderData::updateWorldTransform(const QMatrix4x4 &worldMatrix) +void ShaderData::updateWorldTransform(const Matrix4x4 &worldMatrix) { QMutexLocker lock(&m_mutex); if (m_worldMatrix != worldMatrix) { diff --git a/src/render/materialsystem/shaderdata_p.h b/src/render/materialsystem/shaderdata_p.h index 168335f63..f9c3ecc79 100644 --- a/src/render/materialsystem/shaderdata_p.h +++ b/src/render/materialsystem/shaderdata_p.h @@ -55,7 +55,7 @@ #include <Qt3DRender/private/shadervariables_p.h> #include <Qt3DRender/qshaderdata.h> #include <QMutex> -#include <QMatrix4x4> +#include <Qt3DCore/private/matrix4x4_p.h> QT_BEGIN_NAMESPACE @@ -83,13 +83,13 @@ public: QHash<QString, QVariant> properties() const { return m_originalProperties; } // Called by FramePreparationJob - void updateWorldTransform(const QMatrix4x4 &worldMatrix); + void updateWorldTransform(const Matrix4x4 &worldMatrix); // Call by RenderViewJob void markDirty(); TransformType propertyTransformType(const QString &name) const; - QVariant getTransformedProperty(const QString &name, const QMatrix4x4 &viewMatrix); + QVariant getTransformedProperty(const QString &name, const Matrix4x4 &viewMatrix); // Called by FrameCleanupJob static void cleanup(NodeManagers *managers); @@ -114,8 +114,8 @@ protected: QMutex m_mutex; static QVector<Qt3DCore::QNodeId> m_updatedShaderData; - QMatrix4x4 m_worldMatrix; - QMatrix4x4 m_viewMatrix; + Matrix4x4 m_worldMatrix; + Matrix4x4 m_viewMatrix; NodeManagers *m_managers; void clearUpdatedProperties(); |