Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qquick3dshaderutils_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QQUICK3DSHADERUTILS_H
5#define QQUICK3DSHADERUTILS_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 <QtQuick3D/qtquick3dglobal.h>
19#include <QtQuick3D/private/qquick3dobject_p.h>
20#include <QtQuick3D/private/qquick3dtexture_p.h>
21#include <QtQuick3D/private/qquick3dmaterial_p.h>
22
23#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
24
25#include <QtQuick3DRuntimeRender/private/qssgrendercommands_p.h>
26
27QT_BEGIN_NAMESPACE
28
29class QQuick3DShaderUtilsShader;
30class QQmlContext;
31
32namespace QSSGShaderUtils {
33
35using ResolveFunction = bool (*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey);
37Q_QUICK3D_EXPORT QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey);
38Q_QUICK3D_EXPORT MetaTypeList supportedMetatypes();
39
40
41template<QMetaType::Type>
43{
44};
45
46Q_QUICK3D_EXPORT QByteArray uniformTypeName(QMetaType type);
47Q_QUICK3D_EXPORT QByteArray uniformTypeName(QSSGRenderShaderValue::Type type);
49}
50
51class Q_QUICK3D_EXPORT QQuick3DShaderUtilsTextureInput : public QObject
52{
53 Q_OBJECT
54 Q_PROPERTY(QQuick3DTexture *texture READ texture WRITE setTexture NOTIFY textureChanged)
55 Q_PROPERTY(bool enabled MEMBER enabled NOTIFY enabledChanged)
56
57 QML_NAMED_ELEMENT(TextureInput)
58
59public:
60 explicit QQuick3DShaderUtilsTextureInput(QObject *p = nullptr);
61 virtual ~QQuick3DShaderUtilsTextureInput();
62 QQuick3DTexture *m_texture = nullptr;
63 bool enabled = true;
64 QByteArray name;
65 QQuick3DTexture *texture() const
66 {
67 return m_texture;
68 }
69
70public Q_SLOTS:
71 void setTexture(QQuick3DTexture *texture);
72
73Q_SIGNALS:
74 void textureChanged();
75 void enabledChanged();
76};
77
78class Q_QUICK3D_EXPORT QQuick3DShaderUtilsBuffer : public QObject
79{
80 Q_OBJECT
81 Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY changed)
82 Q_PROPERTY(TextureFilterOperation textureFilterOperation READ textureFilterOperation WRITE setTextureFilterOperation NOTIFY changed)
83 Q_PROPERTY(TextureCoordOperation textureCoordOperation READ textureCoordOperation WRITE setTextureCoordOperation NOTIFY changed)
84 Q_PROPERTY(float sizeMultiplier MEMBER sizeMultiplier NOTIFY changed)
85 Q_PROPERTY(AllocateBufferFlagValues bufferFlags READ bufferFlags WRITE setBufferFlags NOTIFY changed)
86 Q_PROPERTY(QByteArray name MEMBER name NOTIFY changed)
87
88 QML_NAMED_ELEMENT(Buffer)
89
90public:
91 QQuick3DShaderUtilsBuffer() = default;
92 ~QQuick3DShaderUtilsBuffer() override = default;
93
94 enum class TextureFilterOperation // must match QSSGRenderTextureFilterOp
95 {
96 Unknown = 0,
97 Nearest,
98 Linear
99 };
100 Q_ENUM(TextureFilterOperation)
101
102 enum class TextureCoordOperation // must match QSSGRenderTextureCoordOp
103 {
104 Unknown = 0,
105 ClampToEdge,
106 MirroredRepeat,
107 Repeat
108 };
109 Q_ENUM(TextureCoordOperation)
110
111 enum class AllocateBufferFlagValues
112 {
113 None = 0,
114 SceneLifetime = 1
115 };
116 Q_ENUM(AllocateBufferFlagValues)
117
118 enum class TextureFormat {
119 Unknown = 0,
120 RGBA8,
121 RGBA16F,
122 RGBA32F,
123 R8,
124 R16,
125 R16F,
126 R32F
127 };
128 Q_ENUM(TextureFormat)
129
130 QSSGAllocateBuffer command {};
131 TextureFilterOperation textureFilterOperation() const { return TextureFilterOperation(command.m_filterOp); }
132 void setTextureFilterOperation(TextureFilterOperation op);
133
134 TextureCoordOperation textureCoordOperation() const { return TextureCoordOperation(command.m_texCoordOp); }
135 void setTextureCoordOperation(TextureCoordOperation texCoordOp);
136 float &sizeMultiplier = command.m_sizeMultiplier;
137 QSSGCommand *cloneCommand() { return new QSSGAllocateBuffer(command); }
138
139 TextureFormat format() const;
140 void setFormat(TextureFormat format);
141
142 AllocateBufferFlagValues bufferFlags() const { return AllocateBufferFlagValues(int(command.m_bufferFlags)); }
143 void setBufferFlags(AllocateBufferFlagValues flag);
144
145 QByteArray &name = command.m_name;
146
147 static QSSGRenderTextureFormat::Format mapTextureFormat(QQuick3DShaderUtilsBuffer::TextureFormat fmt);
148 static QQuick3DShaderUtilsBuffer::TextureFormat mapRenderTextureFormat(QSSGRenderTextureFormat::Format fmt);
149
150Q_SIGNALS:
151 void changed();
152};
153
154class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderCommand : public QObject
155{
156 Q_OBJECT
157
158 QML_NAMED_ELEMENT(Command)
159
160public:
161 QQuick3DShaderUtilsRenderCommand() = default;
162 ~QQuick3DShaderUtilsRenderCommand() override = default;
163 virtual QSSGCommand *cloneCommand() { Q_ASSERT(0); return nullptr; }
164 virtual int bufferCount() const { return 0; }
165 virtual QQuick3DShaderUtilsBuffer *bufferAt(int idx) const { Q_UNUSED(idx); return nullptr; }
166};
167
168class Q_QUICK3D_EXPORT QQuick3DShaderUtilsBufferInput : public QQuick3DShaderUtilsRenderCommand
169{
170 Q_OBJECT
171 Q_PROPERTY(QQuick3DShaderUtilsBuffer *buffer READ buffer WRITE setBuffer)
172 Q_PROPERTY(QByteArray sampler MEMBER sampler)
173
174 QML_NAMED_ELEMENT(BufferInput)
175
176public:
177 QQuick3DShaderUtilsBufferInput() = default;
178 ~QQuick3DShaderUtilsBufferInput() override = default;
179 QSSGApplyBufferValue command { QByteArray(), QByteArray() };
180 QByteArray &sampler = command.m_samplerName;
181 QSSGCommand *cloneCommand() override { return new QSSGApplyBufferValue(command); }
182
183 int bufferCount() const override { return (m_buffer != nullptr) ? 1 : 0; }
184 QQuick3DShaderUtilsBuffer *bufferAt(int idx) const override
185 {
186 Q_ASSERT(idx < 1 && idx >= 0);
187 return (m_buffer && idx == 0) ? m_buffer : nullptr;
188 }
189
190 QQuick3DShaderUtilsBuffer *buffer() const { return m_buffer; }
191 void setBuffer(QQuick3DShaderUtilsBuffer *buffer) {
192 if (m_buffer == buffer)
193 return;
194
195 if (buffer) {
196 Q_ASSERT(!buffer->name.isEmpty());
197 command.m_bufferName = buffer->name;
198 }
199 m_buffer = buffer;
200 }
201
202 QQuick3DShaderUtilsBuffer *m_buffer = nullptr;
203
204};
205
206class Q_QUICK3D_EXPORT QQuick3DShaderUtilsApplyValue : public QQuick3DShaderUtilsRenderCommand
207{
208 Q_OBJECT
209 Q_PROPERTY(QByteArray target MEMBER target)
210 Q_PROPERTY(QVariant value MEMBER value)
211
212 QML_NAMED_ELEMENT(SetUniformValue)
213
214public:
215 QQuick3DShaderUtilsApplyValue() = default;
216 ~QQuick3DShaderUtilsApplyValue() override = default;
217 QSSGCommand *cloneCommand() override { return new QSSGApplyValue(command); }
218 QSSGApplyValue command { };
219 QVariant &value = command.m_value;
220 QByteArray &target = command.m_propertyName;
221};
222
223class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPass : public QObject
224{
225 Q_OBJECT
226 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands READ commands)
227 Q_PROPERTY(QQuick3DShaderUtilsBuffer *output MEMBER outputBuffer)
228 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsShader> shaders READ shaders)
229
230 QML_NAMED_ELEMENT(Pass)
231
232public:
233 QQuick3DShaderUtilsRenderPass() = default;
234 ~QQuick3DShaderUtilsRenderPass() override = default;
235
236 static void qmlAppendCommand(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, QQuick3DShaderUtilsRenderCommand *command);
237 static QQuick3DShaderUtilsRenderCommand *qmlCommandAt(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, qsizetype index);
238 static qsizetype qmlCommandCount(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
239 static void qmlCommandClear(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
240
241 static void qmlAppendShader(QQmlListProperty<QQuick3DShaderUtilsShader> *list, QQuick3DShaderUtilsShader *shader);
242 static QQuick3DShaderUtilsShader *qmlShaderAt(QQmlListProperty<QQuick3DShaderUtilsShader> *list, qsizetype index);
243 static qsizetype qmlShaderCount(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
244 static void qmlShaderClear(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
245
246 QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands();
247 QVector<QQuick3DShaderUtilsRenderCommand *> m_commands;
248 QQuick3DShaderUtilsBuffer *outputBuffer = nullptr;
249 QQmlListProperty<QQuick3DShaderUtilsShader> shaders();
250 QVarLengthArray<QQuick3DShaderUtilsShader *, 2> m_shaders;
251
252Q_SIGNALS:
253 void changed();
254};
255
256class Q_QUICK3D_EXPORT QQuick3DShaderUtilsShader : public QObject
257{
258 Q_OBJECT
259 Q_PROPERTY(QUrl shader MEMBER shader NOTIFY shaderChanged)
260 Q_PROPERTY(Stage stage MEMBER stage NOTIFY stageChanged)
261
262 QML_NAMED_ELEMENT(Shader)
263
264public:
265 QQuick3DShaderUtilsShader() = default;
266 virtual ~QQuick3DShaderUtilsShader() = default;
267 enum class Stage : quint8
268 {
269 Vertex = 0,
270 Fragment = 1
271 };
272 Q_ENUM(Stage)
273
274 QUrl shader;
275 Stage stage = Stage::Fragment;
276
277Q_SIGNALS:
278 void shaderChanged();
279 void stageChanged();
280};
281
282QT_END_NAMESPACE
283
284Q_DECLARE_OPAQUE_POINTER(QQuick3DShaderUtilsTextureInput)
285
286#endif // QQUICK3DSHADERUTILS_H
\qmltype Shader \inherits QtObject \inqmlmodule QtQuick3D
ResolveFunction resolveShaderOverride
QSSGRenderShaderValue::Type uniformType(QMetaType type)
QByteArray uniformTypeName(QMetaType type)
bool(*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey) ResolveFunction
static constexpr QMetaType::Type qssg_metatype_list[]
QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey)
MetaTypeList supportedMetatypes()
void setResolveFunction(ResolveFunction fn)