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// Qt-Security score:significant reason:default
4
5
6#ifndef QQUICK3DSHADERUTILS_H
7#define QQUICK3DSHADERUTILS_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <QtQuick3D/qtquick3dglobal.h>
21#include <QtQuick3D/private/qquick3dobject_p.h>
22#include <QtQuick3D/private/qquick3dtexture_p.h>
23#include <QtQuick3D/private/qquick3dmaterial_p.h>
24
25#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
26
27#include <QtQuick3DRuntimeRender/private/qssgrendercommands_p.h>
28
29QT_BEGIN_NAMESPACE
30
31class QQuick3DShaderUtilsShader;
32class QQmlContext;
33class QQuick3DRenderPass;
34
35namespace QSSGShaderUtils {
36
38using ResolveFunction = bool (*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey);
40Q_QUICK3D_EXPORT QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey);
41Q_QUICK3D_EXPORT MetaTypeList supportedMetatypes();
42
43
44template<QMetaType::Type>
46{
47};
48
49Q_QUICK3D_EXPORT QByteArray uniformTypeName(QMetaType type);
50Q_QUICK3D_EXPORT QByteArray uniformTypeName(QSSGRenderShaderValue::Type type);
52}
53
54class Q_QUICK3D_EXPORT QQuick3DShaderUtilsTextureInput : public QQuick3DObject
55{
56 Q_OBJECT
57 Q_PROPERTY(QQuick3DTexture *texture READ texture WRITE setTexture NOTIFY textureChanged)
58 Q_PROPERTY(bool enabled MEMBER enabled NOTIFY enabledChanged)
59
60 QML_NAMED_ELEMENT(TextureInput)
61
62public:
63 explicit QQuick3DShaderUtilsTextureInput(QQuick3DObject *p = nullptr);
64 virtual ~QQuick3DShaderUtilsTextureInput();
65 QQuick3DTexture *m_texture = nullptr;
66 bool enabled = true;
67 QByteArray name;
68 QQuick3DTexture *texture() const
69 {
70 return m_texture;
71 }
72
73public Q_SLOTS:
74 void setTexture(QQuick3DTexture *texture);
75
76Q_SIGNALS:
77 void textureChanged();
78 void enabledChanged();
79};
80
81class Q_QUICK3D_EXPORT QQuick3DShaderUtilsBuffer : public QQuick3DObject
82{
83 Q_OBJECT
84 Q_PROPERTY(TextureFormat format READ format WRITE setFormat NOTIFY changed)
85 Q_PROPERTY(TextureFilterOperation textureFilterOperation READ textureFilterOperation WRITE setTextureFilterOperation NOTIFY changed)
86 Q_PROPERTY(TextureCoordOperation textureCoordOperation READ textureCoordOperation WRITE setTextureCoordOperation NOTIFY changed)
87 Q_PROPERTY(float sizeMultiplier MEMBER sizeMultiplier NOTIFY changed)
88 Q_PROPERTY(AllocateBufferFlagValues bufferFlags READ bufferFlags WRITE setBufferFlags NOTIFY changed)
89 Q_PROPERTY(QByteArray name MEMBER name NOTIFY changed)
90
91 QML_NAMED_ELEMENT(Buffer)
92
93public:
94 QQuick3DShaderUtilsBuffer() = default;
95 ~QQuick3DShaderUtilsBuffer() override = default;
96
97 enum class TextureFilterOperation // must match QSSGRenderTextureFilterOp
98 {
99 Unknown = 0,
100 Nearest,
101 Linear
102 };
103 Q_ENUM(TextureFilterOperation)
104
105 enum class TextureCoordOperation // must match QSSGRenderTextureCoordOp
106 {
107 Unknown = 0,
108 ClampToEdge,
109 MirroredRepeat,
110 Repeat
111 };
112 Q_ENUM(TextureCoordOperation)
113
114 enum class AllocateBufferFlagValues
115 {
116 None = 0,
117 SceneLifetime = 1
118 };
119 Q_ENUM(AllocateBufferFlagValues)
120
121 enum class TextureFormat {
122 Unknown = 0,
123 RGBA8,
124 RGBA16F,
125 RGBA32F,
126 R8,
127 R16,
128 R16F,
129 R32F
130 };
131 Q_ENUM(TextureFormat)
132
133 QSSGAllocateBuffer command {};
134 TextureFilterOperation textureFilterOperation() const { return TextureFilterOperation(command.m_filterOp); }
135 void setTextureFilterOperation(TextureFilterOperation op);
136
137 TextureCoordOperation textureCoordOperation() const { return TextureCoordOperation(command.m_texCoordOp); }
138 void setTextureCoordOperation(TextureCoordOperation texCoordOp);
139 float &sizeMultiplier = command.m_sizeMultiplier;
140 QSSGCommand *cloneCommand() { return new QSSGAllocateBuffer(command); }
141
142 TextureFormat format() const;
143 void setFormat(TextureFormat format);
144
145 AllocateBufferFlagValues bufferFlags() const { return AllocateBufferFlagValues(int(command.m_bufferFlags)); }
146 void setBufferFlags(AllocateBufferFlagValues flag);
147
148 QByteArray &name = command.m_name;
149
150 static QSSGRenderTextureFormat::Format mapTextureFormat(QQuick3DShaderUtilsBuffer::TextureFormat fmt);
151 static QQuick3DShaderUtilsBuffer::TextureFormat mapRenderTextureFormat(QSSGRenderTextureFormat::Format fmt);
152
153Q_SIGNALS:
154 void changed();
155};
156
157class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderCommand : public QQuick3DObject
158{
159 Q_OBJECT
160
161 QML_NAMED_ELEMENT(Command)
162
163public:
164 QQuick3DShaderUtilsRenderCommand() = default;
165 ~QQuick3DShaderUtilsRenderCommand() override = default;
166 virtual QSSGCommand *cloneCommand() { Q_ASSERT(0); return nullptr; }
167 virtual int bufferCount() const { return 0; }
168 virtual QQuick3DShaderUtilsBuffer *bufferAt(int idx) const { Q_UNUSED(idx); return nullptr; }
169
170Q_SIGNALS:
171 void changed();
172};
173
174class Q_QUICK3D_EXPORT QQuick3DShaderUtilsBufferInput : public QQuick3DShaderUtilsRenderCommand
175{
176 Q_OBJECT
177 Q_PROPERTY(QQuick3DShaderUtilsBuffer *buffer READ buffer WRITE setBuffer)
178 Q_PROPERTY(QByteArray sampler MEMBER sampler)
179
180 QML_NAMED_ELEMENT(BufferInput)
181
182public:
183 QQuick3DShaderUtilsBufferInput() = default;
184 ~QQuick3DShaderUtilsBufferInput() override = default;
185 QSSGApplyBufferValue command { QByteArray(), QByteArray() };
186 QByteArray &sampler = command.m_samplerName;
187 QSSGCommand *cloneCommand() override { return new QSSGApplyBufferValue(command); }
188
189 int bufferCount() const override { return (m_buffer != nullptr) ? 1 : 0; }
190 QQuick3DShaderUtilsBuffer *bufferAt(int idx) const override
191 {
192 Q_ASSERT(idx < 1 && idx >= 0);
193 return (m_buffer && idx == 0) ? m_buffer : nullptr;
194 }
195
196 QQuick3DShaderUtilsBuffer *buffer() const { return m_buffer; }
197 void setBuffer(QQuick3DShaderUtilsBuffer *buffer) {
198 if (m_buffer == buffer)
199 return;
200
201 if (buffer) {
202 Q_ASSERT(!buffer->name.isEmpty());
203 command.m_bufferName = buffer->name;
204 }
205 m_buffer = buffer;
206 }
207
208 QQuick3DShaderUtilsBuffer *m_buffer = nullptr;
209
210};
211
212class Q_QUICK3D_EXPORT QQuick3DRenderPassTargetBlend
213{
214 Q_GADGET
215 Q_PROPERTY(bool enable MEMBER enable)
216 Q_PROPERTY(ColorMask colorWrite MEMBER colorWrite)
217 Q_PROPERTY(BlendFactor srcColor MEMBER srcColor)
218 Q_PROPERTY(BlendFactor dstColor MEMBER dstColor)
219 Q_PROPERTY(BlendOperation opColor MEMBER opColor)
220 Q_PROPERTY(BlendFactor srcAlpha MEMBER srcAlpha)
221 Q_PROPERTY(BlendFactor dstAlpha MEMBER dstAlpha)
222 Q_PROPERTY(BlendOperation opAlpha MEMBER opAlpha)
223 QML_VALUE_TYPE(renderTargetBlend)
224 QML_ADDED_IN_VERSION(6, 11)
225
226public:
227 enum ColorMaskComponent : quint32 {
228 R = 1 << 0,
229 G = 1 << 1,
230 B = 1 << 2,
231 A = 1 << 3,
232 };
233 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
234
235 enum class BlendFactor {
236 Zero,
237 One,
238 SrcColor,
239 OneMinusSrcColor,
240 DstColor,
241 OneMinusDstColor,
242 SrcAlpha,
243 OneMinusSrcAlpha,
244 DstAlpha,
245 OneMinusDstAlpha,
246 ConstantColor,
247 OneMinusConstantColor,
248 ConstantAlpha,
249 OneMinusConstantAlpha,
250 SrcAlphaSaturate,
251 Src1Color,
252 OneMinusSrc1Color,
253 Src1Alpha,
254 OneMinusSrc1Alpha
255 };
256 Q_ENUM(BlendFactor)
257
258 enum class BlendOperation {
259 Add,
260 Subtract,
261 ReverseSubtract,
262 Min,
263 Max
264 };
265 Q_ENUM(BlendOperation)
266
267 ColorMask colorWrite = ColorMask(0xF); // R | G | B | A
268 bool enable = false;
269 BlendFactor srcColor = BlendFactor::One;
270 BlendFactor dstColor = BlendFactor::OneMinusSrcAlpha;
271 BlendOperation opColor = BlendOperation::Add;
272 BlendFactor srcAlpha = BlendFactor::One;
273 BlendFactor dstAlpha = BlendFactor::OneMinusSrcAlpha;
274 BlendOperation opAlpha = BlendOperation::Add;
275
276 bool operator==(const QQuick3DRenderPassTargetBlend &other) const
277 {
278 return colorWrite == other.colorWrite
279 && enable == other.enable
280 && srcColor == other.srcColor
281 && dstColor == other.dstColor
282 && opColor == other.opColor
283 && srcAlpha == other.srcAlpha
284 && dstAlpha == other.dstAlpha
285 && opAlpha == other.opAlpha;
286 }
287
288 QQuick3DRenderPassTargetBlend() = default;
289 QQuick3DRenderPassTargetBlend(QRhiGraphicsPipeline::TargetBlend targetBlend)
290 : colorWrite(ColorMask(targetBlend.colorWrite.toInt()))
291 , enable(targetBlend.enable)
292 , srcColor(BlendFactor(targetBlend.srcColor))
293 , dstColor(BlendFactor(targetBlend.dstColor))
294 , opColor(BlendOperation(targetBlend.opColor))
295 , srcAlpha(BlendFactor(targetBlend.srcAlpha))
296 , dstAlpha(BlendFactor(targetBlend.dstAlpha))
297 , opAlpha(BlendOperation(targetBlend.opAlpha))
298 {
299 }
300
301 QRhiGraphicsPipeline::TargetBlend toRhiTargetBlend() const
302 {
303 QRhiGraphicsPipeline::TargetBlend tb;
304 tb.colorWrite = QRhiGraphicsPipeline::ColorMask(colorWrite.toInt());
305 tb.enable = enable;
306 tb.srcColor = QRhiGraphicsPipeline::BlendFactor(int(srcColor));
307 tb.dstColor = QRhiGraphicsPipeline::BlendFactor(int(dstColor));
308 tb.opColor = QRhiGraphicsPipeline::BlendOp(int(opColor));
309 tb.srcAlpha = QRhiGraphicsPipeline::BlendFactor(int(srcAlpha));
310 tb.dstAlpha = QRhiGraphicsPipeline::BlendFactor(int(dstAlpha));
311 tb.opAlpha = QRhiGraphicsPipeline::BlendOp(int(opAlpha));
312 return tb;
313 }
314};
315
323
324class Q_QUICK3D_EXPORT QQuick3DShaderUtilsPipelineStateOverride : public QQuick3DShaderUtilsRenderCommand
325{
326 Q_OBJECT
327 Q_PROPERTY(bool depthTestEnabled READ depthTestEnabled WRITE setDepthTestEnabled RESET resetDepthTestEnabled NOTIFY depthTestEnabledChanged)
328 Q_PROPERTY(bool depthWriteEnabled READ depthWriteEnabled WRITE setDepthWriteEnabled RESET resetDepthWriteEnabled NOTIFY depthWriteEnabledChanged)
329 Q_PROPERTY(bool blendEnabled READ blendEnabled WRITE setBlendEnabled RESET resetBlendEnabled NOTIFY blendEnabledChanged FINAL)
330 Q_PROPERTY(bool usesStencilReference READ usesStencilReference WRITE setUsesStencilReference RESET resetUsesStencilReference NOTIFY usesStencilReferenceChanged)
331 Q_PROPERTY(bool usesScissor READ usesScissor WRITE setUsesScissor RESET resetUsesScissor NOTIFY usesScissorChanged)
332 Q_PROPERTY(CompareOperation depthFunction READ depthFunction WRITE setDepthFunction RESET resetDepthFunction NOTIFY depthFunctionChanged)
333 Q_PROPERTY(CullMode cullMode READ cullMode WRITE setCullMode RESET resetCullMode NOTIFY cullModeChanged)
334 Q_PROPERTY(PolygonMode polygonMode READ polygonMode WRITE setPolygonMode RESET resetPolygonMode NOTIFY polygonModeChanged)
335 Q_PROPERTY(quint32 stencilWriteMask READ stencilWriteMask WRITE setStencilWriteMask RESET resetStencilWriteMask NOTIFY stencilWriteMaskChanged)
336 Q_PROPERTY(quint32 stencilReference READ stencilReference WRITE setStencilReference RESET resetStencilReference NOTIFY stencilReferenceChanged)
337 Q_PROPERTY(QRectF viewport READ viewport WRITE setViewport RESET resetViewport NOTIFY viewportChanged)
338 Q_PROPERTY(QRect scissor READ scissor WRITE setScissor RESET resetScissor NOTIFY scissorChanged)
339 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend0 READ targetBlend0 WRITE setTargetBlend0 RESET resetTargetBlend0 NOTIFY targetBlend0Changed)
340 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend1 READ targetBlend1 WRITE setTargetBlend1 RESET resetTargetBlend1 NOTIFY targetBlend1Changed)
341 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend2 READ targetBlend2 WRITE setTargetBlend2 RESET resetTargetBlend2 NOTIFY targetBlend2Changed)
342 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend3 READ targetBlend3 WRITE setTargetBlend3 RESET resetTargetBlend3 NOTIFY targetBlend3Changed)
343 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend4 READ targetBlend4 WRITE setTargetBlend4 RESET resetTargetBlend4 NOTIFY targetBlend4Changed)
344 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend5 READ targetBlend5 WRITE setTargetBlend5 RESET resetTargetBlend5 NOTIFY targetBlend5Changed)
345 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend6 READ targetBlend6 WRITE setTargetBlend6 RESET resetTargetBlend6 NOTIFY targetBlend6Changed)
346 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend7 READ targetBlend7 WRITE setTargetBlend7 RESET resetTargetBlend7 NOTIFY targetBlend7Changed)
347 QML_NAMED_ELEMENT(PipelineStateOverride)
348 QML_ADDED_IN_VERSION(6, 11)
349
350public:
351 enum class CompareOperation {
352 Never,
353 Less,
354 Equal,
355 LessOrEqual,
356 Greater,
357 NotEqual,
358 GreaterOrEqual,
359 Always
360 };
361 Q_ENUM(CompareOperation)
362
363 enum class CullMode {
364 None,
365 Front,
366 Back
367 };
368 Q_ENUM(CullMode)
369
370 enum class PolygonMode {
371 Fill,
372 Line
373 };
374 Q_ENUM(PolygonMode)
375
376 QQuick3DShaderUtilsPipelineStateOverride();
377 ~QQuick3DShaderUtilsPipelineStateOverride() override;
378
379 bool depthTestEnabled() const;
380 void setDepthTestEnabled(bool newDepthTestEnabled);
381 void resetDepthTestEnabled();
382 bool depthWriteEnabled() const;
383 void setDepthWriteEnabled(bool newDepthWriteEnabled);
384 void resetDepthWriteEnabled();
385
386 bool blendEnabled() const;
387 void setBlendEnabled(bool newBlendEnabled);
388 void resetBlendEnabled();
389
390 bool usesStencilReference() const;
391 void setUsesStencilReference(bool newUsesStencilReference);
392 void resetUsesStencilReference();
393
394 bool usesScissor() const;
395 void setUsesScissor(bool newUsesScissor);
396 void resetUsesScissor();
397
398 CompareOperation depthFunction() const;
399 void setDepthFunction(CompareOperation newDepthFunction);
400 void resetDepthFunction();
401
402 CullMode cullMode() const;
403 void setCullMode(CullMode newCullMode);
404 void resetCullMode();
405
406 PolygonMode polygonMode() const;
407 void setPolygonMode(PolygonMode newPolygonMode);
408 void resetPolygonMode();
409
410 quint32 stencilWriteMask() const;
411 void setStencilWriteMask(quint32 newStencilWriteMask);
412 void resetStencilWriteMask();
413
414 quint32 stencilReference() const;
415 void setStencilReference(quint32 newStencilReference);
416 void resetStencilReference();
417
418 QRectF viewport() const;
419 void setViewport(const QRectF &newViewport);
420 void resetViewport();
421
422 QRect scissor() const;
423 void setScissor(const QRect &newScissor);
424 void resetScissor();
425
426 QQuick3DRenderPassTargetBlend targetBlend0() const;
427 void setTargetBlend0(const QQuick3DRenderPassTargetBlend &newTargetBlend0);
428 void resetTargetBlend0();
429
430 QQuick3DRenderPassTargetBlend targetBlend1() const;
431 void setTargetBlend1(const QQuick3DRenderPassTargetBlend &newTargetBlend1);
432 void resetTargetBlend1();
433
434 QQuick3DRenderPassTargetBlend targetBlend2() const;
435 void setTargetBlend2(const QQuick3DRenderPassTargetBlend &newTargetBlend2);
436 void resetTargetBlend2();
437
438 QQuick3DRenderPassTargetBlend targetBlend3() const;
439 void setTargetBlend3(const QQuick3DRenderPassTargetBlend &newTargetBlend3);
440 void resetTargetBlend3();
441
442 QQuick3DRenderPassTargetBlend targetBlend4() const;
443 void setTargetBlend4(const QQuick3DRenderPassTargetBlend &newTargetBlend4);
444 void resetTargetBlend4();
445
446 QQuick3DRenderPassTargetBlend targetBlend5() const;
447 void setTargetBlend5(const QQuick3DRenderPassTargetBlend &newTargetBlend5);
448 void resetTargetBlend5();
449
450 QQuick3DRenderPassTargetBlend targetBlend6() const;
451 void setTargetBlend6(const QQuick3DRenderPassTargetBlend &newTargetBlend6);
452 void resetTargetBlend6();
453
454 QQuick3DRenderPassTargetBlend targetBlend7() const;
455 void setTargetBlend7(const QQuick3DRenderPassTargetBlend &newTargetBlend7);
456 void resetTargetBlend7();
457
458Q_SIGNALS:
459 void depthTestEnabledChanged();
460 void depthWriteEnabledChanged();
461 void blendEnabledChanged();
462 void usesStencilReferenceChanged();
463 void usesScissorChanged();
464 void depthFunctionChanged();
465 void cullModeChanged();
466 void polygonModeChanged();
467 void stencilWriteMaskChanged();
468 void stencilReferenceChanged();
469 void viewportChanged();
470 void scissorChanged();
471 void targetBlend0Changed();
472 void targetBlend1Changed();
473 void targetBlend2Changed();
474 void targetBlend3Changed();
475 void targetBlend4Changed();
476 void targetBlend5Changed();
477 void targetBlend6Changed();
478 void targetBlend7Changed();
479
480private:
481 QSSGCommand *cloneCommand() override { return new QSSGPipelineStateOverrideCommand(command); }
482 QSSGPipelineStateOverrideCommand command { };
483};
484
485
486class Q_QUICK3D_EXPORT QQuick3DShaderUtilsApplyValue : public QQuick3DShaderUtilsRenderCommand
487{
488 Q_OBJECT
489 Q_PROPERTY(QByteArray target MEMBER target)
490 Q_PROPERTY(QVariant value MEMBER value)
491
492 QML_NAMED_ELEMENT(SetUniformValue)
493
494public:
495 QQuick3DShaderUtilsApplyValue() = default;
496 ~QQuick3DShaderUtilsApplyValue() override = default;
497 QSSGCommand *cloneCommand() override { return new QSSGApplyValue(command); }
498 QSSGApplyValue command { };
499 QVariant &value = command.m_value;
500 QByteArray &target = command.m_propertyName;
501};
502
503class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderablesFilter : public QQuick3DShaderUtilsRenderCommand
504{
505 Q_OBJECT
506
507 Q_PROPERTY(quint32 layerMask MEMBER layerMask)
508 Q_PROPERTY(RenderableTypes renderableTypes READ renderableTypes WRITE setRenderableTypes)
509 QML_NAMED_ELEMENT(RenderablesFilter)
510 QML_ADDED_IN_VERSION(6, 11)
511
512public:
513 enum class RenderableType : quint32 {
514 None = 0x0,
515 Opaque = 0x1,
516 Transparent = 0x2,
517 };
518 Q_DECLARE_FLAGS(RenderableTypes, RenderableType)
519 Q_FLAG(RenderableTypes)
520
521 QQuick3DShaderUtilsRenderablesFilter() = default;
522 ~QQuick3DShaderUtilsRenderablesFilter() override;
523
524 RenderableTypes renderableTypes() const;
525 void setRenderableTypes(RenderableTypes types);
526
527 QSSGCommand *cloneCommand() override { return new QSSGRenderablesFilterCommand(command); }
528 QSSGRenderablesFilterCommand command { };
529
530 quint32 &layerMask = command.layerMask;
531};
532
533class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassTexture : public QQuick3DObject
534{
535 Q_OBJECT
536 Q_PROPERTY(TextureFormat format READ format WRITE setFormat FINAL)
537 QML_NAMED_ELEMENT(RenderPassTexture)
538 QML_ADDED_IN_VERSION(6, 11)
539
540public:
541 enum class TextureFormat {
542 Unknown = 0,
543 RGBA8,
544 RGBA16F,
545 RGBA32F,
546 R8,
547 R16,
548 R16F,
549 R32F,
550 Depth16,
551 Depth24,
552 Depth32,
553 Depth24Stencil8,
554 };
555 Q_ENUM(TextureFormat)
556
557 QQuick3DShaderUtilsRenderPassTexture() = default;
558 ~QQuick3DShaderUtilsRenderPassTexture() override;
559
560 TextureFormat format() const;
561 void setFormat(TextureFormat newFormat);
562
563 std::shared_ptr<QSSGAllocateTexture> command;
564
565private:
566 friend class QQuick3DShaderUtilsRenderPassColorAttachment;
567 friend class QQuick3DShaderUtilsRenderPassDepthTextureAttachment;
568
569
570private:
571 static QSSGRenderTextureFormat asRenderTextureFormat(QQuick3DShaderUtilsRenderPassTexture::TextureFormat fmt);
572 static QQuick3DShaderUtilsRenderPassTexture::TextureFormat fromRenderTextureFormat(QSSGRenderTextureFormat fmt);
573};
574
575// Class for user defined color attachments in render passes
576class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassColorAttachment : public QQuick3DShaderUtilsRenderCommand
577{
578 Q_OBJECT
579 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
580 Q_PROPERTY(QByteArray name READ name WRITE setName FINAL)
581 QML_NAMED_ELEMENT(ColorAttachment)
582 QML_ADDED_IN_VERSION(6, 11)
583
584public:
585 QQuick3DShaderUtilsRenderPassColorAttachment() = default;
586 ~QQuick3DShaderUtilsRenderPassColorAttachment() override;
587
588 QByteArray name() const;
589 void setName(const QByteArray &newName);
590
591 QSSGCommand *cloneCommand() override;
592
593private:
594 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
595 QByteArray m_name;
596};
597
598class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthTextureAttachment : public QQuick3DShaderUtilsRenderCommand
599{
600 Q_OBJECT
601 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
602 QML_NAMED_ELEMENT(DepthTextureAttachment)
603 QML_ADDED_IN_VERSION(6, 11)
604
605public:
606 QQuick3DShaderUtilsRenderPassDepthTextureAttachment() = default;
607 ~QQuick3DShaderUtilsRenderPassDepthTextureAttachment() override;
608
609 QSSGCommand *cloneCommand() override;
610
611 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
612};
613
614class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthStencilAttachment : public QQuick3DShaderUtilsRenderCommand
615{
616 Q_OBJECT
617 QML_NAMED_ELEMENT(DepthStencilAttachment)
618 QML_ADDED_IN_VERSION(6, 11)
619
620public:
621 QQuick3DShaderUtilsRenderPassDepthStencilAttachment() = default;
622 ~QQuick3DShaderUtilsRenderPassDepthStencilAttachment() override;
623
624 QSSGCommand *cloneCommand() override;
625
626};
627
628class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassAddDefine : public QQuick3DShaderUtilsRenderCommand
629{
630 Q_OBJECT
631 Q_PROPERTY(QByteArray name READ name WRITE setName NOTIFY nameChanged)
632 Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged)
633 QML_NAMED_ELEMENT(AddDefine)
634 QML_ADDED_IN_VERSION(6, 11)
635
636public:
637 QQuick3DShaderUtilsRenderPassAddDefine();
638 ~QQuick3DShaderUtilsRenderPassAddDefine() override;
639
640 QSSGCommand *cloneCommand() override;
641
642 QByteArray name() const;
643 void setName(const QByteArray &newName);
644
645 int value() const;
646 void setValue(int newValue);
647
648 QSSGAddShaderDefine command;
649
650Q_SIGNALS:
651 void nameChanged();
652 void valueChanged();
653};
654
655class Q_QUICK3D_EXPORT QQuick3DShaderUtilsSubRenderPass : public QQuick3DShaderUtilsRenderCommand
656{
657 Q_OBJECT
658 Q_PROPERTY(QQuick3DRenderPass *renderPass READ renderPass WRITE setRenderPass NOTIFY renderPassChanged FINAL)
659 QML_NAMED_ELEMENT(SubRenderPass)
660 QML_ADDED_IN_VERSION(6, 11)
661
662public:
663 QQuick3DShaderUtilsSubRenderPass() = default;
664 ~QQuick3DShaderUtilsSubRenderPass() override;
665
666 QQuick3DRenderPass *renderPass() const;
667 void setRenderPass(QQuick3DRenderPass *newRenderPass);
668
669 QSSGCommand *cloneCommand() override;
670
671signals:
672 void renderPassChanged();
673
674protected:
675 virtual QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) final;
676 virtual void itemChange(ItemChange change, const ItemChangeData &value) final;
677
678private:
679 void updateSceneManager(QQuick3DSceneManager *sceneManager);
680
681 QQuick3DRenderPass *m_renderPass = nullptr;
682 mutable bool m_hasWarnedAboutInvalidId = false;
683};
684
685class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPass : public QQuick3DObject
686{
687 Q_OBJECT
688 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands READ commands)
689 Q_PROPERTY(QQuick3DShaderUtilsBuffer *output MEMBER outputBuffer)
690 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsShader> shaders READ shaders)
691 QML_NAMED_ELEMENT(Pass)
692 QML_ADDED_IN_VERSION(6, 11)
693
694public:
695 QQuick3DShaderUtilsRenderPass() = default;
696 ~QQuick3DShaderUtilsRenderPass() override;
697
698 static void qmlAppendCommand(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, QQuick3DShaderUtilsRenderCommand *command);
699 static QQuick3DShaderUtilsRenderCommand *qmlCommandAt(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, qsizetype index);
700 static qsizetype qmlCommandCount(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
701 static void qmlCommandClear(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
702
703 static void qmlAppendShader(QQmlListProperty<QQuick3DShaderUtilsShader> *list, QQuick3DShaderUtilsShader *shader);
704 static QQuick3DShaderUtilsShader *qmlShaderAt(QQmlListProperty<QQuick3DShaderUtilsShader> *list, qsizetype index);
705 static qsizetype qmlShaderCount(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
706 static void qmlShaderClear(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
707
708 QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands();
709 QVector<QQuick3DShaderUtilsRenderCommand *> m_commands;
710 QQuick3DShaderUtilsBuffer *outputBuffer = nullptr;
711 QQmlListProperty<QQuick3DShaderUtilsShader> shaders();
712 QVarLengthArray<QQuick3DShaderUtilsShader *, 2> m_shaders;
713
714Q_SIGNALS:
715 void changed();
716};
717
718class Q_QUICK3D_EXPORT QQuick3DShaderUtilsShader : public QQuick3DObject
719{
720 Q_OBJECT
721 Q_PROPERTY(QUrl shader MEMBER shader NOTIFY shaderChanged)
722 Q_PROPERTY(Stage stage MEMBER stage NOTIFY stageChanged)
723
724 QML_NAMED_ELEMENT(Shader)
725
726public:
727 QQuick3DShaderUtilsShader() = default;
728 virtual ~QQuick3DShaderUtilsShader() = default;
729 enum class Stage : quint8
730 {
731 Vertex = 0,
732 Fragment = 1
733 };
734 Q_ENUM(Stage)
735
736 QUrl shader;
737 Stage stage = Stage::Fragment;
738
739Q_SIGNALS:
740 void shaderChanged();
741 void stageChanged();
742};
743
744template<typename T, typename std::enable_if_t<std::is_base_of_v<QQuick3DObject, T>, bool> = true>
745class QQuick3DSuperClassInfo
746{
747public:
748 QQuick3DSuperClassInfo() = default;
749
750 static const char *superClassName()
751 {
752 return T::staticMetaObject.className();
753 }
754};
755
756class QQuick3DPropertyChangedTracker;
757
759{
761public:
763
764public Q_SLOTS:
767
768private:
769 QQuick3DPropertyChangedTracker *m_tracker = nullptr;
770 QMetaProperty m_property;
771};
772
773class Q_QUICK3D_EXPORT QQuick3DPropertyChangedTracker
774{
775public:
776 enum class DirtyPropertyHint
777 {
778 Value,
779 Reference,
780 };
781
782 template<typename T>
783 explicit QQuick3DPropertyChangedTracker(QQuick3DObject *owner, QQuick3DSuperClassInfo<T> info)
784 : m_owner(owner)
785 , m_superClassName(info.superClassName())
786 {
787 Q_ASSERT(m_owner != nullptr);
788 }
789 virtual ~QQuick3DPropertyChangedTracker();
790
791 using UniformProperty = QSSGUserShaderAugmentation::Property;
792 using UniformPropertyList = QVector<UniformProperty>;
793protected:
794 friend class QQuick3DPropertyWatcher;
795
796 // Will re-use already extracted list and update dirty properties
797 QList<UniformProperty> extractProperties();
798
799 void addPropertyWatcher(QMetaProperty property, DirtyPropertyHint hint, QQuick3DObject *object = nullptr);
800
801 virtual void markTrackedPropertyDirty(QMetaProperty property, DirtyPropertyHint hint) = 0;
802
803 struct Tracked
804 {
805 QQuick3DPropertyWatcher *watcher = nullptr;
806 QPointer<QQuick3DObject> object;
807 int pid = -1;
808 };
809
810 QHash<int, Tracked> m_trackedProperties;
811 QQuick3DObject *m_owner = nullptr;
812 const char *m_superClassName = nullptr;
813 QList<UniformProperty> m_propertyList; // always sorted by propertyIndex
814
815private:
816 std::optional<UniformProperty> createOrUpdateTrackedProperty(const QMetaProperty property, bool addWatchers);
817 std::vector<int> m_dirtyProperties;
818 bool m_extracted = false;
819};
820
821QT_END_NAMESPACE
822
823Q_DECLARE_OPAQUE_POINTER(QQuick3DShaderUtilsTextureInput)
824
825#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)
Combined button and popup list for selecting options.