1// Copyright (C) 2022 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 QQUICKSHADEREFFECT_P_P_H
5#define QQUICKSHADEREFFECT_P_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 <private/qtquickglobal_p.h>
19
20QT_REQUIRE_CONFIG(quick_shadereffect);
21
22#include <private/qquickshadereffect_p.h>
23#include <private/qquickitem_p.h>
24#include <private/qquickshadereffectmesh_p.h>
25
26QT_BEGIN_NAMESPACE
27
28namespace QtPrivate {
29class EffectSlotMapper;
30}
31
32class QQuickShaderEffectPrivate : public QQuickItemPrivate
33{
34 Q_DECLARE_PUBLIC(QQuickShaderEffect)
35
36public:
37 QQuickShaderEffectPrivate();
38 ~QQuickShaderEffectPrivate();
39
40 void updatePolish() override;
41
42 QUrl fragmentShader() const { return m_fragShader; }
43 void setFragmentShader(const QUrl &fileUrl);
44
45 QUrl vertexShader() const { return m_vertShader; }
46 void setVertexShader(const QUrl &fileUrl);
47
48 bool blending() const { return m_blending; }
49 void setBlending(bool enable);
50
51 QVariant mesh() const;
52 void setMesh(const QVariant &mesh);
53
54 QQuickShaderEffect::CullMode cullMode() const { return m_cullMode; }
55 void setCullMode(QQuickShaderEffect::CullMode face);
56
57 QString log() const;
58 QQuickShaderEffect::Status status() const;
59
60 bool supportsAtlasTextures() const { return m_supportsAtlasTextures; }
61 void setSupportsAtlasTextures(bool supports);
62
63 QString parseLog();
64
65 void handleEvent(QEvent *);
66 void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);
67 QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *);
68 void handleComponentComplete();
69 void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value);
70 void maybeUpdateShaders();
71 bool updateUniformValue(const QByteArray &name, const QVariant &value,
72 QSGShaderEffectNode *node);
73
74 void propertyChanged(int mappedId);
75 void sourceDestroyed(QObject *object);
76 void markGeometryDirtyAndUpdate();
77 void markGeometryDirtyAndUpdateIfSupportsAtlas();
78 void shaderCodePrepared(bool ok, QSGGuiThreadShaderEffectManager::ShaderInfo::Type typeHint,
79 const QUrl &loadUrl, QSGGuiThreadShaderEffectManager::ShaderInfo *result);
80
81private:
82 QSGGuiThreadShaderEffectManager *shaderEffectManager() const;
83
84 enum Shader {
85 Vertex,
86 Fragment,
87
88 NShader
89 };
90 bool updateShader(Shader shaderType, const QUrl &fileUrl);
91 void updateShaderVars(Shader shaderType);
92 void disconnectSignals(Shader shaderType);
93 void clearMappers(Shader shaderType);
94 std::optional<int> findMappedShaderVariableId(const QByteArray &name) const;
95 bool sourceIsUnique(QQuickItem *source, Shader typeToSkip, int indexToSkip) const;
96
97 bool inDestructor = false;
98 const QMetaObject *m_itemMetaObject = nullptr;
99 QSize m_meshResolution;
100 QQuickShaderEffectMesh *m_mesh;
101 QMetaObject::Connection m_meshConnection;
102 QQuickGridMesh m_defaultMesh;
103 QQuickShaderEffect::CullMode m_cullMode;
104 bool m_blending;
105 bool m_supportsAtlasTextures;
106 mutable QSGGuiThreadShaderEffectManager *m_mgr;
107 QUrl m_fragShader;
108 bool m_fragNeedsUpdate;
109 QUrl m_vertShader;
110 bool m_vertNeedsUpdate;
111
112 QSGShaderEffectNode::ShaderData m_shaders[NShader];
113 QSGShaderEffectNode::DirtyShaderFlags m_dirty;
114 QSet<int> m_dirtyConstants[NShader];
115 QSet<int> m_dirtyTextures[NShader];
116 QSGGuiThreadShaderEffectManager::ShaderInfo *m_inProgress[NShader];
117
118 QVector<QtPrivate::EffectSlotMapper *> m_mappers[NShader];
119
120 QHash<QQuickItem *, QMetaObject::Connection> m_destroyedConnections;
121};
122
123QT_END_NAMESPACE
124
125#endif // QQUICKSHADEREFFECT_P_P_H
126

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