diff options
Diffstat (limited to 'src/particles/qquickimageparticle.cpp')
-rw-r--r-- | src/particles/qquickimageparticle.cpp | 252 |
1 files changed, 125 insertions, 127 deletions
diff --git a/src/particles/qquickimageparticle.cpp b/src/particles/qquickimageparticle.cpp index 884edc3390..855726c20a 100644 --- a/src/particles/qquickimageparticle.cpp +++ b/src/particles/qquickimageparticle.cpp @@ -1,41 +1,7 @@ -/**************************************************************************** -** -** Copyright (C) 2019 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtQuick module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include <QtQuick/private/qsgcontext_p.h> #include <private/qsgadaptationlayer_p.h> @@ -52,16 +18,16 @@ #include <QtQuick/private/qsgplaintexture_p.h> #include <private/qqmlglobal_p.h> #include <QtQml/qqmlinfo.h> +#include <QtCore/QtMath> +#include <rhi/qrhi.h> + #include <cmath> -#include <QtGui/private/qrhi_p.h> QT_BEGIN_NAMESPACE // Must match the shader code #define UNIFORM_ARRAY_SIZE 64 -const qreal CONV = 0.017453292519943295; - class ImageMaterialData { public: @@ -88,41 +54,45 @@ class ImageMaterialData class TabledMaterialRhiShader : public QSGMaterialShader { public: - TabledMaterialRhiShader() + TabledMaterialRhiShader(int viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_tabled.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_tabled.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_tabled.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_tabled.frag.qsb"), viewCount); } bool updateUniformData(RenderState &renderState, QSGMaterial *newMaterial, QSGMaterial *) override { QByteArray *buf = renderState.uniformData(); Q_ASSERT(buf->size() >= 80 + 2 * (UNIFORM_ARRAY_SIZE * 4 * 4)); + const int shaderMatrixCount = newMaterial->viewCount(); + const int matrixCount = qMin(renderState.projectionMatrixCount(), shaderMatrixCount); - if (renderState.isMatrixDirty()) { - const QMatrix4x4 m = renderState.combinedMatrix(); - memcpy(buf->data(), m.constData(), 64); + for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) { + if (renderState.isMatrixDirty()) { + const QMatrix4x4 m = renderState.combinedMatrix(viewIndex); + memcpy(buf->data() + 64 * viewIndex, m.constData(), 64); + } } if (renderState.isOpacityDirty()) { const float opacity = renderState.opacity(); - memcpy(buf->data() + 64, &opacity, 4); + memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4); } ImageMaterialData *state = static_cast<ImageMaterial *>(newMaterial)->state(); float entry = float(state->entry); - memcpy(buf->data() + 68, &entry, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 4, &entry, 4); float timestamp = float(state->timestamp); - memcpy(buf->data() + 72, ×tamp, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 8, ×tamp, 4); - float *p = reinterpret_cast<float *>(buf->data() + 80); + float *p = reinterpret_cast<float *>(buf->data() + 64 * shaderMatrixCount + 16); for (int i = 0; i < UNIFORM_ARRAY_SIZE; ++i) { *p = state->sizeTable[i]; p += 4; } - p = reinterpret_cast<float *>(buf->data() + 80 + (UNIFORM_ARRAY_SIZE * 4 * 4)); + p = reinterpret_cast<float *>(buf->data() + 64 * shaderMatrixCount + 16 + (UNIFORM_ARRAY_SIZE * 4 * 4)); for (int i = 0; i < UNIFORM_ARRAY_SIZE; ++i) { *p = state->opacityTable[i]; p += 4; @@ -150,7 +120,7 @@ class TabledMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new TabledMaterialRhiShader; + return new TabledMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -166,34 +136,38 @@ QSGMaterialType TabledMaterial::m_type; class DeformableMaterialRhiShader : public QSGMaterialShader { public: - DeformableMaterialRhiShader() + DeformableMaterialRhiShader(int viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_deformed.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_deformed.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_deformed.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_deformed.frag.qsb"), viewCount); } bool updateUniformData(RenderState &renderState, QSGMaterial *newMaterial, QSGMaterial *) override { QByteArray *buf = renderState.uniformData(); Q_ASSERT(buf->size() >= 80 + 2 * (UNIFORM_ARRAY_SIZE * 4 * 4)); + const int shaderMatrixCount = newMaterial->viewCount(); + const int matrixCount = qMin(renderState.projectionMatrixCount(), shaderMatrixCount); - if (renderState.isMatrixDirty()) { - const QMatrix4x4 m = renderState.combinedMatrix(); - memcpy(buf->data(), m.constData(), 64); + for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) { + if (renderState.isMatrixDirty()) { + const QMatrix4x4 m = renderState.combinedMatrix(viewIndex); + memcpy(buf->data() + 64 * viewIndex, m.constData(), 64); + } } if (renderState.isOpacityDirty()) { const float opacity = renderState.opacity(); - memcpy(buf->data() + 64, &opacity, 4); + memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4); } ImageMaterialData *state = static_cast<ImageMaterial *>(newMaterial)->state(); float entry = float(state->entry); - memcpy(buf->data() + 68, &entry, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 4, &entry, 4); float timestamp = float(state->timestamp); - memcpy(buf->data() + 72, ×tamp, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 8, ×tamp, 4); return true; } @@ -214,7 +188,7 @@ class DeformableMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new DeformableMaterialRhiShader; + return new DeformableMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -230,41 +204,45 @@ QSGMaterialType DeformableMaterial::m_type; class ParticleSpriteMaterialRhiShader : public QSGMaterialShader { public: - ParticleSpriteMaterialRhiShader() + ParticleSpriteMaterialRhiShader(int viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_sprite.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_sprite.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_sprite.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_sprite.frag.qsb"), viewCount); } bool updateUniformData(RenderState &renderState, QSGMaterial *newMaterial, QSGMaterial *) override { QByteArray *buf = renderState.uniformData(); Q_ASSERT(buf->size() >= 80 + 2 * (UNIFORM_ARRAY_SIZE * 4 * 4)); + const int shaderMatrixCount = newMaterial->viewCount(); + const int matrixCount = qMin(renderState.projectionMatrixCount(), shaderMatrixCount); - if (renderState.isMatrixDirty()) { - const QMatrix4x4 m = renderState.combinedMatrix(); - memcpy(buf->data(), m.constData(), 64); + for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) { + if (renderState.isMatrixDirty()) { + const QMatrix4x4 m = renderState.combinedMatrix(viewIndex); + memcpy(buf->data() + 64 * viewIndex, m.constData(), 64); + } } if (renderState.isOpacityDirty()) { const float opacity = renderState.opacity(); - memcpy(buf->data() + 64, &opacity, 4); + memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4); } ImageMaterialData *state = static_cast<ImageMaterial *>(newMaterial)->state(); float entry = float(state->entry); - memcpy(buf->data() + 68, &entry, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 4, &entry, 4); float timestamp = float(state->timestamp); - memcpy(buf->data() + 72, ×tamp, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 8, ×tamp, 4); - float *p = reinterpret_cast<float *>(buf->data() + 80); + float *p = reinterpret_cast<float *>(buf->data() + 64 * shaderMatrixCount + 16); for (int i = 0; i < UNIFORM_ARRAY_SIZE; ++i) { *p = state->sizeTable[i]; p += 4; } - p = reinterpret_cast<float *>(buf->data() + 80 + (UNIFORM_ARRAY_SIZE * 4 * 4)); + p = reinterpret_cast<float *>(buf->data() + 64 * shaderMatrixCount + 16 + (UNIFORM_ARRAY_SIZE * 4 * 4)); for (int i = 0; i < UNIFORM_ARRAY_SIZE; ++i) { *p = state->opacityTable[i]; p += 4; @@ -292,7 +270,7 @@ class SpriteMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new ParticleSpriteMaterialRhiShader; + return new ParticleSpriteMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -308,37 +286,41 @@ QSGMaterialType SpriteMaterial::m_type; class ColoredPointMaterialRhiShader : public QSGMaterialShader { public: - ColoredPointMaterialRhiShader() + ColoredPointMaterialRhiShader(int viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_coloredpoint.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_coloredpoint.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_coloredpoint.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_coloredpoint.frag.qsb"), viewCount); } bool updateUniformData(RenderState &renderState, QSGMaterial *newMaterial, QSGMaterial *) override { QByteArray *buf = renderState.uniformData(); Q_ASSERT(buf->size() >= 80 + 2 * (UNIFORM_ARRAY_SIZE * 4 * 4)); + const int shaderMatrixCount = newMaterial->viewCount(); + const int matrixCount = qMin(renderState.projectionMatrixCount(), shaderMatrixCount); - if (renderState.isMatrixDirty()) { - const QMatrix4x4 m = renderState.combinedMatrix(); - memcpy(buf->data(), m.constData(), 64); + for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) { + if (renderState.isMatrixDirty()) { + const QMatrix4x4 m = renderState.combinedMatrix(viewIndex); + memcpy(buf->data() + 64 * viewIndex, m.constData(), 64); + } } if (renderState.isOpacityDirty()) { const float opacity = renderState.opacity(); - memcpy(buf->data() + 64, &opacity, 4); + memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4); } ImageMaterialData *state = static_cast<ImageMaterial *>(newMaterial)->state(); float entry = float(state->entry); - memcpy(buf->data() + 68, &entry, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 4, &entry, 4); float timestamp = float(state->timestamp); - memcpy(buf->data() + 72, ×tamp, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 8, ×tamp, 4); float dpr = float(state->dpr); - memcpy(buf->data() + 76, &dpr, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 12, &dpr, 4); return true; } @@ -359,7 +341,7 @@ class ColoredPointMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new ColoredPointMaterialRhiShader; + return new ColoredPointMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -375,10 +357,11 @@ QSGMaterialType ColoredPointMaterial::m_type; class ColoredMaterialRhiShader : public ColoredPointMaterialRhiShader { public: - ColoredMaterialRhiShader() + ColoredMaterialRhiShader(int viewCount) + : ColoredPointMaterialRhiShader(viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_colored.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_colored.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_colored.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_colored.frag.qsb"), viewCount); } }; @@ -387,7 +370,7 @@ class ColoredMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new ColoredMaterialRhiShader; + return new ColoredMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -403,37 +386,41 @@ QSGMaterialType ColoredMaterial::m_type; class SimplePointMaterialRhiShader : public QSGMaterialShader { public: - SimplePointMaterialRhiShader() + SimplePointMaterialRhiShader(int viewCount) { - setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_simplepoint.vert.qsb")); - setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_simplepoint.frag.qsb")); + setShaderFileName(VertexStage, QStringLiteral(":/particles/shaders_ng/imageparticle_simplepoint.vert.qsb"), viewCount); + setShaderFileName(FragmentStage, QStringLiteral(":/particles/shaders_ng/imageparticle_simplepoint.frag.qsb"), viewCount); } bool updateUniformData(RenderState &renderState, QSGMaterial *newMaterial, QSGMaterial *) override { QByteArray *buf = renderState.uniformData(); Q_ASSERT(buf->size() >= 80 + 2 * (UNIFORM_ARRAY_SIZE * 4 * 4)); + const int shaderMatrixCount = newMaterial->viewCount(); + const int matrixCount = qMin(renderState.projectionMatrixCount(), shaderMatrixCount); - if (renderState.isMatrixDirty()) { - const QMatrix4x4 m = renderState.combinedMatrix(); - memcpy(buf->data(), m.constData(), 64); + for (int viewIndex = 0; viewIndex < matrixCount; ++viewIndex) { + if (renderState.isMatrixDirty()) { + const QMatrix4x4 m = renderState.combinedMatrix(viewIndex); + memcpy(buf->data() + 64 * viewIndex, m.constData(), 64); + } } if (renderState.isOpacityDirty()) { const float opacity = renderState.opacity(); - memcpy(buf->data() + 64, &opacity, 4); + memcpy(buf->data() + 64 * shaderMatrixCount, &opacity, 4); } ImageMaterialData *state = static_cast<ImageMaterial *>(newMaterial)->state(); float entry = float(state->entry); - memcpy(buf->data() + 68, &entry, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 4, &entry, 4); float timestamp = float(state->timestamp); - memcpy(buf->data() + 72, ×tamp, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 8, ×tamp, 4); float dpr = float(state->dpr); - memcpy(buf->data() + 76, &dpr, 4); + memcpy(buf->data() + 64 * shaderMatrixCount + 12, &dpr, 4); return true; } @@ -454,7 +441,7 @@ class SimplePointMaterial : public ImageMaterial public: QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override { Q_UNUSED(renderMode); - return new SimplePointMaterialRhiShader; + return new SimplePointMaterialRhiShader(viewCount()); } QSGMaterialType *type() const override { return &m_type; } @@ -687,13 +674,12 @@ void fillUniformArrayFromImage(float* array, const QImage& img, int size) For fine-grained control, see sizeTable and opacityTable. Acceptable values are - \list - \li ImageParticle.None: Particles just appear and disappear. - \li ImageParticle.Fade: Particles fade in from 0 opacity at the start of their life, and fade out to 0 at the end. - \li ImageParticle.Scale: Particles scale in from 0 size at the start of their life, and scale back to 0 at the end. - \endlist - Default value is Fade. + \value ImageParticle.None Particles just appear and disappear. + \value ImageParticle.Fade Particles fade in from 0 opacity at the start of their life, and fade out to 0 at the end. + \value ImageParticle.Scale Particles scale in from 0 size at the start of their life, and scale back to 0 at the end. + + The default value is \c ImageParticle.Fade. */ /*! \qmlproperty bool QtQuick.Particles::ImageParticle::spritesInterpolate @@ -766,6 +752,7 @@ void QQuickImageParticle::sceneGraphInvalidated() m_material = nullptr; delete m_outgoingNode; m_outgoingNode = nullptr; + m_apiChecked = false; } void QQuickImageParticle::setImage(const QUrl &image) @@ -1017,7 +1004,7 @@ void QQuickImageParticle::resetColor() { m_explicitColor = false; for (auto groupId : groupIds()) { - for (QQuickParticleData* d : qAsConst(m_system->groupData[groupId]->data)) { + for (QQuickParticleData* d : std::as_const(m_system->groupData[groupId]->data)) { if (d->colorOwner == this) { d->colorOwner = nullptr; } @@ -1036,7 +1023,7 @@ void QQuickImageParticle::resetRotation() { m_explicitRotation = false; for (auto groupId : groupIds()) { - for (QQuickParticleData* d : qAsConst(m_system->groupData[groupId]->data)) { + for (QQuickParticleData* d : std::as_const(m_system->groupData[groupId]->data)) { if (d->rotationOwner == this) { d->rotationOwner = nullptr; } @@ -1053,7 +1040,7 @@ void QQuickImageParticle::resetDeformation() { m_explicitDeformation = false; for (auto groupId : groupIds()) { - for (QQuickParticleData* d : qAsConst(m_system->groupData[groupId]->data)) { + for (QQuickParticleData* d : std::as_const(m_system->groupData[groupId]->data)) { if (d->deformationOwner == this) { d->deformationOwner = nullptr; } @@ -1074,14 +1061,20 @@ void QQuickImageParticle::reset() update(); } + +void QQuickImageParticle::invalidateSceneGraph() +{ + reset(); +} + void QQuickImageParticle::createEngine() { if (m_spriteEngine) delete m_spriteEngine; - if (m_sprites.count()) { + if (m_sprites.size()) { m_spriteEngine = new QQuickSpriteEngine(m_sprites, this); - connect(m_spriteEngine, SIGNAL(stateChanged(int)), - this, SLOT(spriteAdvance(int)), Qt::DirectConnection); + connect(m_spriteEngine, &QQuickStochasticEngine::stateChanged, + this, &QQuickImageParticle::spriteAdvance, Qt::DirectConnection); m_explicitAnimation = true; } else { m_spriteEngine = nullptr; @@ -1280,7 +1273,7 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node) m_debugMode = m_system->m_debugMode; - if (m_sprites.count() || m_bypassOptimizations) { + if (m_sprites.size() || m_bypassOptimizations) { perfLevel = Sprites; } else if (m_colorTable || m_sizeTable || m_opacityTable) { perfLevel = Tabled; @@ -1297,7 +1290,7 @@ void QQuickImageParticle::finishBuildParticleNodes(QSGNode** node) for (auto groupId : groupIds()) { //For sharing higher levels, need to have highest used so it renders - for (QQuickParticlePainter* p : qAsConst(m_system->groupData[groupId]->painters)) { + for (QQuickParticlePainter* p : std::as_const(m_system->groupData[groupId]->painters)) { QQuickImageParticle* other = qobject_cast<QQuickImageParticle*>(p); if (other){ if (other->perfLevel > perfLevel) { @@ -1652,7 +1645,7 @@ void QQuickImageParticle::spritesUpdate(qreal time) ImageMaterialData *state = getState(m_material); // Sprite progression handled CPU side, so as to have per-frame control. for (auto groupId : groupIds()) { - for (QQuickParticleData* mainDatum : qAsConst(m_system->groupData[groupId]->data)) { + for (QQuickParticleData* mainDatum : std::as_const(m_system->groupData[groupId]->data)) { QSGGeometryNode *node = m_nodes[groupId]; if (!node) continue; @@ -1660,7 +1653,7 @@ void QQuickImageParticle::spritesUpdate(qreal time) // This is particularly important for cut-up sprites. QQuickParticleData* datum = (mainDatum->animationOwner == this ? mainDatum : getShadowDatum(mainDatum)); int spriteIdx = 0; - for (int i = 0; i<m_startsIdx.count(); i++) { + for (int i = 0; i<m_startsIdx.size(); i++) { if (m_startsIdx[i].second == groupId){ spriteIdx = m_startsIdx[i].first + datum->index; break; @@ -1713,12 +1706,12 @@ void QQuickImageParticle::spritesUpdate(qreal time) void QQuickImageParticle::spriteAdvance(int spriteIdx) { - if (!m_startsIdx.count())//Probably overly defensive + if (!m_startsIdx.size())//Probably overly defensive return; int gIdx = -1; int i; - for (i = 0; i<m_startsIdx.count(); i++) { + for (i = 0; i<m_startsIdx.size(); i++) { if (spriteIdx < m_startsIdx[i].first) { gIdx = m_startsIdx[i-1].second; break; @@ -1825,10 +1818,13 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx) if (m_explicitRotation){ if (!datum->rotationOwner) datum->rotationOwner = this; - rotation = - (m_rotation + (m_rotationVariation - 2*QRandomGenerator::global()->bounded(m_rotationVariation)) ) * CONV; - rotationVelocity = - (m_rotationVelocity + (m_rotationVelocityVariation - 2*QRandomGenerator::global()->bounded(m_rotationVelocityVariation)) ) * CONV; + rotation = qDegreesToRadians( + m_rotation + (m_rotationVariation + - 2 * QRandomGenerator::global()->bounded(m_rotationVariation))); + rotationVelocity = qDegreesToRadians( + m_rotationVelocity + + (m_rotationVelocityVariation + - 2 * QRandomGenerator::global()->bounded(m_rotationVelocityVariation))); autoRotate = m_autoRotation ? 1 : 0; if (datum->rotationOwner == this) { datum->rotation = rotation; @@ -1850,15 +1846,17 @@ void QQuickImageParticle::initialize(int gIdx, int pIdx) if (m_explicitColor) { if (!datum->colorOwner) datum->colorOwner = this; - color.r = m_color.red() * (1 - redVariation) + QRandomGenerator::global()->bounded(256) * redVariation; - color.g = m_color.green() * (1 - greenVariation) + QRandomGenerator::global()->bounded(256) * greenVariation; - color.b = m_color.blue() * (1 - blueVariation) + QRandomGenerator::global()->bounded(256) * blueVariation; - color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + QRandomGenerator::global()->bounded(256) * m_alphaVariation; + const auto rgbColor = m_color.toRgb(); + color.r = rgbColor.red() * (1 - redVariation) + QRandomGenerator::global()->bounded(256) * redVariation; + color.g = rgbColor.green() * (1 - greenVariation) + QRandomGenerator::global()->bounded(256) * greenVariation; + color.b = rgbColor.blue() * (1 - blueVariation) + QRandomGenerator::global()->bounded(256) * blueVariation; + color.a = m_alpha * rgbColor.alpha() * (1 - m_alphaVariation) + QRandomGenerator::global()->bounded(256) * m_alphaVariation; if (datum->colorOwner == this) datum->color = color; else getShadowDatum(datum)->color = color; } + break; default: break; } |