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
313class Q_QUICK3D_EXPORT QQuick3DShaderUtilsPipelineStateOverride : public QQuick3DShaderUtilsRenderCommand
314{
315 Q_OBJECT
316 Q_PROPERTY(bool depthTestEnabled READ depthTestEnabled WRITE setDepthTestEnabled RESET resetDepthTestEnabled NOTIFY depthTestEnabledChanged)
317 Q_PROPERTY(bool depthWriteEnabled READ depthWriteEnabled WRITE setDepthWriteEnabled RESET resetDepthWriteEnabled NOTIFY depthWriteEnabledChanged)
318 Q_PROPERTY(bool blendEnabled READ blendEnabled WRITE setBlendEnabled RESET resetBlendEnabled NOTIFY blendEnabledChanged FINAL)
319 Q_PROPERTY(bool usesStencilReference READ usesStencilReference WRITE setUsesStencilReference RESET resetUsesStencilReference NOTIFY usesStencilReferenceChanged)
320 Q_PROPERTY(bool usesScissor READ usesScissor WRITE setUsesScissor RESET resetUsesScissor NOTIFY usesScissorChanged)
321 Q_PROPERTY(CompareOperation depthFunction READ depthFunction WRITE setDepthFunction RESET resetDepthFunction NOTIFY depthFunctionChanged)
322 Q_PROPERTY(CullMode cullMode READ cullMode WRITE setCullMode RESET resetCullMode NOTIFY cullModeChanged)
323 Q_PROPERTY(PolygonMode polygonMode READ polygonMode WRITE setPolygonMode RESET resetPolygonMode NOTIFY polygonModeChanged)
324 Q_PROPERTY(quint32 stencilWriteMask READ stencilWriteMask WRITE setStencilWriteMask RESET resetStencilWriteMask NOTIFY stencilWriteMaskChanged)
325 Q_PROPERTY(quint32 stencilReference READ stencilReference WRITE setStencilReference RESET resetStencilReference NOTIFY stencilReferenceChanged)
326 Q_PROPERTY(QRectF viewport READ viewport WRITE setViewport RESET resetViewport NOTIFY viewportChanged)
327 Q_PROPERTY(QRect scissor READ scissor WRITE setScissor RESET resetScissor NOTIFY scissorChanged)
328 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend0 READ targetBlend0 WRITE setTargetBlend0 RESET resetTargetBlend0 NOTIFY targetBlend0Changed)
329 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend1 READ targetBlend1 WRITE setTargetBlend1 RESET resetTargetBlend1 NOTIFY targetBlend1Changed)
330 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend2 READ targetBlend2 WRITE setTargetBlend2 RESET resetTargetBlend2 NOTIFY targetBlend2Changed)
331 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend3 READ targetBlend3 WRITE setTargetBlend3 RESET resetTargetBlend3 NOTIFY targetBlend3Changed)
332 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend4 READ targetBlend4 WRITE setTargetBlend4 RESET resetTargetBlend4 NOTIFY targetBlend4Changed)
333 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend5 READ targetBlend5 WRITE setTargetBlend5 RESET resetTargetBlend5 NOTIFY targetBlend5Changed)
334 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend6 READ targetBlend6 WRITE setTargetBlend6 RESET resetTargetBlend6 NOTIFY targetBlend6Changed)
335 Q_PROPERTY(QQuick3DRenderPassTargetBlend targetBlend7 READ targetBlend7 WRITE setTargetBlend7 RESET resetTargetBlend7 NOTIFY targetBlend7Changed)
336 QML_NAMED_ELEMENT(PipelineStateOverride)
337 QML_ADDED_IN_VERSION(6, 11)
338
339public:
340 enum class CompareOperation {
341 Never,
342 Less,
343 Equal,
344 LessOrEqual,
345 Greater,
346 NotEqual,
347 GreaterOrEqual,
348 Always
349 };
350 Q_ENUM(CompareOperation)
351
352 enum class CullMode {
353 None,
354 Front,
355 Back
356 };
357 Q_ENUM(CullMode)
358
359 enum class PolygonMode {
360 Fill,
361 Line
362 };
363 Q_ENUM(PolygonMode)
364
365 QQuick3DShaderUtilsPipelineStateOverride() = default;
366 ~QQuick3DShaderUtilsPipelineStateOverride() override;
367
368 bool depthTestEnabled() const;
369 void setDepthTestEnabled(bool newDepthTestEnabled);
370 void resetDepthTestEnabled();
371 bool depthWriteEnabled() const;
372 void setDepthWriteEnabled(bool newDepthWriteEnabled);
373 void resetDepthWriteEnabled();
374
375 bool blendEnabled() const;
376 void setBlendEnabled(bool newBlendEnabled);
377 void resetBlendEnabled();
378
379 bool usesStencilReference() const;
380 void setUsesStencilReference(bool newUsesStencilReference);
381 void resetUsesStencilReference();
382
383 bool usesScissor() const;
384 void setUsesScissor(bool newUsesScissor);
385 void resetUsesScissor();
386
387 CompareOperation depthFunction() const;
388 void setDepthFunction(CompareOperation newDepthFunction);
389 void resetDepthFunction();
390
391 CullMode cullMode() const;
392 void setCullMode(CullMode newCullMode);
393 void resetCullMode();
394
395 PolygonMode polygonMode() const;
396 void setPolygonMode(PolygonMode newPolygonMode);
397 void resetPolygonMode();
398
399 quint32 stencilWriteMask() const;
400 void setStencilWriteMask(quint32 newStencilWriteMask);
401 void resetStencilWriteMask();
402
403 quint32 stencilReference() const;
404 void setStencilReference(quint32 newStencilReference);
405 void resetStencilReference();
406
407 QRectF viewport() const;
408 void setViewport(const QRectF &newViewport);
409 void resetViewport();
410
411 QRect scissor() const;
412 void setScissor(const QRect &newScissor);
413 void resetScissor();
414
415 QQuick3DRenderPassTargetBlend targetBlend0() const;
416 void setTargetBlend0(const QQuick3DRenderPassTargetBlend &newTargetBlend0);
417 void resetTargetBlend0();
418
419 QQuick3DRenderPassTargetBlend targetBlend1() const;
420 void setTargetBlend1(const QQuick3DRenderPassTargetBlend &newTargetBlend1);
421 void resetTargetBlend1();
422
423 QQuick3DRenderPassTargetBlend targetBlend2() const;
424 void setTargetBlend2(const QQuick3DRenderPassTargetBlend &newTargetBlend2);
425 void resetTargetBlend2();
426
427 QQuick3DRenderPassTargetBlend targetBlend3() const;
428 void setTargetBlend3(const QQuick3DRenderPassTargetBlend &newTargetBlend3);
429 void resetTargetBlend3();
430
431 QQuick3DRenderPassTargetBlend targetBlend4() const;
432 void setTargetBlend4(const QQuick3DRenderPassTargetBlend &newTargetBlend4);
433 void resetTargetBlend4();
434
435 QQuick3DRenderPassTargetBlend targetBlend5() const;
436 void setTargetBlend5(const QQuick3DRenderPassTargetBlend &newTargetBlend5);
437 void resetTargetBlend5();
438
439 QQuick3DRenderPassTargetBlend targetBlend6() const;
440 void setTargetBlend6(const QQuick3DRenderPassTargetBlend &newTargetBlend6);
441 void resetTargetBlend6();
442
443 QQuick3DRenderPassTargetBlend targetBlend7() const;
444 void setTargetBlend7(const QQuick3DRenderPassTargetBlend &newTargetBlend7);
445 void resetTargetBlend7();
446
447Q_SIGNALS:
448 void depthTestEnabledChanged();
449 void depthWriteEnabledChanged();
450 void blendEnabledChanged();
451 void usesStencilReferenceChanged();
452 void usesScissorChanged();
453 void depthFunctionChanged();
454 void cullModeChanged();
455 void polygonModeChanged();
456 void stencilWriteMaskChanged();
457 void stencilReferenceChanged();
458 void viewportChanged();
459 void scissorChanged();
460 void targetBlend0Changed();
461 void targetBlend1Changed();
462 void targetBlend2Changed();
463 void targetBlend3Changed();
464 void targetBlend4Changed();
465 void targetBlend5Changed();
466 void targetBlend6Changed();
467 void targetBlend7Changed();
468
469private:
470 QSSGCommand *cloneCommand() override { return new QSSGPipelineStateOverrideCommand(command); }
471 QSSGPipelineStateOverrideCommand command { };
472};
473
474
475class Q_QUICK3D_EXPORT QQuick3DShaderUtilsApplyValue : public QQuick3DShaderUtilsRenderCommand
476{
477 Q_OBJECT
478 Q_PROPERTY(QByteArray target MEMBER target)
479 Q_PROPERTY(QVariant value MEMBER value)
480
481 QML_NAMED_ELEMENT(SetUniformValue)
482
483public:
484 QQuick3DShaderUtilsApplyValue() = default;
485 ~QQuick3DShaderUtilsApplyValue() override = default;
486 QSSGCommand *cloneCommand() override { return new QSSGApplyValue(command); }
487 QSSGApplyValue command { };
488 QVariant &value = command.m_value;
489 QByteArray &target = command.m_propertyName;
490};
491
492class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderablesFilter : public QQuick3DShaderUtilsRenderCommand
493{
494 Q_OBJECT
495
496 Q_PROPERTY(quint32 layerMask MEMBER layerMask)
497 Q_PROPERTY(RenderableTypes renderableTypes READ renderableTypes WRITE setRenderableTypes)
498 QML_NAMED_ELEMENT(RenderablesFilter)
499 QML_ADDED_IN_VERSION(6, 11)
500
501public:
502 enum class RenderableType : quint32 {
503 None = 0x0,
504 Opaque = 0x1,
505 Transparent = 0x2,
506 };
507 Q_DECLARE_FLAGS(RenderableTypes, RenderableType)
508 Q_FLAG(RenderableTypes)
509
510 QQuick3DShaderUtilsRenderablesFilter() = default;
511 ~QQuick3DShaderUtilsRenderablesFilter() override;
512
513 RenderableTypes renderableTypes() const;
514 void setRenderableTypes(RenderableTypes types);
515
516 QSSGCommand *cloneCommand() override { return new QSSGRenderablesFilterCommand(command); }
517 QSSGRenderablesFilterCommand command { };
518
519 quint32 &layerMask = command.layerMask;
520};
521
522class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassTexture : public QQuick3DObject
523{
524 Q_OBJECT
525 Q_PROPERTY(TextureFormat format READ format WRITE setFormat FINAL)
526 QML_NAMED_ELEMENT(RenderPassTexture)
527 QML_ADDED_IN_VERSION(6, 11)
528
529public:
530 enum class TextureFormat {
531 Unknown = 0,
532 RGBA8,
533 RGBA16F,
534 RGBA32F,
535 R8,
536 R16,
537 R16F,
538 R32F,
539 Depth16,
540 Depth24,
541 Depth32,
542 Depth24Stencil8,
543 };
544 Q_ENUM(TextureFormat)
545
546 QQuick3DShaderUtilsRenderPassTexture() = default;
547 ~QQuick3DShaderUtilsRenderPassTexture() override;
548
549 TextureFormat format() const;
550 void setFormat(TextureFormat newFormat);
551
552 std::shared_ptr<QSSGAllocateTexture> command;
553
554private:
555 friend class QQuick3DShaderUtilsRenderPassColorAttachment;
556 friend class QQuick3DShaderUtilsRenderPassDepthTextureAttachment;
557
558
559private:
560 static QSSGRenderTextureFormat asRenderTextureFormat(QQuick3DShaderUtilsRenderPassTexture::TextureFormat fmt);
561 static QQuick3DShaderUtilsRenderPassTexture::TextureFormat fromRenderTextureFormat(QSSGRenderTextureFormat fmt);
562};
563
564// Class for user defined color attachments in render passes
565class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassColorAttachment : public QQuick3DShaderUtilsRenderCommand
566{
567 Q_OBJECT
568 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
569 Q_PROPERTY(QByteArray name READ name WRITE setName FINAL)
570 QML_NAMED_ELEMENT(ColorAttachment)
571 QML_ADDED_IN_VERSION(6, 11)
572
573public:
574 QQuick3DShaderUtilsRenderPassColorAttachment() = default;
575 ~QQuick3DShaderUtilsRenderPassColorAttachment() override;
576
577 QByteArray name() const;
578 void setName(const QByteArray &newName);
579
580 QSSGCommand *cloneCommand() override;
581
582private:
583 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
584 QByteArray m_name;
585};
586
587class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthTextureAttachment : public QQuick3DShaderUtilsRenderCommand
588{
589 Q_OBJECT
590 Q_PROPERTY(QQuick3DShaderUtilsRenderPassTexture *target MEMBER target)
591 QML_NAMED_ELEMENT(DepthTextureAttachment)
592 QML_ADDED_IN_VERSION(6, 11)
593
594public:
595 QQuick3DShaderUtilsRenderPassDepthTextureAttachment() = default;
596 ~QQuick3DShaderUtilsRenderPassDepthTextureAttachment() override;
597
598 QSSGCommand *cloneCommand() override;
599
600 QPointer<QQuick3DShaderUtilsRenderPassTexture> target;
601};
602
603class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassDepthStencilAttachment : public QQuick3DShaderUtilsRenderCommand
604{
605 Q_OBJECT
606 QML_NAMED_ELEMENT(DepthStencilAttachment)
607 QML_ADDED_IN_VERSION(6, 11)
608
609public:
610 QQuick3DShaderUtilsRenderPassDepthStencilAttachment() = default;
611 ~QQuick3DShaderUtilsRenderPassDepthStencilAttachment() override;
612
613 QSSGCommand *cloneCommand() override;
614
615};
616
617class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPassAddDefine : public QQuick3DShaderUtilsRenderCommand
618{
619 Q_OBJECT
620 Q_PROPERTY(QByteArray name MEMBER name)
621 Q_PROPERTY(int value MEMBER value)
622 QML_NAMED_ELEMENT(AddDefine)
623 QML_ADDED_IN_VERSION(6, 11)
624
625public:
626 QQuick3DShaderUtilsRenderPassAddDefine();
627 ~QQuick3DShaderUtilsRenderPassAddDefine() override;
628
629 QSSGCommand *cloneCommand() override;
630
631 QSSGAddShaderDefine command;
632 QByteArray &name = command.m_name;
633 int &value = command.m_value;
634};
635
636class Q_QUICK3D_EXPORT QQuick3DShaderUtilsSubRenderPass : public QQuick3DShaderUtilsRenderCommand
637{
638 Q_OBJECT
639 Q_PROPERTY(QQuick3DRenderPass *renderPass READ renderPass WRITE setRenderPass NOTIFY renderPassChanged FINAL)
640 QML_NAMED_ELEMENT(SubRenderPass)
641 QML_ADDED_IN_VERSION(6, 11)
642
643public:
644 QQuick3DShaderUtilsSubRenderPass() = default;
645 ~QQuick3DShaderUtilsSubRenderPass() override;
646
647 QQuick3DRenderPass *renderPass() const;
648 void setRenderPass(QQuick3DRenderPass *newRenderPass);
649
650 QSSGCommand *cloneCommand() override;
651
652signals:
653 void renderPassChanged();
654
655protected:
656 virtual QSSGRenderGraphObject *updateSpatialNode(QSSGRenderGraphObject *node) final;
657 virtual void itemChange(ItemChange change, const ItemChangeData &value) final;
658
659private:
660 void updateSceneManager(QQuick3DSceneManager *sceneManager);
661
662 QQuick3DRenderPass *m_renderPass = nullptr;
663 mutable bool m_hasWarnedAboutInvalidId = false;
664};
665
666class Q_QUICK3D_EXPORT QQuick3DShaderUtilsRenderPass : public QQuick3DObject
667{
668 Q_OBJECT
669 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands READ commands)
670 Q_PROPERTY(QQuick3DShaderUtilsBuffer *output MEMBER outputBuffer)
671 Q_PROPERTY(QQmlListProperty<QQuick3DShaderUtilsShader> shaders READ shaders)
672 QML_NAMED_ELEMENT(Pass)
673 QML_ADDED_IN_VERSION(6, 11)
674
675public:
676 QQuick3DShaderUtilsRenderPass() = default;
677 ~QQuick3DShaderUtilsRenderPass() override;
678
679 static void qmlAppendCommand(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, QQuick3DShaderUtilsRenderCommand *command);
680 static QQuick3DShaderUtilsRenderCommand *qmlCommandAt(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list, qsizetype index);
681 static qsizetype qmlCommandCount(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
682 static void qmlCommandClear(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list);
683
684 static void qmlAppendShader(QQmlListProperty<QQuick3DShaderUtilsShader> *list, QQuick3DShaderUtilsShader *shader);
685 static QQuick3DShaderUtilsShader *qmlShaderAt(QQmlListProperty<QQuick3DShaderUtilsShader> *list, qsizetype index);
686 static qsizetype qmlShaderCount(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
687 static void qmlShaderClear(QQmlListProperty<QQuick3DShaderUtilsShader> *list);
688
689 QQmlListProperty<QQuick3DShaderUtilsRenderCommand> commands();
690 QVector<QQuick3DShaderUtilsRenderCommand *> m_commands;
691 QQuick3DShaderUtilsBuffer *outputBuffer = nullptr;
692 QQmlListProperty<QQuick3DShaderUtilsShader> shaders();
693 QVarLengthArray<QQuick3DShaderUtilsShader *, 2> m_shaders;
694
695Q_SIGNALS:
696 void changed();
697};
698
699class Q_QUICK3D_EXPORT QQuick3DShaderUtilsShader : public QQuick3DObject
700{
701 Q_OBJECT
702 Q_PROPERTY(QUrl shader MEMBER shader NOTIFY shaderChanged)
703 Q_PROPERTY(Stage stage MEMBER stage NOTIFY stageChanged)
704
705 QML_NAMED_ELEMENT(Shader)
706
707public:
708 QQuick3DShaderUtilsShader() = default;
709 virtual ~QQuick3DShaderUtilsShader() = default;
710 enum class Stage : quint8
711 {
712 Vertex = 0,
713 Fragment = 1
714 };
715 Q_ENUM(Stage)
716
717 QUrl shader;
718 Stage stage = Stage::Fragment;
719
720Q_SIGNALS:
721 void shaderChanged();
722 void stageChanged();
723};
724
725template<typename T, typename std::enable_if_t<std::is_base_of_v<QQuick3DObject, T>, bool> = true>
726class QQuick3DSuperClassInfo
727{
728public:
729 QQuick3DSuperClassInfo() = default;
730
731 static const char *superClassName()
732 {
733 return T::staticMetaObject.className();
734 }
735};
736
738
740{
742public:
744
745public Q_SLOTS:
748
749private:
750 QQuick3DPropertyChangedTracker *m_tracker = nullptr;
751 QMetaProperty m_property;
752};
753
755{
756public:
758 {
761 };
762
763 template<typename T>
764 explicit QQuick3DPropertyChangedTracker(QQuick3DObject *owner, QQuick3DSuperClassInfo<T> info)
765 : m_owner(owner)
766 , m_superClassName(info.superClassName())
767 {
768 Q_ASSERT(m_owner != nullptr);
769 }
771
774protected:
776
777 void extractProperties(UniformPropertyList &outUniforms);
778
779 void addPropertyWatcher(QMetaProperty property, DirtyPropertyHint hint, QQuick3DObject *object = nullptr);
780
781 virtual void markTrackedPropertyDirty(QMetaProperty property, DirtyPropertyHint hint) = 0;
782
789
793 const char *m_superClassName = nullptr;
794};
795
796QT_END_NAMESPACE
797
798Q_DECLARE_OPAQUE_POINTER(QQuick3DShaderUtilsTextureInput)
799
800#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.