1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKSHADEREFFECTSOURCE_P_H
5#define QQUICKSHADEREFFECTSOURCE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick/private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_shadereffect);
21
22#include "qquickitem.h"
23#include <QtQuick/qsgtextureprovider.h>
24#include <private/qsgadaptationlayer_p.h>
25#include <QtQuick/private/qsgcontext_p.h>
26#include <private/qsgdefaultinternalimagenode_p.h>
27#include <private/qquickitemchangelistener_p.h>
28
29#include "qpointer.h"
30#include "qsize.h"
31#include "qrect.h"
32
33QT_BEGIN_NAMESPACE
34
35class QSGNode;
36class UpdatePaintNodeData;
37class QOpenGLFramebufferObject;
38class QSGSimpleRectNode;
39
40class QQuickShaderEffectSourceTextureProvider;
41
42class Q_QUICK_EXPORT QQuickShaderEffectSource : public QQuickItem,
43 public QSafeQuickItemChangeListener<QQuickShaderEffectSource>
44{
45 Q_OBJECT
46 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
47 Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged)
48 Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged)
49 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged)
50 Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged)
51 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged)
52 Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged)
53 Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged)
54 Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged)
55 Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION(2, 6))
56 Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION(2, 9))
57 QML_NAMED_ELEMENT(ShaderEffectSource)
58 QML_ADDED_IN_VERSION(2, 0)
59
60public:
61 enum WrapMode {
62 ClampToEdge,
63 RepeatHorizontally,
64 RepeatVertically,
65 Repeat
66 };
67 Q_ENUM(WrapMode)
68
69 enum Format {
70 RGBA8 = 1,
71 RGBA16F,
72 RGBA32F,
73
74 // Qt 5 legacy values that were ignored starting from Qt 6.0
75 Alpha = RGBA8,
76 RGB = RGBA8,
77 RGBA = RGBA8
78 };
79 Q_ENUM(Format)
80
81 enum TextureMirroring {
82 NoMirroring = 0x00,
83 MirrorHorizontally = 0x01,
84 MirrorVertically = 0x02
85 };
86 Q_ENUM(TextureMirroring)
87
88 QQuickShaderEffectSource(QQuickItem *parent = nullptr);
89 ~QQuickShaderEffectSource() override;
90
91 WrapMode wrapMode() const;
92 void setWrapMode(WrapMode mode);
93
94 QQuickItem *sourceItem() const;
95 void setSourceItem(QQuickItem *item);
96
97 QRectF sourceRect() const;
98 void setSourceRect(const QRectF &rect);
99
100 QSize textureSize() const;
101 void setTextureSize(const QSize &size);
102
103 Format format() const;
104 void setFormat(Format format);
105
106 bool live() const;
107 void setLive(bool live);
108
109 bool hideSource() const;
110 void setHideSource(bool hide);
111
112 bool mipmap() const;
113 void setMipmap(bool enabled);
114
115 bool recursive() const;
116 void setRecursive(bool enabled);
117
118 TextureMirroring textureMirroring() const;
119 void setTextureMirroring(TextureMirroring mirroring);
120
121 bool isTextureProvider() const override { return true; }
122 QSGTextureProvider *textureProvider() const override;
123
124 Q_INVOKABLE void scheduleUpdate();
125
126 int samples() const;
127 void setSamples(int count);
128
129Q_SIGNALS:
130 void wrapModeChanged();
131 void sourceItemChanged();
132 void sourceRectChanged();
133 void textureSizeChanged();
134 void formatChanged();
135 void liveChanged();
136 void hideSourceChanged();
137 void mipmapChanged();
138 void recursiveChanged();
139 void textureMirroringChanged();
140 void samplesChanged();
141
142 void scheduledUpdateCompleted();
143
144private Q_SLOTS:
145 void sourceItemDestroyed(QObject *item);
146 void invalidateSceneGraph();
147
148protected:
149 void releaseResources() override;
150 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
151
152 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
153 void itemChange(ItemChange change, const ItemChangeData &value) override;
154
155private:
156 void ensureTexture();
157
158 QQuickShaderEffectSourceTextureProvider *m_provider;
159 QSGLayer *m_texture;
160 WrapMode m_wrapMode;
161 QQuickItem *m_sourceItem;
162 QRectF m_sourceRect;
163 QSize m_textureSize;
164 Format m_format;
165 int m_samples;
166 uint m_live : 1;
167 uint m_hideSource : 1;
168 uint m_mipmap : 1;
169 uint m_recursive : 1;
170 uint m_grab : 1;
171 uint m_textureMirroring : 2; // Stores TextureMirroring enum
172};
173
174QT_END_NAMESPACE
175
176#endif // QQUICKSHADEREFFECTSOURCE_P_H
177

source code of qtdeclarative/src/quick/items/qquickshadereffectsource_p.h