1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #ifndef QQUICKGENERICSHADEREFFECT_P_H |
41 | #define QQUICKGENERICSHADEREFFECT_P_H |
42 | |
43 | // |
44 | // W A R N I N G |
45 | // ------------- |
46 | // |
47 | // This file is not part of the Qt API. It exists purely as an |
48 | // implementation detail. This header file may change from version to |
49 | // version without notice, or even be removed. |
50 | // |
51 | // We mean it. |
52 | // |
53 | |
54 | #include <QtQuick/qquickitem.h> |
55 | #include <private/qtquickglobal_p.h> |
56 | #include <private/qsgadaptationlayer_p.h> |
57 | #include "qquickshadereffect_p.h" |
58 | #include "qquickshadereffectmesh_p.h" |
59 | |
60 | QT_BEGIN_NAMESPACE |
61 | |
62 | class QSignalMapper; |
63 | |
64 | class Q_QUICK_PRIVATE_EXPORT QQuickGenericShaderEffect : public QObject |
65 | { |
66 | Q_OBJECT |
67 | |
68 | public: |
69 | QQuickGenericShaderEffect(QQuickShaderEffect *item, QObject *parent = nullptr); |
70 | ~QQuickGenericShaderEffect(); |
71 | |
72 | QByteArray fragmentShader() const { return m_fragShader; } |
73 | void setFragmentShader(const QByteArray &src); |
74 | |
75 | QByteArray vertexShader() const { return m_vertShader; } |
76 | void setVertexShader(const QByteArray &src); |
77 | |
78 | bool blending() const { return m_blending; } |
79 | void setBlending(bool enable); |
80 | |
81 | QVariant mesh() const; |
82 | void setMesh(const QVariant &mesh); |
83 | |
84 | QQuickShaderEffect::CullMode cullMode() const { return m_cullMode; } |
85 | void setCullMode(QQuickShaderEffect::CullMode face); |
86 | |
87 | QString log() const; |
88 | QQuickShaderEffect::Status status() const; |
89 | |
90 | bool supportsAtlasTextures() const { return m_supportsAtlasTextures; } |
91 | void setSupportsAtlasTextures(bool supports); |
92 | |
93 | QString parseLog(); |
94 | |
95 | void handleEvent(QEvent *); |
96 | void handleGeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry); |
97 | QSGNode *handleUpdatePaintNode(QSGNode *, QQuickItem::UpdatePaintNodeData *); |
98 | void handleComponentComplete(); |
99 | void handleItemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value); |
100 | void maybeUpdateShaders(); |
101 | |
102 | private slots: |
103 | void propertyChanged(int mappedId); |
104 | void sourceDestroyed(QObject *object); |
105 | void markGeometryDirtyAndUpdate(); |
106 | void markGeometryDirtyAndUpdateIfSupportsAtlas(); |
107 | void shaderCodePrepared(bool ok, QSGGuiThreadShaderEffectManager::ShaderInfo::Type typeHint, |
108 | const QByteArray &src, QSGGuiThreadShaderEffectManager::ShaderInfo *result); |
109 | |
110 | private: |
111 | QSGGuiThreadShaderEffectManager *shaderEffectManager() const; |
112 | |
113 | enum Shader { |
114 | Vertex, |
115 | Fragment, |
116 | |
117 | NShader |
118 | }; |
119 | bool updateShader(Shader shaderType, const QByteArray &src); |
120 | void updateShaderVars(Shader shaderType); |
121 | void disconnectSignals(Shader shaderType); |
122 | bool sourceIsUnique(QQuickItem *source, Shader typeToSkip, int indexToSkip) const; |
123 | |
124 | QQuickShaderEffect *m_item; |
125 | QSize m_meshResolution; |
126 | QQuickShaderEffectMesh *m_mesh; |
127 | QQuickGridMesh m_defaultMesh; |
128 | QQuickShaderEffect::CullMode m_cullMode; |
129 | bool m_blending; |
130 | bool m_supportsAtlasTextures; |
131 | mutable QSGGuiThreadShaderEffectManager *m_mgr; |
132 | QByteArray m_fragShader; |
133 | bool m_fragNeedsUpdate; |
134 | QByteArray m_vertShader; |
135 | bool m_vertNeedsUpdate; |
136 | |
137 | QSGShaderEffectNode::ShaderData m_shaders[NShader]; |
138 | QSGShaderEffectNode::DirtyShaderFlags m_dirty; |
139 | QSet<int> m_dirtyConstants[NShader]; |
140 | QSet<int> m_dirtyTextures[NShader]; |
141 | QSGGuiThreadShaderEffectManager::ShaderInfo *m_inProgress[NShader]; |
142 | |
143 | struct SignalMapper { |
144 | SignalMapper() : mapper(nullptr), active(false) { } |
145 | QSignalMapper *mapper; |
146 | bool active; |
147 | }; |
148 | QVector<SignalMapper> m_signalMappers[NShader]; |
149 | }; |
150 | |
151 | QT_END_NAMESPACE |
152 | |
153 | #endif // QQUICKGENERICSHADEREFFECT_P_H |
154 | |