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_PRIVATE_EXPORT QQuickShaderEffectSource : public QQuickItem, public QQuickItemChangeListener
43{
44 Q_OBJECT
45 Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged FINAL)
46 Q_PROPERTY(QQuickItem *sourceItem READ sourceItem WRITE setSourceItem NOTIFY sourceItemChanged FINAL)
47 Q_PROPERTY(QRectF sourceRect READ sourceRect WRITE setSourceRect NOTIFY sourceRectChanged FINAL)
48 Q_PROPERTY(QSize textureSize READ textureSize WRITE setTextureSize NOTIFY textureSizeChanged FINAL)
49 Q_PROPERTY(Format format READ format WRITE setFormat NOTIFY formatChanged FINAL)
50 Q_PROPERTY(bool live READ live WRITE setLive NOTIFY liveChanged FINAL)
51 Q_PROPERTY(bool hideSource READ hideSource WRITE setHideSource NOTIFY hideSourceChanged FINAL)
52 Q_PROPERTY(bool mipmap READ mipmap WRITE setMipmap NOTIFY mipmapChanged FINAL)
53 Q_PROPERTY(bool recursive READ recursive WRITE setRecursive NOTIFY recursiveChanged FINAL)
54 Q_PROPERTY(TextureMirroring textureMirroring READ textureMirroring WRITE setTextureMirroring NOTIFY textureMirroringChanged REVISION(2, 6) FINAL)
55 Q_PROPERTY(int samples READ samples WRITE setSamples NOTIFY samplesChanged REVISION(2, 9) FINAL)
56 QML_NAMED_ELEMENT(ShaderEffectSource)
57 QML_ADDED_IN_VERSION(2, 0)
58
59public:
60 enum WrapMode {
61 ClampToEdge,
62 RepeatHorizontally,
63 RepeatVertically,
64 Repeat
65 };
66 Q_ENUM(WrapMode)
67
68 enum Format {
69 RGBA8 = 1,
70 RGBA16F,
71 RGBA32F,
72
73 // Qt 5 legacy values that were ignored starting from Qt 6.0
74 Alpha = RGBA8,
75 RGB = RGBA8,
76 RGBA = RGBA8
77 };
78 Q_ENUM(Format)
79
80 enum TextureMirroring {
81 NoMirroring = 0x00,
82 MirrorHorizontally = 0x01,
83 MirrorVertically = 0x02
84 };
85 Q_ENUM(TextureMirroring)
86
87 QQuickShaderEffectSource(QQuickItem *parent = nullptr);
88 ~QQuickShaderEffectSource() override;
89
90 WrapMode wrapMode() const;
91 void setWrapMode(WrapMode mode);
92
93 QQuickItem *sourceItem() const;
94 void setSourceItem(QQuickItem *item);
95
96 QRectF sourceRect() const;
97 void setSourceRect(const QRectF &rect);
98
99 QSize textureSize() const;
100 void setTextureSize(const QSize &size);
101
102 Format format() const;
103 void setFormat(Format format);
104
105 bool live() const;
106 void setLive(bool live);
107
108 bool hideSource() const;
109 void setHideSource(bool hide);
110
111 bool mipmap() const;
112 void setMipmap(bool enabled);
113
114 bool recursive() const;
115 void setRecursive(bool enabled);
116
117 TextureMirroring textureMirroring() const;
118 void setTextureMirroring(TextureMirroring mirroring);
119
120 bool isTextureProvider() const override { return true; }
121 QSGTextureProvider *textureProvider() const override;
122
123 Q_INVOKABLE void scheduleUpdate();
124
125 int samples() const;
126 void setSamples(int count);
127
128Q_SIGNALS:
129 void wrapModeChanged();
130 void sourceItemChanged();
131 void sourceRectChanged();
132 void textureSizeChanged();
133 void formatChanged();
134 void liveChanged();
135 void hideSourceChanged();
136 void mipmapChanged();
137 void recursiveChanged();
138 void textureMirroringChanged();
139 void samplesChanged();
140
141 void scheduledUpdateCompleted();
142
143private Q_SLOTS:
144 void sourceItemDestroyed(QObject *item);
145 void invalidateSceneGraph();
146
147protected:
148 void releaseResources() override;
149 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *) override;
150
151 void itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &) override;
152 void itemChange(ItemChange change, const ItemChangeData &value) override;
153
154private:
155 void ensureTexture();
156
157 QQuickShaderEffectSourceTextureProvider *m_provider;
158 QSGLayer *m_texture;
159 WrapMode m_wrapMode;
160 QQuickItem *m_sourceItem;
161 QRectF m_sourceRect;
162 QSize m_textureSize;
163 Format m_format;
164 int m_samples;
165 uint m_live : 1;
166 uint m_hideSource : 1;
167 uint m_mipmap : 1;
168 uint m_recursive : 1;
169 uint m_grab : 1;
170 uint m_textureMirroring : 2; // Stores TextureMirroring enum
171};
172
173QT_END_NAMESPACE
174
175#endif // QQUICKSHADEREFFECTSOURCE_P_H
176

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