diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 14:51:40 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2019-07-11 17:24:39 +0200 |
commit | 13374ceb165c44658aa97890c37b206859c9a31c (patch) | |
tree | 562362b196a459ee3449a5a1e60e5216a9dd6984 /src/quick/scenegraph/util/qsgflatcolormaterial.cpp | |
parent | ae47deba4c943c496412530a8d2a5a688ae12038 (diff) | |
parent | b5d18be5a03406d0aac83856dd41e1525fd14a28 (diff) |
Merge remote-tracking branch 'origin/wip/qt6' into wip/cmake
Change-Id: I2963c1209316fb6755f572969f368970450d7991
Diffstat (limited to 'src/quick/scenegraph/util/qsgflatcolormaterial.cpp')
-rw-r--r-- | src/quick/scenegraph/util/qsgflatcolormaterial.cpp | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp index 28f6113a60..f121d2a9e2 100644 --- a/src/quick/scenegraph/util/qsgflatcolormaterial.cpp +++ b/src/quick/scenegraph/util/qsgflatcolormaterial.cpp @@ -116,6 +116,51 @@ void FlatColorMaterialShader::initialize() } +class FlatColorMaterialRhiShader : public QSGMaterialRhiShader +{ +public: + FlatColorMaterialRhiShader(); + + bool updateUniformData(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; +}; + +FlatColorMaterialRhiShader::FlatColorMaterialRhiShader() +{ + setShaderFileName(VertexStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.vert.qsb")); + setShaderFileName(FragmentStage, QStringLiteral(":/qt-project.org/scenegraph/shaders_ng/flatcolor.frag.qsb")); +} + +bool FlatColorMaterialRhiShader::updateUniformData(const RenderState &state, + QSGMaterial *newMaterial, + QSGMaterial *oldMaterial) +{ + Q_ASSERT(!oldMaterial || newMaterial->type() == oldMaterial->type()); + QSGFlatColorMaterial *oldMat = static_cast<QSGFlatColorMaterial *>(oldMaterial); + QSGFlatColorMaterial *mat = static_cast<QSGFlatColorMaterial *>(newMaterial); + bool changed = false; + QByteArray *buf = state.uniformData(); + + if (state.isMatrixDirty()) { + const QMatrix4x4 m = state.combinedMatrix(); + memcpy(buf->data(), m.constData(), 64); + changed = true; + } + + const QColor &c = mat->color(); + if (!oldMat || c != oldMat->color() || state.isOpacityDirty()) { + const float opacity = state.opacity() * c.alphaF(); + QVector4D v(c.redF() * opacity, + c.greenF() * opacity, + c.blueF() * opacity, + opacity); + Q_ASSERT(sizeof(v) == 16); + memcpy(buf->data() + 64, &v, 16); + changed = true; + } + + return changed; +} + /*! \class QSGFlatColorMaterial @@ -126,7 +171,7 @@ void FlatColorMaterialShader::initialize() \inmodule QtQuick \ingroup qtquick-scenegraph-materials - \warning This utility class is only functional when running with the OpenGL + \warning This utility class is only functional when running with the default backend of the Qt Quick scenegraph. The flat color material will fill every pixel in a geometry using @@ -150,10 +195,9 @@ void FlatColorMaterialShader::initialize() QSGFlatColorMaterial::QSGFlatColorMaterial() : m_color(QColor(255, 255, 255)) { + setFlag(SupportsRhiShader, true); } - - /*! \fn const QColor &QSGFlatColorMaterial::color() const @@ -193,7 +237,10 @@ QSGMaterialType *QSGFlatColorMaterial::type() const QSGMaterialShader *QSGFlatColorMaterial::createShader() const { - return new FlatColorMaterialShader; + if (flags().testFlag(RhiShaderWanted)) + return new FlatColorMaterialRhiShader; + else + return new FlatColorMaterialShader; } |