diff options
Diffstat (limited to 'src/particles/qquickimageparticle_p.h')
-rw-r--r-- | src/particles/qquickimageparticle_p.h | 145 |
1 files changed, 75 insertions, 70 deletions
diff --git a/src/particles/qquickimageparticle_p.h b/src/particles/qquickimageparticle_p.h index 95323c25a6..f0bfb8a1d6 100644 --- a/src/particles/qquickimageparticle_p.h +++ b/src/particles/qquickimageparticle_p.h @@ -1,44 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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$ -** -****************************************************************************/ - -#ifndef ULTRAPARTICLE_H -#define ULTRAPARTICLE_H +// Copyright (C) 2019 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 + +#ifndef QQUICKIMAGEPARTICLE_P_H +#define QQUICKIMAGEPARTICLE_P_H // // W A R N I N G @@ -50,22 +14,26 @@ // // We mean it. // + #include "qquickparticlepainter_p.h" #include "qquickdirection_p.h" -#include <private/qquickpixmapcache_p.h> +#include <private/qquickpixmap_p.h> #include <QQmlListProperty> -#include <QtQuick/qsgsimplematerial.h> #include <QtGui/qcolor.h> +#include <QtQuick/qsgmaterial.h> QT_BEGIN_NAMESPACE class ImageMaterialData; class QSGGeometryNode; +class QSGMaterial; class QQuickSprite; class QQuickStochasticEngine; -struct SimpleVertex { +class QRhi; + +struct SimplePointVertex { float x; float y; float t; @@ -78,6 +46,21 @@ struct SimpleVertex { float ay; }; +struct ColoredPointVertex { + float x; + float y; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + Color4ub color; +}; + +// Like Colored, but using DrawTriangles instead of DrawPoints struct ColoredVertex { float x; float y; @@ -90,13 +73,16 @@ struct ColoredVertex { float ax; float ay; Color4ub color; + uchar tx; + uchar ty; + uchar _padding[2]; // feel free to use }; struct DeformableVertex { float x; float y; - float tx; - float ty; + float rotation; + float rotationVelocity; float t; float lifeSpan; float size; @@ -110,16 +96,17 @@ struct DeformableVertex { float xy; float yx; float yy; - float rotation; - float rotationVelocity; - float autoRotate;//Assumed that GPUs prefer floats to bools + uchar tx; + uchar ty; + uchar autoRotate; + uchar _padding; // feel free to use }; struct SpriteVertex { float x; float y; - float tx; - float ty; + float rotation; + float rotationVelocity; float t; float lifeSpan; float size; @@ -133,16 +120,16 @@ struct SpriteVertex { float xy; float yx; float yy; - float rotation; - float rotationVelocity; - float autoRotate;//Assumed that GPUs prefer floats to bools + uchar tx; + uchar ty; + uchar autoRotate; + uchar _padding; // feel free to use float animW; float animH; float animProgress; float animX1; float animY1; float animX2; - float animY2; }; template <typename Vertex> @@ -153,7 +140,13 @@ struct Vertices { Vertex v4; }; -class QQuickImageParticle : public QQuickParticlePainter +class ImageMaterial : public QSGMaterial +{ +public: + virtual ImageMaterialData *state() = 0; +}; + +class Q_QUICKPARTICLES_EXPORT QQuickImageParticle : public QQuickParticlePainter { Q_OBJECT Q_PROPERTY(QUrl source READ image WRITE setImage NOTIFY imageChanged) @@ -192,8 +185,10 @@ class QQuickImageParticle : public QQuickParticlePainter Q_PROPERTY(bool spritesInterpolate READ spritesInterpolate WRITE setSpritesInterpolate NOTIFY spritesInterpolateChanged) Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged) + QML_NAMED_ELEMENT(ImageParticle) + QML_ADDED_IN_VERSION(2, 0) public: - explicit QQuickImageParticle(QQuickItem *parent = 0); + explicit QQuickImageParticle(QQuickItem *parent = nullptr); virtual ~QQuickImageParticle(); enum Status { Null, Ready, Loading, Error }; @@ -211,7 +206,8 @@ public: enum PerformanceLevel{//TODO: Expose? Unknown = 0, - Simple, + SimplePoint, + ColoredPoint, Colored, Deformable, Tabled, @@ -315,7 +311,6 @@ Q_SIGNALS: void statusChanged(Status arg); public Q_SLOTS: - void reloadColor(const Color4ub &c, QQuickParticleData* d); void setAlphaVariation(qreal arg); void setAlpha(qreal arg); @@ -352,7 +347,7 @@ protected: void commit(int gIdx, int pIdx) override; QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override; - void prepareNextFrame(QSGNode**); + bool prepareNextFrame(QSGNode**); void buildParticleNodes(QSGNode**); void sceneGraphInvalidated() override; @@ -363,7 +358,8 @@ private Q_SLOTS: void spriteAdvance(int spriteIndex); void spritesUpdate(qreal time = 0 ); void mainThreadFetchImageData(); - void finishBuildParticleNodes(QSGNode **n); + void invalidateSceneGraph(); + private: struct ImageData { QUrl source; @@ -375,10 +371,12 @@ private: QScopedPointer<ImageData> m_opacityTable; bool loadingSomething(); + void finishBuildParticleNodes(QSGNode **n); QColor m_color; qreal m_color_variation; + QSGNode *m_outgoingNode; QHash<int, QSGGeometryNode *> m_nodes; QHash<int, int> m_idxStarts;//TODO: Proper resizing will lead to needing a spriteEngine per particle - do this after sprite engine gains transparent sharing? QList<QPair<int, int> > m_startsIdx;//Same data, optimized for alternate retrieval @@ -415,38 +413,45 @@ private: bool m_bypassOptimizations; PerformanceLevel perfLevel; + PerformanceLevel m_targetPerfLevel; + void checkPerfLevel(PerformanceLevel level); - PerformanceLevel m_lastLevel; bool m_debugMode; template<class Vertex> void initTexCoords(Vertex* v, int count){ Vertex* end = v + count; + // Vertex coords between (0.0, 0.0) and (1.0, 1.0) while (v < end){ v[0].tx = 0; v[0].ty = 0; - v[1].tx = 1; + v[1].tx = 255; v[1].ty = 0; v[2].tx = 0; - v[2].ty = 1; + v[2].ty = 255; - v[3].tx = 1; - v[3].ty = 1; + v[3].tx = 255; + v[3].ty = 255; v += 4; } } - template<class MaterialData> - static MaterialData* getState(QSGMaterial* m) { - return static_cast<QSGSimpleMaterial<MaterialData> *>(m)->state(); + ImageMaterialData *getState(QSGMaterial *m) { + return static_cast<ImageMaterial *>(m)->state(); } + EntryEffect m_entryEffect; Status m_status; int m_startedImageLoading; + QRhi *m_rhi; + bool m_apiChecked; + qreal m_dpr; + bool m_previousActive; }; QT_END_NAMESPACE -#endif // ULTRAPARTICLE_H + +#endif // QQUICKIMAGEPARTICLE_P_H |