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};
170
171class Q_QUICK3D_EXPORT QQuick3DShaderUtilsBufferInput : public QQuick3DShaderUtilsRenderCommand
172{
173 Q_OBJECT
174 Q_PROPERTY(QQuick3DShaderUtilsBuffer *buffer READ buffer WRITE setBuffer)
175 Q_PROPERTY(QByteArray sampler MEMBER sampler)
176
177 QML_NAMED_ELEMENT(BufferInput)
178
179public:
180 QQuick3DShaderUtilsBufferInput() = default;
181 ~QQuick3DShaderUtilsBufferInput() override = default;
182 QSSGApplyBufferValue command { QByteArray(), QByteArray() };
183 QByteArray &sampler = command.m_samplerName;
184 QSSGCommand *cloneCommand() override { return new QSSGApplyBufferValue(command); }
185
186 int bufferCount() const override { return (m_buffer != nullptr) ? 1 : 0; }
187 QQuick3DShaderUtilsBuffer *bufferAt(int idx) const override
188 {
189 Q_ASSERT(idx < 1 && idx >= 0);
190 return (m_buffer && idx == 0) ? m_buffer : nullptr;
191 }
192
193 QQuick3DShaderUtilsBuffer *buffer() const { return m_buffer; }
194 void setBuffer(QQuick3DShaderUtilsBuffer *buffer) {
195 if (m_buffer == buffer)
196 return;
197
198 if (buffer) {
199 Q_ASSERT(!buffer->name.isEmpty());
200 command.m_bufferName = buffer->name;
201 }
202 m_buffer = buffer;
203 }
204
205 QQuick3DShaderUtilsBuffer *m_buffer = nullptr;
206
207};
208
209class Q_QUICK3D_EXPORT QQuick3DRenderPassTargetBlend
210{
211 Q_GADGET
212 Q_PROPERTY(bool enable MEMBER enable)
213 Q_PROPERTY(ColorMask colorWrite MEMBER colorWrite)
214 Q_PROPERTY(BlendFactor srcColor MEMBER srcColor)
215 Q_PROPERTY(BlendFactor dstColor MEMBER dstColor)
216 Q_PROPERTY(BlendOperation opColor MEMBER opColor)
217 Q_PROPERTY(BlendFactor srcAlpha MEMBER srcAlpha)
218 Q_PROPERTY(BlendFactor dstAlpha MEMBER dstAlpha)
219 Q_PROPERTY(BlendOperation opAlpha MEMBER opAlpha)
220 QML_VALUE_TYPE(renderTargetBlend)
221 QML_ADDED_IN_VERSION(6, 11)
222
223public:
224 enum ColorMaskComponent : quint32 {
225 R = 1 << 0,
226 G = 1 << 1,
227 B = 1 << 2,
228 A = 1 << 3,
229 };
230 Q_DECLARE_FLAGS(ColorMask, ColorMaskComponent)
231
232 enum class BlendFactor {
233 Zero,
234 One,
235 SrcColor,
236 OneMinusSrcColor,
237 DstColor,
238 OneMinusDstColor,
239 SrcAlpha,
240 OneMinusSrcAlpha,
241 DstAlpha,
242 OneMinusDstAlpha,
243 ConstantColor,
244 OneMinusConstantColor,
245 ConstantAlpha,
246 OneMinusConstantAlpha,
247 SrcAlphaSaturate,
248 Src1Color,
249 OneMinusSrc1Color,
250 Src1Alpha,
251 OneMinusSrc1Alpha
252 };
253 Q_ENUM(BlendFactor)
254
255 enum class BlendOperation {
256 Add,
257 Subtract,
258 ReverseSubtract,
259 Min,
260 Max
261 };
262 Q_ENUM(BlendOperation)
263
264 ColorMask colorWrite = ColorMask(0xF); // R | G | B | A
265 bool enable = false;
266 BlendFactor srcColor = BlendFactor::One;
267 BlendFactor dstColor = BlendFactor::OneMinusSrcAlpha;
268 BlendOperation opColor = BlendOperation::Add;
269 BlendFactor srcAlpha = BlendFactor::One;
270 BlendFactor dstAlpha = BlendFactor::OneMinusSrcAlpha;
271 BlendOperation opAlpha = BlendOperation::Add;
272
273 bool operator==(const QQuick3DRenderPassTargetBlend &other) const
274 {
275 return colorWrite == other.colorWrite
276 && enable == other.enable
277 && srcColor == other.srcColor
278 && dstColor == other.dstColor
279 && opColor == other.opColor
280 && srcAlpha == other.srcAlpha
281 && dstAlpha == other.dstAlpha
282 && opAlpha == other.opAlpha;
283 }
284
285 QQuick3DRenderPassTargetBlend() = default;
286 QQuick3DRenderPassTargetBlend(QRhiGraphicsPipeline::TargetBlend targetBlend)
287 : colorWrite(ColorMask(targetBlend.colorWrite.toInt()))
288 , enable(targetBlend.enable)
289 , srcColor(BlendFactor(targetBlend.srcColor))
290 , dstColor(BlendFactor(targetBlend.dstColor))
291 , opColor(BlendOperation(targetBlend.opColor))
292 , srcAlpha(BlendFactor(targetBlend.srcAlpha))
293 , dstAlpha(BlendFactor(targetBlend.dstAlpha))
294 , opAlpha(BlendOperation(targetBlend.opAlpha))
295 {
296 }
297
298 QRhiGraphicsPipeline::TargetBlend toRhiTargetBlend() const
299 {
300 QRhiGraphicsPipeline::TargetBlend tb;
301 tb.colorWrite = QRhiGraphicsPipeline::ColorMask(colorWrite.toInt());
302 tb.enable = enable;
303 tb.srcColor = QRhiGraphicsPipeline::BlendFactor(int(srcColor));
304 tb.dstColor = QRhiGraphicsPipeline::BlendFactor(int(dstColor));
305 tb.opColor = QRhiGraphicsPipeline::BlendOp(int(opColor));
306 tb.srcAlpha = QRhiGraphicsPipeline::BlendFactor(int(srcAlpha));
307 tb.dstAlpha = QRhiGraphicsPipeline::BlendFactor(int(dstAlpha));
308 tb.opAlpha = QRhiGraphicsPipeline::BlendOp(int(opAlpha));
309 return tb;
310 }
311};
312
320
321class Q_QUICK3D_EXPORT QQuick3DShaderUtilsPipelineStateOverride : public QQuick3DShaderUtilsRenderCommand
322{
323 Q_OBJECT
324 Q_PROPERTY(bool depthTestEnabled READ depthTestEnabled WRITE setDepthTestEnabled RESET resetDepthTestEnabled NOTIFY depthTestEnabledChanged)
325 Q_PROPERTY(bool depthWriteEnabled READ depthWriteEnabled WRITE setDepthWriteEnabled RESET resetDepthWriteEnabled NOTIFY depthWriteEnabledChanged)
326 Q_PROPERTY(bool blendEnabled READ blendEnabled WRITE setBlendEnabled RESET resetBlendEnabled NOTIFY blendEnabledChanged FINAL)
327 Q_PROPERTY(bool usesStencilReference READ usesStencilReference WRITE setUsesStencilReference RESET resetUsesStencilReference NOTIFY usesStencilReferenceChanged)
328 Q_PROPERTY(bool usesScissor READ usesScissor WRITE setUsesScissor RESET resetUsesScissor NOTIFY usesScissorChanged)
329 Q_PROPERTY(CompareOperation depthFunction READ depthFunction WRITE setDepthFunction RESET resetDepthFunction NOTIFY depthFunctionChanged)
330 Q_PROPERTY(CullMode cullMode READ cullMode WRITE setCullMode RESET resetCullMode NOTIFY cullModeChanged)
331 Q_PROPERTY(PolygonMode polygonMode READ polygonMode WRITE setPolygonMode RESET resetPolygonMode NOTIFY polygonModeChanged)
332 Q_PROPERTY(quint32 stencilWriteMask READ stencilWriteMask WRITE setStencilWriteMask RESET resetStencilWriteMask NOTIFY stencilWriteMaskChanged)
333 Q_PROPERTY(quint32 stencilReference READ stencilReference WRITE setStencilReference RESET resetStencilReference NOTIFY stencilReferenceChanged)
334 Q_PROPERTY(QRectF viewport READ viewport WRITE setViewport RESET resetViewport NOTIFY viewportChanged)
335 Q_PROPERTY(QRect scissor READ scissor WRITE setScissor RESET resetScissor NOTIFY scissorChanged)
336 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend0 READ targetBlend0 WRITE setTargetBlend0 RESET resetTargetBlend0 NOTIFY targetBlend0Changed)
337 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend1 READ targetBlend1 WRITE setTargetBlend1 RESET resetTargetBlend1 NOTIFY targetBlend1Changed)
338 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend2 READ targetBlend2 WRITE setTargetBlend2 RESET resetTargetBlend2 NOTIFY targetBlend2Changed)
339 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend3 READ targetBlend3 WRITE setTargetBlend3 RESET resetTargetBlend3 NOTIFY targetBlend3Changed)
340 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend4 READ targetBlend4 WRITE setTargetBlend4 RESET resetTargetBlend4 NOTIFY targetBlend4Changed)
341 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend5 READ targetBlend5 WRITE setTargetBlend5 RESET resetTargetBlend5 NOTIFY targetBlend5Changed)
342 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend6 READ targetBlend6 WRITE setTargetBlend6 RESET resetTargetBlend6 NOTIFY targetBlend6Changed)
343 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend7 READ targetBlend7 WRITE setTargetBlend7 RESET resetTargetBlend7 NOTIFY targetBlend7Changed)
344 QML_NAMED_ELEMENT(PipelineStateOverride)
345 QML_ADDED_IN_VERSION(6, 11)
346
347public:
348 enum class CompareOperation {
349 Never,
350 Less,
351 Equal,
352 LessOrEqual,
353 Greater,
354 NotEqual,
355 GreaterOrEqual,
356 Always
357 };
358 Q_ENUM(CompareOperation)
359
360 enum class CullMode {
361 None,
362 Front,
363 Back
364 };
365 Q_ENUM(CullMode)
366
367 enum class PolygonMode {
368 Fill,
369 Line
370 };
371 Q_ENUM(PolygonMode)
372
373 QQuick3DShaderUtilsPipelineStateOverride() = default;
374 ~QQuick3DShaderUtilsPipelineStateOverride() override;
375
376 bool depthTestEnabled() const;
377 void setDepthTestEnabled(bool newDepthTestEnabled);
378 void resetDepthTestEnabled();
379 bool depthWriteEnabled() const;
380 void setDepthWriteEnabled(bool newDepthWriteEnabled);
381 void resetDepthWriteEnabled();
382
383 bool blendEnabled() const;
384 void setBlendEnabled(bool newBlendEnabled);
385 void resetBlendEnabled();
386
387 bool usesStencilReference() const;
388 void setUsesStencilReference(bool newUsesStencilReference);
389 void resetUsesStencilReference();
390
391 bool usesScissor() const;
392 void setUsesScissor(bool newUsesScissor);
393 void resetUsesScissor();
394
395 CompareOperation depthFunction() const;
396 void setDepthFunction(CompareOperation newDepthFunction);
397 void resetDepthFunction();
398
399 CullMode cullMode() const;
400 void setCullMode(CullMode newCullMode);
401 void resetCullMode();
402
403 PolygonMode polygonMode() const;
404 void setPolygonMode(PolygonMode newPolygonMode);
405 void resetPolygonMode();
406
407 quint32 stencilWriteMask() const;
408 void setStencilWriteMask(quint32 newStencilWriteMask);
409 void resetStencilWriteMask();
410
411 quint32 stencilReference() const;
412 void setStencilReference(quint32 newStencilReference);
413 void resetStencilReference();
414
415 QRectF viewport() const;
416 void setViewport(const QRectF &newViewport);
417 void resetViewport();
418
419 QRect scissor() const;
420 void setScissor(const QRect &newScissor);
421 void resetScissor();
422
423 QQuick3DRenderPassTargetBlend targetBlend0() const;
424 void setTargetBlend0(const QQuick3DRenderPassTargetBlend &newTargetBlend0);
425 void resetTargetBlend0();
426
427 QQuick3DRenderPassTargetBlend targetBlend1() const;
428 void setTargetBlend1(const QQuick3DRenderPassTargetBlend &newTargetBlend1);
429 void resetTargetBlend1();
430
431 QQuick3DRenderPassTargetBlend targetBlend2() const;
432 void setTargetBlend2(const QQuick3DRenderPassTargetBlend &newTargetBlend2);
433 void resetTargetBlend2();
434
435 QQuick3DRenderPassTargetBlend targetBlend3() const;
436 void setTargetBlend3(const QQuick3DRenderPassTargetBlend &newTargetBlend3);
437 void resetTargetBlend3();
438
439 QQuick3DRenderPassTargetBlend targetBlend4() const;
440 void setTargetBlend4(const QQuick3DRenderPassTargetBlend &newTargetBlend4);
441 void resetTargetBlend4();
442
443 QQuick3DRenderPassTargetBlend targetBlend5() const;
444 void setTargetBlend5(const QQuick3DRenderPassTargetBlend &newTargetBlend5);
445 void resetTargetBlend5();
446
447 QQuick3DRenderPassTargetBlend targetBlend6() const;
448 void setTargetBlend6(const QQuick3DRenderPassTargetBlend &newTargetBlend6);
449 void resetTargetBlend6();
450
451 QQuick3DRenderPassTargetBlend targetBlend7() const;
452 void setTargetBlend7(const QQuick3DRenderPassTargetBlend &newTargetBlend7);
453 void resetTargetBlend7();
454
455Q_SIGNALS:
456 void depthTestEnabledChanged();
457 void depthWriteEnabledChanged();
458 void blendEnabledChanged();
459 void usesStencilReferenceChanged();
460 void usesScissorChanged();
461 void depthFunctionChanged();
462 void cullModeChanged();
463 void polygonModeChanged();
464 void stencilWriteMaskChanged();
465 void stencilReferenceChanged();
466 void viewportChanged();
467 void scissorChanged();
468 void targetBlend0Changed();
469 void targetBlend1Changed();
470 void targetBlend2Changed();
471 void targetBlend3Changed();
472 void targetBlend4Changed();
473 void targetBlend5Changed();
474 void targetBlend6Changed();
475 void targetBlend7Changed();
476
477private:
478 QSSGCommand *cloneCommand() override { return new QSSGPipelineStateOverrideCommand(command); }
479 QSSGPipelineStateOverrideCommand command { };
480};
481
482
483class Q_QUICK3D_EXPORT QQuick3DShaderUtilsApplyValue : public QQuick3DShaderUtilsRenderCommand
484{
485 Q_OBJECT
486 Q_PROPERTY(QByteArray target MEMBER target)
487 Q_PROPERTY(QVariant value MEMBER value)
488
489 QML_NAMED_ELEMENT(SetUniformValue)
490
491public:
492 QQuick3DShaderUtilsApplyValue() = default;
493 ~QQuick3DShaderUtilsApplyValue() override = default;
494 QSSGCommand *cloneCommand() override { return new QSSGApplyValue(command); }
495 QSSGApplyValue command { };
496 QVariant &value = command.m_value;
497 QByteArray &target = command.m_propertyName;
498};
499
500class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderablesFilter : public QQuick3DShaderUtilsRenderCommand
501{
502 Q_OBJECT
503
504 Q_PROPERTY(quint32 layerMask MEMBER layerMask)
505 Q_PROPERTY(RenderableTypes renderableTypes READ renderableTypes WRITE setRenderableTypes)
506 QML_NAMED_ELEMENT(RenderablesFilter)
507 QML_ADDED_IN_VERSION(6, 11)
508
509public:
510 enum class RenderableType : quint32 {
511 None = 0x0,
512 Opaque = 0x1,
513 Transparent = 0x2,
514 };
515 Q_DECLARE_FLAGS(RenderableTypes, RenderableType)
516 Q_FLAG(RenderableTypes)
517
518 QQuick3DShaderUtilsRenderablesFilter() = default;
519 ~QQuick3DShaderUtilsRenderablesFilter() override;
520
521 RenderableTypes renderableTypes() const;
522 void setRenderableTypes(RenderableTypes types);
523
524 QSSGCommand *cloneCommand() override { return new QSSGRenderablesFilterCommand(command); }
525 QSSGRenderablesFilterCommand command { };
526
527 quint32 &layerMask = command.layerMask;
528};
529
530class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassTexture : public QQuick3DObject
531{
532 Q_OBJECT
533 Q_PROPERTY(TextureFormat format READ format WRITE setFormat FINAL)
534 QML_NAMED_ELEMENT(RenderPassTexture)
535 QML_ADDED_IN_VERSION(6, 11)
536
537public:
538 enum class TextureFormat {
539 Unknown = 0,
540 RGBA8,
541 RGBA16F,
542 RGBA32F,
543 R8,
544 R16,
545 R16F,
546 R32F,
547 Depth16,
548 Depth24,
549 Depth32,
550 Depth24Stencil8,
551 };
552 Q_ENUM(TextureFormat)
553
554 QQuick3DShaderUtilsRenderPassTexture() = default;
555 ~QQuick3DShaderUtilsRenderPassTexture() override;
556
557 TextureFormat format() const;
558 void setFormat(TextureFormat newFormat);
559
560 std::shared_ptr<QSSGAllocateTexture> command;
561
562private:
563 friend class QQuick3DShaderUtilsRenderPassColorAttachment;
564 friend class QQuick3DShaderUtilsRenderPassDepthTextureAttachment;
565
566
567private:
568 static QSSGRenderTextureFormat asRenderTextureFormat(QQuick3DShaderUtilsRenderPassTexture::TextureFormat fmt);
569 static QQuick3DShaderUtilsRenderPassTexture::TextureFormat fromRenderTextureFormat(QSSGRenderTextureFormat fmt);
570};
571
572// Class for user defined color attachments in render passes
573class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassColorAttachment : public QQuick3DShaderUtilsRenderCommand
574{
575 Q_OBJECT
576 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
577 Q_PROPERTY(QByteArray name READ name WRITE setName FINAL)
578 QML_NAMED_ELEMENT(ColorAttachment)
579 QML_ADDED_IN_VERSION(6, 11)
580
581public:
582 QQuick3DShaderUtilsRenderPassColorAttachment() = default;
583 ~QQuick3DShaderUtilsRenderPassColorAttachment() override;
584
585 QByteArray name() const;
586 void setName(const QByteArray &newName);
587
588 QSSGCommand *cloneCommand() override;
589
590private:
591 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
592 QByteArray m_name;
593};
594
595class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthTextureAttachment : public QQuick3DShaderUtilsRenderCommand
596{
597 Q_OBJECT
598 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
599 QML_NAMED_ELEMENT(DepthTextureAttachment)
600 QML_ADDED_IN_VERSION(6, 11)
601
602public:
603 QQuick3DShaderUtilsRenderPassDepthTextureAttachment() = default;
604 ~QQuick3DShaderUtilsRenderPassDepthTextureAttachment() override;
605
606 QSSGCommand *cloneCommand() override;
607
608 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
609};
610
611class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthStencilAttachment : public QQuick3DShaderUtilsRenderCommand
612{
613 Q_OBJECT
614 QML_NAMED_ELEMENT(DepthStencilAttachment)
615 QML_ADDED_IN_VERSION(6, 11)
616
617public:
618 QQuick3DShaderUtilsRenderPassDepthStencilAttachment() = default;
619 ~QQuick3DShaderUtilsRenderPassDepthStencilAttachment() override;
620
621 QSSGCommand *cloneCommand() override;
622
623};
624
625class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassAddDefine : public QQuick3DShaderUtilsRenderCommand
626{
627 Q_OBJECT
628 Q_PROPERTY(QByteArray name MEMBER name)
629 Q_PROPERTY(int value MEMBER value)
630 QML_NAMED_ELEMENT(AddDefine)
631 QML_ADDED_IN_VERSION(6, 11)
632
633public:
634 QQuick3DShaderUtilsRenderPassAddDefine();
635 ~QQuick3DShaderUtilsRenderPassAddDefine() override;
636
637 QSSGCommand *cloneCommand() override;
638
639 QSSGAddShaderDefine command;
640 QByteArray &name = command.m_name;
641 int &value = command.m_value;
642};
643
644class Q_QUICK3D_EXPORT QQuick3DShaderUtilsSubRenderPass : public QQuick3DShaderUtilsRenderCommand
645{
646 Q_OBJECT
647 Q_PROPERTY(QQuick3DRenderPass *renderPass READ renderPass WRITE setRenderPass NOTIFY renderPassChanged FINAL)
648 QML_NAMED_ELEMENT(SubRenderPass)
649 QML_ADDED_IN_VERSION(6, 11)
650
651public:
652 QQuick3DShaderUtilsSubRenderPass() = default;
653 ~QQuick3DShaderUtilsSubRenderPass() override;
654
655 QQuick3DRenderPass *renderPass() const;
656 void setRenderPass(QQuick3DRenderPass *newRenderPass);
657
658 QSSGCommand *cloneCommand() override;
659
660signals:
661 void renderPassChanged();
662
663protected:
664 virtual QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) final;
665 virtual void itemChange(ItemChange change, const ItemChangeData &value) final;
666
667private:
668 void updateSceneManager(QQuick3DSceneManager *sceneManager);
669
670 QQuick3DRenderPass *m_renderPass = nullptr;
671 mutable bool m_hasWarnedAboutInvalidId = false;
672};
673
674class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPass : public QQuick3DObject
675{
676 Q_OBJECT
677 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands READ commands)
678 Q_PROPERTY(QQuick3DShaderUtilsBuffer *output MEMBER outputBuffer)
679 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsShader> shaders READ shaders)
680 QML_NAMED_ELEMENT(Pass)
681 QML_ADDED_IN_VERSION(6, 11)
682
683public:
684 QQuick3DShaderUtilsRenderPass() = default;
685 ~QQuick3DShaderUtilsRenderPass() override;
686
687 static void qmlAppendCommand(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, QQuick3DShaderUtilsRenderCommand *command);
688 static QQuick3DShaderUtilsRenderCommand *qmlCommandAt(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, qsizetype index);
689 static qsizetype qmlCommandCount(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
690 static void qmlCommandClear(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
691
692 static void qmlAppendShader(QQmlListProperty<QQuick3DShaderUtilsShader> *list, QQuick3DShaderUtilsShader *shader);
693 static QQuick3DShaderUtilsShader *qmlShaderAt(QQmlListProperty<QQuick3DShaderUtilsShader> *list, qsizetype index);
694 static qsizetype qmlShaderCount(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
695 static void qmlShaderClear(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
696
697 QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands();
698 QVector<QQuick3DShaderUtilsRenderCommand *> m_commands;
699 QQuick3DShaderUtilsBuffer *outputBuffer = nullptr;
700 QQmlListProperty<QQuick3DShaderUtilsShader> shaders();
701 QVarLengthArray<QQuick3DShaderUtilsShader *, 2> m_shaders;
702
703Q_SIGNALS:
704 void changed();
705};
706
707class Q_QUICK3D_EXPORT QQuick3DShaderUtilsShader : public QQuick3DObject
708{
709 Q_OBJECT
710 Q_PROPERTY(QUrl shader MEMBER shader NOTIFY shaderChanged)
711 Q_PROPERTY(Stage stage MEMBER stage NOTIFY stageChanged)
712
713 QML_NAMED_ELEMENT(Shader)
714
715public:
716 QQuick3DShaderUtilsShader() = default;
717 virtual ~QQuick3DShaderUtilsShader() = default;
718 enum class Stage : quint8
719 {
720 Vertex = 0,
721 Fragment = 1
722 };
723 Q_ENUM(Stage)
724
725 QUrl shader;
726 Stage stage = Stage::Fragment;
727
728Q_SIGNALS:
729 void shaderChanged();
730 void stageChanged();
731};
732
733template<typename T, typename std::enable_if_t<std::is_base_of_v<QQuick3DObject, T>, bool> = true>
734class QQuick3DSuperClassInfo
735{
736public:
737 QQuick3DSuperClassInfo() = default;
738
739 static const char *superClassName()
740 {
741 return T::staticMetaObject.className();
742 }
743};
744
746
748{
750public:
752
753public Q_SLOTS:
756
757private:
758 QQuick3DPropertyChangedTracker *m_tracker = nullptr;
759 QMetaProperty m_property;
760};
761
763{
764public:
766 {
769 };
770
771 template<typename T>
772 explicit QQuick3DPropertyChangedTracker(QQuick3DObject *owner, QQuick3DSuperClassInfo<T> info)
773 : m_owner(owner)
774 , m_superClassName(info.superClassName())
775 {
776 Q_ASSERT(m_owner != nullptr);
777 }
779
782protected:
784
785 void extractProperties(UniformPropertyList &outUniforms);
786
787 void addPropertyWatcher(QMetaProperty property, DirtyPropertyHint hint, QQuick3DObject *object = nullptr);
788
789 virtual void markTrackedPropertyDirty(QMetaProperty property, DirtyPropertyHint hint) = 0;
790
797
801 const char *m_superClassName = nullptr;
802};
803
804QT_END_NAMESPACE
805
806Q_DECLARE_OPAQUE_POINTER(QQuick3DShaderUtilsTextureInput)
807
808#endif // QQUICK3DSHADERUTILS_H
void extractProperties(UniformPropertyList &outUniforms)
void addPropertyWatcher(QMetaProperty property, DirtyPropertyHint hint, QQuick3DObject *object=nullptr)
QQuick3DPropertyChangedTracker(QQuick3DObject *owner, QQuick3DSuperClassInfo< T > info)
virtual void markTrackedPropertyDirty(QMetaProperty property, DirtyPropertyHint hint)=0
\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.