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.cpp
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
7
8#include <QtCore/qfile.h>
9#include <QtQml/qqmlcontext.h>
10#include <QtQml/qqmlfile.h>
11
18#include <ssg/qssgrenderextensions.h>
19#include <ssg/qquick3dextensionhelpers.h>
20
21#include <QtQuick3DRuntimeRender/private/qssgrenderbuffer_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderimage_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrenderpasstexture_p.h>
24
25#include <QtCore/QLoggingCategory>
26
28
29Q_LOGGING_CATEGORY(lcSubRenderPass, "qt.quick3d.subrenderpass")
30
31/*!
32 \qmltype Shader
33 \inherits QtObject
34 \inqmlmodule QtQuick3D
35 \brief Container component for defining shader code used by post-processing effects.
36
37 The Shader type is used for populating the \l{Pass::shaders}{shaders} list in the
38 render \l{Pass}{pass} of an \l Effect.
39
40 A shader is code which is executed directly on the graphic hardware at a particular
41 \l{Shader::stage}{stage} of the rendering pipeline.
42
43 \sa Effect
44*/
45/*!
46 \qmlproperty url Shader::shader
47 Specifies the name of the shader source file. For details on how to write shader code,
48 see the \l Effect documentation.
49
50 \warning Shader snippets are assumed to be trusted content. Application
51 developers are advised to carefully consider the potential implications
52 before allowing the loading of user-provided content that is not part of the
53 application.
54*/
55/*!
56 \qmlproperty enumeration Shader::stage
57 Specifies the stage of the rendering pipeline when the shader code will be executed.
58 The default is \c Shader.Fragment
59
60 \value Shader.Vertex The shader is a vertex shader. This code is run once per vertex
61 in the input geometry and can be used to modify it before the geometry is rasterized
62 (scan converted). In the case of effects, the input geometry is always a quad (four
63 vertexes representing the corners of the render target).
64 \value Shader.Fragment The shader is a fragment shader. After vertex processing,
65 the modified geometry is turned into fragments (rasterization). Then a fragment shader
66 is executed for each fragment, assigning a color to it. Fragments are a related concept
67 to pixels, but with additional information attached. Also, as a result of some
68 anti-aliasing strategies, there may be more than one fragment for each pixel in the
69 output.
70*/
71
72/*!
73 \qmltype TextureInput
74 \inherits QtObject
75 \inqmlmodule QtQuick3D
76 \brief Specifies a texture exposed to the shaders of a CustomMaterial or Effect.
77 \deprecated [6.13] Declare a property of the \l Texture type instead.
78
79 This is a type which can be used for exposing a \l Texture to a shader, either
80 in the \l{Pass}{render pass} of an \l Effect, or in a \l CustomMaterial. It exists
81 primarily to assign a local name to the \l Texture that can be referenced from
82 shaders.
83
84 When a TextureInput property is declared in an \l Effect or a \l CustomMaterial,
85 it will automatically be available as a sampler in all shaders by its property
86 name.
87
88 A property of the \l Texture type is exposed to the shaders in the same way,
89 so the wrapper is no longer needed. Declare the property with the \l Texture
90 type, or a subtype such as \l CubeMapTexture, and assign the texture to it
91 directly. Instead of disabling a TextureInput, set the property to null,
92 which exposes the same dummy texture to the shaders.
93
94 \qml
95 // Deprecated
96 property TextureInput tex: TextureInput {
97 texture: Texture { source: "image.png" }
98 }
99
100 // Recommended
101 property Texture tex: Texture { source: "image.png" }
102 \endqml
103*/
104/*!
105 \qmlproperty Texture TextureInput::texture
106 The texture for which this TextureInput serves as an indirection.
107*/
108/*!
109 \qmlproperty bool TextureInput::enabled
110 The property determines if this TextureInput is enabled. The default value
111 is true. When disabled, the shaders of the effect sample a dummy, opaque
112 black texture instead of the one specified by \l texture.
113*/
114
115/*!
116 \qmltype Pass
117 \inherits QtObject
118 \inqmlmodule QtQuick3D
119 \brief Defines a render pass in an Effect.
120
121 An \l Effect may consist of multiple render passes. Each render pass has a
122 setup phase where the list of \l{Pass::commands}{render commands} are executed,
123 a \l{Pass::output}{output buffer} and a list of \l{Pass::shaders}{shaders} to
124 use for rendering the effect.
125
126 See the documentation for \l Effect for more details on how to set up multiple
127 rendering passes.
128*/
129/*!
130 \qmlproperty Buffer Pass::output
131 Specifies the output \l {Buffer}{buffer} of the pass.
132*/
133/*!
134 \qmlproperty list Pass::commands
135 Specifies the list of render \l {Command}{commands} of the pass.
136*/
137/*!
138 \qmlproperty list Pass::shaders
139 Specifies the list of \l {Shader}{shaders} of the pass.
140*/
141
142/*!
143 \qmltype Command
144 \inherits QtObject
145 \inqmlmodule QtQuick3D
146 \brief Supertype of commands to be performed as part of a pass in an Effect.
147
148 The Command type should not be instantiated by itself, but only exists as a
149 polymorphic supertype for the different actions that can be performed as part
150 of a \l{Pass}{render pass}.
151
152 \sa BufferInput, SetUniformValue, Effect
153*/
154
155/*!
156 \qmltype BufferInput
157 \inherits Command
158 \inqmlmodule QtQuick3D
159 \brief Defines an input buffer to be used as input for a pass of an Effect.
160
161 BufferInput is a \l Command which can be added to the list of commands in the \l Pass of
162 an \l Effect. When executed, it will expose the buffer as a sample to the shaders
163 in the render pass. The shaders must declare a sampler with the name given in the
164 BufferInput's \c sampler property.
165
166 This can be used for sharing intermediate results between the different passes of an
167 effect.
168
169 \sa Texture
170*/
171/*!
172 \qmlproperty Buffer BufferInput::buffer
173 Specifies the \l {Buffer}{buffer} which should be exposed to the shader.
174*/
175/*!
176 \qmlproperty string BufferInput::sampler
177 Specifies the name under which the buffer is exposed to the shader.
178 When this property is not set, the buffer is exposed with the built-in name \c INPUT.
179*/
180
181/*!
182 \qmltype Buffer
183 \inherits QtObject
184 \inqmlmodule QtQuick3D
185 \brief Creates or references a color buffer to be used for a pass of an Effect.
186
187 A Buffer can be used to create intermediate buffers to share data between
188 \l{Pass}{render passes} in an \l Effect.
189
190 \note If the \l name property of the Buffer is empty, it will reference the
191 default output texture of the render pass.
192*/
193/*!
194 \qmlproperty enumeration Buffer::format
195 Specifies the texture format. The default value is Buffer.RGBA8.
196
197 \value Buffer.RGBA8
198 \value Buffer.RGBA16F
199 \value Buffer.RGBA32F
200 \value Buffer.R8
201 \value Buffer.R16
202 \value Buffer.R16F
203 \value Buffer.R32F
204*/
205/*!
206 \qmlproperty enumeration Buffer::textureFilterOperation
207 Specifies the texture filtering mode when sampling the contents of the
208 Buffer. The default value is Buffer.Linear.
209
210 \value Buffer.Nearest Use nearest-neighbor filtering.
211 \value Buffer.Linear Use linear filtering.
212*/
213/*!
214 \qmlproperty enumeration Buffer::textureCoordOperation
215 Specifies the behavior for texture coordinates when sampling outside the [0, 1] range.
216 The default is Buffer.ClampToEdge.
217
218 \value Buffer.ClampToEdge Clamp coordinates to the edges.
219 \value Buffer.Repeat Wrap the coordinates at the edges to tile the texture.
220 \value Buffer.MirroredRepeat Wrap the coordinate at the edges, but mirror the texture
221 when tiling it.
222*/
223/*!
224 \qmlproperty real Buffer::sizeMultiplier
225 Specifies the size multiplier of the buffer. For instance, a value of \c 1.0 creates
226 a buffer with the same size as the effect's input texture while \c 0.5 creates buffer
227 where both width and height is half as big. The default value is 1.0.
228*/
229/*!
230 \qmlproperty enumeration Buffer::bufferFlags
231 Specifies the buffer allocation flags. The default is Buffer.None.
232
233 \value Buffer.None No special behavior.
234 \value Buffer.SceneLifetime The buffer is allocated for the whole lifetime of the scene.
235*/
236/*!
237 \qmlproperty string Buffer::name
238 Specifies the name of the buffer.
239
240 \note When this property is empty, the Buffer will refer to the default output texture
241 of the \l{Pass}{render pass} instead of allocating a buffer. This can be useful to
242 override certain settings of the output, such as the texture format, without introducing
243 a new, separate intermediate texture.
244*/
245
246/*!
247 \qmltype SetUniformValue
248 \inherits Command
249 \inqmlmodule QtQuick3D
250 \brief Defines a value to be set during a single \l {Pass}{pass}.
251 \since 5.15
252
253 SetUniformValue is a \l Command which can be added to the list of commands in a \l Pass. When
254 executed, it will set the uniform given by the \l{SetUniformValue::target}{target} property
255 to \l{SetUniformValue::value}{value}.
256
257 \note The value set by this command is will only be set during the \l {Pass}{pass} it occurs in.
258 For consecutive passes the value will be revert to the initial value of the uniform as it
259 was defined in the \l Effect item.
260
261 \sa BufferInput
262*/
263/*!
264 \qmlproperty string SetUniformValue::target
265 Specifies the name of the uniform that will have its value changed during the \l {Pass}{pass}.
266 This must match the name of an existing property in the \l Effect.
267*/
268/*!
269 \qmlproperty Variant SetUniformValue::value
270 Specifies the value that will be set on the \c target uniform.
271*/
272
273/*!
274 \qmlvaluetype renderTargetBlend
275 \inqmlmodule QtQuick3D
276 \brief Defines blending parameters for a single color attachment of a render pass.
277 \since 6.11
278
279 The renderTargetBlend type is used to specify blending parameters for a single
280 color attachment of a \l RenderPass. An instance of renderTargetBlend can be
281 assigned to one of the \l PipelineStateOverride \c targetBlend0 through \c targetBlend7
282 properties, where the index corresponds to the color attachment slot.
283
284 The color blend equation is:
285 \badcode
286 result.rgb = srcColor * src.rgb opColor dstColor * dst.rgb
287 result.a = srcAlpha * src.a opAlpha dstAlpha * dst.a
288 \endcode
289*/
290
291/*!
292 \qmlproperty bool renderTargetBlend::blendEnabled
293 If set to \c true, enables blending for the color attachment. If set to \c false,
294 disables blending and the output color is written directly to the attachment.
295 The default value is \c false.
296*/
297
298/*!
299 \qmlproperty enumeration renderTargetBlend::colorWrite
300 A bitmask that controls which color channels are written to the color attachment.
301 Multiple values can be combined with the \c | operator.
302 The default value is \c {R | G | B | A}.
303
304 \value RenderTargetBlend.R Write to the red channel.
305 \value RenderTargetBlend.G Write to the green channel.
306 \value RenderTargetBlend.B Write to the blue channel.
307 \value RenderTargetBlend.A Write to the alpha channel.
308*/
309
310/*!
311 \qmlproperty enumeration renderTargetBlend::srcColor
312 Sets the source color blend factor. This value scales the RGB components of the
313 fragment shader output before the blend operation. The default value is \c One.
314
315 \value RenderTargetBlend.Zero Factor is (0, 0, 0).
316 \value RenderTargetBlend.One Factor is (1, 1, 1).
317 \value RenderTargetBlend.SrcColor Factor is the source color (r, g, b).
318 \value RenderTargetBlend.OneMinusSrcColor Factor is (1-r, 1-g, 1-b) of the source.
319 \value RenderTargetBlend.DstColor Factor is the destination color (r, g, b).
320 \value RenderTargetBlend.OneMinusDstColor Factor is (1-r, 1-g, 1-b) of the destination.
321 \value RenderTargetBlend.SrcAlpha Factor is the source alpha (a, a, a).
322 \value RenderTargetBlend.OneMinusSrcAlpha Factor is (1-a, 1-a, 1-a) of the source.
323 \value RenderTargetBlend.DstAlpha Factor is the destination alpha (a, a, a).
324 \value RenderTargetBlend.OneMinusDstAlpha Factor is (1-a, 1-a, 1-a) of the destination.
325 \value RenderTargetBlend.ConstantColor Factor is the constant color set on the pipeline.
326 \value RenderTargetBlend.OneMinusConstantColor Factor is one minus the constant color.
327 \value RenderTargetBlend.ConstantAlpha Factor is the constant alpha.
328 \value RenderTargetBlend.OneMinusConstantAlpha Factor is one minus the constant alpha.
329 \value RenderTargetBlend.SrcAlphaSaturate Factor is min(src.a, 1-dst.a) for RGB, 1 for A.
330 \value RenderTargetBlend.Src1Color Factor is from the second color output of the fragment shader.
331 \value RenderTargetBlend.OneMinusSrc1Color Factor is one minus the second color output.
332 \value RenderTargetBlend.Src1Alpha Factor is the alpha of the second color output.
333 \value RenderTargetBlend.OneMinusSrc1Alpha Factor is one minus the alpha of the second output.
334*/
335
336/*!
337 \qmlproperty enumeration renderTargetBlend::dstColor
338 Sets the destination color blend factor. This value scales the RGB components of the
339 current value in the color attachment before the blend operation.
340 The default value is \c OneMinusSrcAlpha.
341 See \c srcColor for the list of available values.
342*/
343
344/*!
345 \qmlproperty enumeration renderTargetBlend::opColor
346 Sets the arithmetic operation used to combine the scaled source and destination
347 color components. The default value is \c Add.
348
349 \value RenderTargetBlend.Add Result = src + dst.
350 \value RenderTargetBlend.Subtract Result = src - dst.
351 \value RenderTargetBlend.ReverseSubtract Result = dst - src.
352 \value RenderTargetBlend.Min Result = min(src, dst).
353 \value RenderTargetBlend.Max Result = max(src, dst).
354*/
355
356/*!
357 \qmlproperty enumeration renderTargetBlend::srcAlpha
358 Sets the source alpha blend factor. This value scales the alpha component of the
359 fragment shader output before the blend operation. The default value is \c One.
360 See \c srcColor for the list of available values.
361*/
362
363/*!
364 \qmlproperty enumeration renderTargetBlend::dstAlpha
365 Sets the destination alpha blend factor. This value scales the alpha component of the
366 current value in the color attachment before the blend operation.
367 The default value is \c OneMinusSrcAlpha.
368 See \c srcColor for the list of available values.
369*/
370
371/*!
372 \qmlproperty enumeration renderTargetBlend::opAlpha
373 Sets the arithmetic operation used to combine the scaled source and destination
374 alpha components. The default value is \c Add.
375 See \c opColor for the list of available values.
376*/
377
378/*!
379 \qmltype PipelineStateOverride
380 \inherits Command
381 \inqmlmodule QtQuick3D
382 \brief Defines pipeline state overrides for a single \l {RenderPass}{pass}.
383 \since 6.11
384
385 PipelineStateOverride is a \l Command which can be added to the list of commands in a \l RenderPass.
386 When executed, it will override the pipeline state in the render pass according to the properties set on
387 the PipelineStateOverride. Only values that are set will override the existing pipeline state's values.
388 If you want to reset a value that has been overridden to the default, then set the property
389 to \c undefined.
390
391 \sa renderTargetBlend
392*/
393
394/*!
395 \qmltype DepthStencilAttachment
396 \inherits Command
397 \inqmlmodule QtQuick3D
398 \brief Defines a depth-stencil attachment for a RenderPass.
399 \since 6.11
400
401 DepthStencilAttachment adds an implicit depth/stencil render buffer to a
402 \l RenderPass. The render buffer is automatically created and managed by the
403 rendering system. Because it is backed by an opaque render buffer rather
404 than a texture, its contents cannot be sampled in shaders. If you need to
405 read back depth values in a later pass, use \l DepthTextureAttachment instead.
406
407 Use DepthStencilAttachment when you need depth testing and/or stencil
408 operations in a pass but do not need to access the depth data afterwards.
409
410 \qml
411 RenderPass {
412 commands: [
413 ColorAttachment { name: "color0"; target: colorTexture },
414 // Add a depth buffer so depth testing works in this pass
415 DepthStencilAttachment {}
416 ]
417 }
418 \endqml
419
420 \sa DepthTextureAttachment, RenderPassTexture
421*/
422
424
426
431
432QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey)
433{
435 QByteArray shaderData;
436 if (resolveShaderOverride(fileUrl, context, shaderData, shaderPathKey))
437 return shaderData;
438 }
439
440 if (!shaderPathKey.isEmpty())
441 shaderPathKey.append('>');
442
443 const QUrl loadUrl = context ? context->resolvedUrl(fileUrl) : fileUrl;
444 const QString filePath = QQmlFile::urlToLocalFileOrQrc(loadUrl);
445
446 QFile f(filePath);
447 if (f.open(QIODevice::ReadOnly | QIODevice::Text)) {
448 shaderPathKey += loadUrl.fileName().toUtf8();
449 return f.readAll();
450 } else {
451 qWarning("Failed to read shader code from %s", qPrintable(filePath));
452 }
453
454 return QByteArray();
455}
456
457// These are the QMetaTypes that we convert into uniforms.
475
476template<>
478{
480 static QByteArray name() { return QByteArrayLiteral("float"); }
481};
482
483template<>
485{
487 static QByteArray name() { return QByteArrayLiteral("bool"); }
488};
489
490template<>
492{
494 static QByteArray name() { return QByteArrayLiteral("int"); }
495};
496
497template<>
499{
501 static QByteArray name() { return QByteArrayLiteral("vec2"); }
502};
503
504template<>
506{
508 static QByteArray name() { return QByteArrayLiteral("vec3"); }
509};
510
511template<>
513{
515 static QByteArray name() { return QByteArrayLiteral("vec4"); }
516};
517
518template<>
520{
522 static QByteArray name() { return QByteArrayLiteral("vec4"); }
523};
524
525template<>
527{
529 static QByteArray name() { return QByteArrayLiteral("vec2"); }
530};
531
532template<>
534{
536 static QByteArray name() { return QByteArrayLiteral("vec2"); }
537};
538
539template<>
541{
543 static QByteArray name() { return QByteArrayLiteral("vec2"); }
544};
545
546template<>
548{
550 static QByteArray name() { return QByteArrayLiteral("vec2"); }
551};
552
553template<>
555{
557 static QByteArray name() { return QByteArrayLiteral("vec4"); }
558};
559
560template<>
562{
564 static QByteArray name() { return QByteArrayLiteral("vec4"); }
565};
566
567template<>
569{
571 static QByteArray name() { return QByteArrayLiteral("vec4"); }
572};
573
574template<>
576{
578 static QByteArray name() { return QByteArrayLiteral("mat4"); }
579};
580
582{
583 switch (type.id()) {
584 case QMetaType::Double:
585 case QMetaType::Float:
586 return ShaderType<QMetaType::Double>::name();
587 case QMetaType::Bool:
588 return ShaderType<QMetaType::Bool>::name();
589 case QMetaType::QVector2D:
590 return ShaderType<QMetaType::QVector2D>::name();
591 case QMetaType::QVector3D:
592 return ShaderType<QMetaType::QVector3D>::name();
593 case QMetaType::QVector4D:
594 return ShaderType<QMetaType::QVector4D>::name();
595 case QMetaType::Int:
596 return ShaderType<QMetaType::Int>::name();
597 case QMetaType::QColor:
598 return ShaderType<QMetaType::QColor>::name();
599 case QMetaType::QSize:
600 return ShaderType<QMetaType::QSize>::name();
601 case QMetaType::QSizeF:
602 return ShaderType<QMetaType::QSizeF>::name();
603 case QMetaType::QPoint:
604 return ShaderType<QMetaType::QPoint>::name();
605 case QMetaType::QPointF:
606 return ShaderType<QMetaType::QPointF>::name();
607 case QMetaType::QRect:
608 return ShaderType<QMetaType::QRect>::name();
609 case QMetaType::QRectF:
610 return ShaderType<QMetaType::QRectF>::name();
611 case QMetaType::QQuaternion:
612 return ShaderType<QMetaType::QQuaternion>::name();
613 case QMetaType::QMatrix4x4:
614 return ShaderType<QMetaType::QMatrix4x4>::name();
615 default:
616 return QByteArray();
617 }
618}
619
657
659{
660 switch (type.id()) {
661 case QMetaType::Double:
662 case QMetaType::Float:
663 return ShaderType<QMetaType::Double>::type();
664 case QMetaType::Bool:
665 return ShaderType<QMetaType::Bool>::type();
666 case QMetaType::QVector2D:
667 return ShaderType<QMetaType::QVector2D>::type();
668 case QMetaType::QVector3D:
669 return ShaderType<QMetaType::QVector3D>::type();
670 case QMetaType::QVector4D:
671 return ShaderType<QMetaType::QVector4D>::type();
672 case QMetaType::Int:
673 return ShaderType<QMetaType::Int>::type();
674 case QMetaType::QColor:
675 return ShaderType<QMetaType::QColor>::type();
676 case QMetaType::QSize:
677 return ShaderType<QMetaType::QSize>::type();
678 case QMetaType::QSizeF:
679 return ShaderType<QMetaType::QSizeF>::type();
680 case QMetaType::QPoint:
681 return ShaderType<QMetaType::QPoint>::type();
682 case QMetaType::QPointF:
683 return ShaderType<QMetaType::QPointF>::type();
684 case QMetaType::QRect:
685 return ShaderType<QMetaType::QRect>::type();
686 case QMetaType::QRectF:
687 return ShaderType<QMetaType::QRectF>::type();
688 case QMetaType::QQuaternion:
689 return ShaderType<QMetaType::QQuaternion>::type();
690 case QMetaType::QMatrix4x4:
691 return ShaderType<QMetaType::QMatrix4x4>::type();
692 default:
693 return QSSGRenderShaderValue::Unknown;
694 }
695}
696
698{
699 return {std::begin(qssg_metatype_list), std::end(qssg_metatype_list)};
700}
701
702bool isTextureType(QMetaType type)
703{
704 // A null property value has no object type to check, so this goes by the
705 // declared type.
706 if (!(type.flags() & QMetaType::PointerToQObject))
707 return false;
708 const QMetaObject *metaObject = type.metaObject();
709 return metaObject && metaObject->inherits(&QQuick3DTexture::staticMetaObject);
710}
711
712QQuick3DTexture *textureFromValue(const QVariant &value)
713{
714 return qobject_cast<QQuick3DTexture *>(value.value<QObject *>());
715}
716
717QByteArray samplerTypeName(const QQuick3DTexture *texture)
718{
719 auto samplerType = QSSGRenderSamplerType::Sampler2D;
720 if (const auto *po = texture ? QQuick3DObjectPrivate::get(texture) : nullptr) {
721 if (auto *textureProvider = qobject_cast<QQuick3DTextureProviderExtension *>(texture->textureProvider())) {
722 switch (textureProvider->samplerHint()) {
723 case QQuick3DTextureProviderExtension::SamplerHint::Sampler2D:
724 samplerType = QSSGRenderSamplerType::Sampler2D;
725 break;
726 case QQuick3DTextureProviderExtension::SamplerHint::Sampler2DArray:
727 samplerType = QSSGRenderSamplerType::Sampler2DArray;
728 break;
729 case QQuick3DTextureProviderExtension::SamplerHint::Sampler3D:
730 samplerType = QSSGRenderSamplerType::Sampler3D;
731 break;
732 case QQuick3DTextureProviderExtension::SamplerHint::SamplerCube:
733 samplerType = QSSGRenderSamplerType::SamplerCube;
734 break;
735 case QQuick3DTextureProviderExtension::SamplerHint::SamplerCubeArray:
736 samplerType = QSSGRenderSamplerType::SamplerCubeArray;
737 break;
738 case QQuick3DTextureProviderExtension::SamplerHint::SamplerBuffer:
739 samplerType = QSSGRenderSamplerType::SamplerBuffer;
740 break;
741 }
742 } else if (po->type == QQuick3DObjectPrivate::Type::ImageCube) {
743 samplerType = QSSGRenderSamplerType::SamplerCube;
744 } else if (texture->textureData() && texture->textureData()->depth() > 0) {
745 samplerType = QSSGRenderSamplerType::Sampler3D;
746 }
747 }
748 return QSSGBaseTypeHelpers::toString(samplerType);
749}
750
751QByteArray toShaderFormat(QQuick3DShaderImage::ImageFormat imageFormat)
752{
753 switch (imageFormat) {
754 case QQuick3DShaderImage::RGBA8: return "rgba8";
755 case QQuick3DShaderImage::R8: return "r8";
756 case QQuick3DShaderImage::RG8: return "rg8";
757 case QQuick3DShaderImage::R16: return "r16";
758 case QQuick3DShaderImage::RG16: return "rg16";
759 case QQuick3DShaderImage::RGBA16F: return "rgba16f";
760 case QQuick3DShaderImage::RGBA32F: return "rgba32f";
761 case QQuick3DShaderImage::R16F: return "r16f";
762 case QQuick3DShaderImage::R32F: return "r32f";
763 case QQuick3DShaderImage::RGB10A2: return "rgb10_a2";
764 case QQuick3DShaderImage::R8SI: return "r8i";
765 case QQuick3DShaderImage::R32SI: return "r32i";
766 case QQuick3DShaderImage::RG32SI: return "rg32i";
767 case QQuick3DShaderImage::RGBA32SI: return "rgba32i";
768 case QQuick3DShaderImage::R8UI: return "r8ui";
769 case QQuick3DShaderImage::R32UI: return "r32ui";
770 case QQuick3DShaderImage::RG32UI: return "rg32ui";
771 case QQuick3DShaderImage::RGBA32UI: return "rgba32ui";
772 default: break;
773 }
774 return {};
775}
776
777// The GLSL image type of a shader image with the given shape and format.
778QByteArray toShaderImageType(QQuick3DShaderImage::ImageShape shape, QQuick3DShaderImage::ImageFormat imageFormat)
779{
780 QByteArray prefix;
781 switch (imageFormat) {
782 case QQuick3DShaderImage::R8SI:
783 case QQuick3DShaderImage::R32SI:
784 case QQuick3DShaderImage::RG32SI:
785 case QQuick3DShaderImage::RGBA32SI:
786 prefix = "i";
787 break;
788 case QQuick3DShaderImage::R8UI:
789 case QQuick3DShaderImage::R32UI:
790 case QQuick3DShaderImage::RG32UI:
791 case QQuick3DShaderImage::RGBA32UI:
792 prefix = "u";
793 break;
794 default:
795 break;
796 }
797 switch (shape) {
798 case QQuick3DShaderImage::Image1D: return prefix + "image1D";
799 case QQuick3DShaderImage::Image2D: return prefix + "image2D";
800 case QQuick3DShaderImage::Image3D: return prefix + "image3D";
801 case QQuick3DShaderImage::Image2DArray: return prefix + "image2DArray";
802 case QQuick3DShaderImage::ImageCube: return prefix + "imageCube";
803 }
804 return {};
805}
806
807bool handleBufferProperty(QQuick3DShaderStorageBuffer *buffer, const QByteArray &name, int i,
808 QByteArrayList &metadata, QList<QSSGBaseTypeProperty> &properties)
809{
810 QSSGRenderBuffer *rbuf = buffer ? (QSSGRenderBuffer*)QQuick3DObjectPrivate::get(buffer)->spatialNode : nullptr;
811 metadata.push_back(QByteArrayLiteral("buffer"));
812 metadata.push_back({});
813 metadata.push_back(name);
814 metadata.push_back({});
815 QSSGShaderBuffer sbuf(rbuf, {}, {});
816 properties.push_back({ name, {}, QVariant::fromValue(sbuf), QSSGRenderShaderValue::StorageBuffer, i});
817 return rbuf != nullptr;
818}
819
820void updateBufferProperty(QQuick3DShaderStorageBuffer *buffer, const QSSGBaseTypeProperty &property)
821{
822 QSSGRenderBuffer *rbuf = buffer ? (QSSGRenderBuffer*)QQuick3DObjectPrivate::get(buffer)->spatialNode : nullptr;
823 QSSGShaderBuffer sbuf = property.value.value<QSSGShaderBuffer>();
824 sbuf.buffer = rbuf;
825 property.value = QVariant::fromValue(sbuf);
826}
827
828bool handleImageProperty(QQuick3DShaderImage *image, const QByteArray &name, int i,
829 QByteArrayList &metadata, QList<QSSGBaseTypeProperty> &properties) {
830 QByteArray fullType = image ? toShaderFormat(image->format()) : QByteArrayLiteral("");
831 QSSGRenderImage *rimg = image ? (QSSGRenderImage*)QQuick3DObjectPrivate::get(image)->spatialNode : nullptr;
832 metadata.push_back(QByteArrayLiteral("image"));
833 metadata.push_back(fullType);
834 metadata.push_back(name);
835 metadata.push_back(image ? toShaderImageType(image->shape(), image->format()) : QByteArray());
836 QSSGShaderImage simg(rimg, {}, fullType, {});
837 properties.push_back({ name, {}, QVariant::fromValue(simg), QSSGRenderShaderValue::Image, i});
838 return rimg != nullptr;
839}
840
841void updateImageProperty(QQuick3DShaderImage *image, const QSSGBaseTypeProperty &property)
842{
843 QSSGRenderImage *rimg = image ? (QSSGRenderImage*)QQuick3DObjectPrivate::get(image)->spatialNode : nullptr;
844 QSSGShaderImage simg = property.value.value<QSSGShaderImage>();
845 simg.image = rimg;
846 if (image && (toShaderFormat(image->format()) != simg.format
847 || (!simg.imageType.isEmpty() && toShaderImageType(image->shape(), image->format()) != simg.imageType))) {
848 qWarning() << "Invalid shader image format or shape.";
849 simg.image = nullptr;
850 }
851 property.value = QVariant::fromValue(simg);
852}
853
854/*
855 Sets the values of \a properties from the current values of the \a owner's
856 properties, and appends the metadata of the images and buffers among them
857 to \a metadata, in the form processMetadata() expects.
858
859 Returns false if an image or buffer has no backend node yet.
860*/
861bool resolveResourceProperties(const QObject *owner, const QList<QSSGBaseTypeProperty> &properties,
862 QByteArrayList &metadata)
863{
864 bool allHaveNodes = true;
865 for (const auto &prop : properties) {
866 const QMetaProperty p = owner->metaObject()->property(prop.pid);
867 if (Q_UNLIKELY(!p.isValid()))
868 continue;
869 const QVariant v = p.read(owner);
870 if (!v.isValid())
871 continue;
872 if (prop.shaderDataType == QSSGRenderShaderValue::Texture) {
873 QQuick3DTexture *tex = textureFromValue(v);
874 QSSGRenderImage *ri = tex ? static_cast<QSSGRenderImage *>(QQuick3DObjectPrivate::get(tex)->spatialNode) : nullptr;
875 prop.value = QVariant::fromValue(ri);
876 } else if (prop.shaderDataType == QSSGRenderShaderValue::StorageBuffer) {
877 QQuick3DShaderStorageBuffer *buffer = v.value<QQuick3DShaderStorageBuffer *>();
878 if (!buffer) {
879 prop.value = QVariant::fromValue(QSSGShaderBuffer());
880 continue;
881 }
882 QSSGRenderBuffer *ri = static_cast<QSSGRenderBuffer *>(QQuick3DObjectPrivate::get(buffer)->spatialNode);
883 metadata.append("buffer");
884 metadata.append("");
885 metadata.append(prop.name);
886 metadata.append("");
887 prop.value = QVariant::fromValue(QSSGShaderBuffer(ri, {}, {}));
888 allHaveNodes &= (ri != nullptr);
889 } else if (prop.shaderDataType == QSSGRenderShaderValue::Image) {
890 QQuick3DShaderImage *image = v.value<QQuick3DShaderImage *>();
891 if (!image) {
892 prop.value = QVariant::fromValue(QSSGShaderImage());
893 continue;
894 }
895 QSSGRenderImage *ri = static_cast<QSSGRenderImage *>(QQuick3DObjectPrivate::get(image)->spatialNode);
896 QSSGShaderImage simg(ri, {}, toShaderFormat(image->format()), {});
897 metadata.append("image");
898 // The format and the image type are checked against the shader in processMetadata().
899 metadata.append(simg.format);
900 metadata.append(prop.name);
901 metadata.append(toShaderImageType(image->shape(), image->format()));
902 prop.value = QVariant::fromValue(simg);
903 allHaveNodes &= (ri != nullptr);
904 } else {
905 prop.value = v;
906 }
907 }
908 return allHaveNodes;
909}
910
911/*
912 Updates the values of \a properties from the current values of the
913 \a owner's properties, when only the values have changed since
914 resolveResourceProperties() and the shader does not need to be processed
915 again.
916*/
917void updateResourceProperties(const QObject *owner, const QList<QSSGBaseTypeProperty> &properties)
918{
919 for (const auto &prop : properties) {
920 const QMetaProperty p = owner->metaObject()->property(prop.pid);
921 if (Q_UNLIKELY(!p.isValid()))
922 continue;
923 const QVariant v = p.read(owner);
924 if (!v.isValid())
925 continue;
926 if (prop.shaderDataType == QSSGRenderShaderValue::Texture) {
927 QQuick3DTexture *tex = textureFromValue(v);
928 QSSGRenderImage *ri = tex ? static_cast<QSSGRenderImage *>(QQuick3DObjectPrivate::get(tex)->spatialNode) : nullptr;
929 prop.value = QVariant::fromValue(ri);
930 } else if (prop.shaderDataType == QSSGRenderShaderValue::StorageBuffer) {
931 updateBufferProperty(v.value<QQuick3DShaderStorageBuffer *>(), prop);
932 } else if (prop.shaderDataType == QSSGRenderShaderValue::Image) {
933 updateImageProperty(v.value<QQuick3DShaderImage *>(), prop);
934 } else {
935 prop.value = v;
936 }
937 }
938}
939
940} // QSSGShaderUtils
941
942/*
943 Tracks the ShaderImage and ShaderStorageBuffer objects that the properties of
944 a CustomMaterial, an Effect, a RenderPass or a ComputePass refer to. The
945 objects are referenced into the owner's scene, so they get a backend node
946 even when they are declared outside the View3D, and onResourceChanged is
947 called when an image's format changes or an object is destroyed, as both
948 require the owner to regenerate its shaders.
949*/
950QQuick3DShaderResourceTracker::QQuick3DShaderResourceTracker(QQuick3DObject *owner, std::function<void()> onResourceChanged)
951 : m_owner(owner)
952 , m_onResourceChanged(std::move(onResourceChanged))
953{
954 Q_ASSERT(m_owner != nullptr);
955}
956
957QQuick3DShaderResourceTracker::~QQuick3DShaderResourceTracker()
958{
959 for (auto it = m_references.begin(), end = m_references.end(); it != end; ++it) {
960 QObject::disconnect(it->destroyedConnection);
961 QObject::disconnect(it->formatConnection);
962 QObject::disconnect(it->shapeConnection);
963 if (it->sceneManager)
964 QQuick3DObjectPrivate::get(it.key())->derefSceneManager();
965 }
966}
967
968/*
969 Returns the ShaderImage or ShaderStorageBuffer the property refers to.
970 isResourceProperty is set when the property is of one of those types,
971 even if it is null. An untyped (QtObject or var) property is only a
972 resource while it holds one, matching what
973 QQuick3DPropertyChangedTracker extracts.
974*/
975QQuick3DObject *QQuick3DShaderResourceTracker::resourceForProperty(const QObject *owner, const QMetaProperty &property,
976 bool *isResourceProperty)
977{
978 const QVariant value = property.read(owner);
979 QMetaType type = property.metaType();
980 if (type == QMetaType::fromType<QVariant>())
981 type = value.metaType();
982
983 QQuick3DObject *resource = nullptr;
984 bool isResource = false;
985 if (type == QMetaType::fromType<QQuick3DShaderStorageBuffer *>()) {
986 resource = value.value<QQuick3DShaderStorageBuffer *>();
987 isResource = true;
988 } else if (type == QMetaType::fromType<QQuick3DShaderImage *>()) {
989 resource = value.value<QQuick3DShaderImage *>();
990 isResource = true;
991 } else if (type == QMetaType::fromType<QObject *>()) {
992 // An untyped property is only known to be a resource while it holds one.
993 QObject *object = value.value<QObject *>();
994 if (auto *buffer = qobject_cast<QQuick3DShaderStorageBuffer *>(object))
995 resource = buffer;
996 else if (auto *image = qobject_cast<QQuick3DShaderImage *>(object))
997 resource = image;
998 isResource = (resource != nullptr);
999 }
1000
1001 if (isResourceProperty)
1002 *isResourceProperty = isResource;
1003 return resource;
1004}
1005
1006/*
1007 Replaces the tracked properties, mapping each property index to the
1008 object it refers to (or nullptr).
1009*/
1010void QQuick3DShaderResourceTracker::setResources(const QHash<int, QQuick3DObject *> &resources)
1011{
1012 // Reference the new objects before releasing the old ones, so that an
1013 // object that stays in use does not leave the scene in between.
1014 for (QQuick3DObject *object : resources) {
1015 if (object)
1016 addReference(object);
1017 }
1018 for (QQuick3DObject *object : std::as_const(m_resources)) {
1019 if (object)
1020 removeReference(object);
1021 }
1022
1023 m_resources = resources;
1024 m_boundLayouts.clear();
1025 for (auto it = resources.cbegin(), end = resources.cend(); it != end; ++it)
1026 m_boundLayouts.insert(it.key(), layoutKey(it.value()));
1027}
1028
1029/*
1030 Tracks the ShaderImage and ShaderStorageBuffer properties of the owner
1031 from \a firstPropertyIndex on, including null ones, and connects their
1032 notify signals to \a onPropertyChanged. For owners that do not otherwise
1033 go through their properties when they regenerate the shader.
1034*/
1035void QQuick3DShaderResourceTracker::trackProperties(int firstPropertyIndex, const QMetaMethod &onPropertyChanged)
1036{
1037 const QMetaObject *metaObject = m_owner->metaObject();
1038 QHash<int, QQuick3DObject *> resources;
1039 for (int i = firstPropertyIndex; i < metaObject->propertyCount(); ++i) {
1040 const QMetaProperty property = metaObject->property(i);
1041 bool isResource = false;
1042 QQuick3DObject *resource = resourceForProperty(m_owner, property, &isResource);
1043 if (!isResource)
1044 continue;
1045 resources.insert(i, resource);
1046 if (property.hasNotifySignal() && onPropertyChanged.isValid())
1047 QObject::connect(m_owner, property.notifySignal(), m_owner, onPropertyChanged, Qt::UniqueConnection);
1048 }
1049 setResources(resources);
1050}
1051
1052/*
1053 Re-reads the tracked properties after one of them has been assigned
1054 another object. Returns false if an object has no backend node yet.
1055 */
1056bool QQuick3DShaderResourceTracker::updateResources()
1057{
1058 QHash<int, QQuick3DObject *> resources;
1059 bool allHaveNodes = true;
1060 for (auto it = m_resources.cbegin(), end = m_resources.cend(); it != end; ++it) {
1061 QQuick3DObject *object = resourceForProperty(m_owner, m_owner->metaObject()->property(it.key()));
1062 resources.insert(it.key(), object);
1063 if (object && !QQuick3DObjectPrivate::get(object)->spatialNode)
1064 allHaveNodes = false;
1065 }
1066 setResources(resources);
1067 return allHaveNodes;
1068}
1069
1070/*
1071 True when a tracked property has gained or lost its object, or now refers
1072 to an image of another format, since the last setResources(). Swapping
1073 one object for another of the same kind does not count, as that only
1074 changes the binding, not the generated shader.
1075*/
1076bool QQuick3DShaderResourceTracker::hasResourceLayoutChanged() const
1077{
1078 for (auto it = m_boundLayouts.cbegin(), end = m_boundLayouts.cend(); it != end; ++it) {
1079 const QMetaProperty property = m_owner->metaObject()->property(it.key());
1080 if (layoutKey(resourceForProperty(m_owner, property)) != it.value())
1081 return true;
1082 }
1083 return false;
1084}
1085
1086/*
1087 The part of an object that ends up in the generated shader: whether
1088 there is one, and for an image, its format and shape.
1089*/
1090QByteArray QQuick3DShaderResourceTracker::layoutKey(QQuick3DObject *object)
1091{
1092 if (!object)
1093 return {};
1094 if (auto *image = qobject_cast<QQuick3DShaderImage *>(object))
1095 return QByteArrayLiteral("image:") + QSSGShaderUtils::toShaderFormat(image->format()) + ':'
1096 + QSSGShaderUtils::toShaderImageType(image->shape(), image->format());
1097 return QByteArrayLiteral("buffer");
1098}
1099
1100void QQuick3DShaderResourceTracker::updateSceneManager(QQuick3DSceneManager *sceneManager)
1101{
1102 for (auto it = m_references.begin(), end = m_references.end(); it != end; ++it) {
1103 if (it->sceneManager)
1104 QQuick3DObjectPrivate::get(it.key())->derefSceneManager();
1105 it->sceneManager = sceneManager;
1106 if (sceneManager)
1107 QQuick3DObjectPrivate::get(it.key())->refSceneManager(*sceneManager);
1108 }
1109}
1110
1111void QQuick3DShaderResourceTracker::addReference(QQuick3DObject *object)
1112{
1113 auto it = m_references.find(object);
1114 if (it == m_references.end()) {
1115 it = m_references.insert(object, {});
1116 if (QQuick3DSceneManager *sceneManager = QQuick3DObjectPrivate::get(m_owner)->sceneManager) {
1117 QQuick3DObjectPrivate::get(object)->refSceneManager(*sceneManager);
1118 it->sceneManager = sceneManager;
1119 }
1120 // The object is already being torn down when destroyed() is emitted,
1121 // so only forget it here, without releasing its scene reference.
1122 it->destroyedConnection = QObject::connect(object, &QObject::destroyed, m_owner, [this, object]() {
1123 m_references.remove(object);
1124 for (QQuick3DObject *&resource : m_resources) {
1125 if (resource == object)
1126 resource = nullptr;
1127 }
1128 m_onResourceChanged();
1129 });
1130 // The format and the shape are part of the generated image declaration.
1131 if (auto *image = qobject_cast<QQuick3DShaderImage *>(object)) {
1132 it->formatConnection = QObject::connect(image, &QQuick3DShaderImage::formatChanged, m_owner, [this]() { m_onResourceChanged(); });
1133 it->shapeConnection = QObject::connect(image, &QQuick3DShaderImage::shapeChanged, m_owner, [this]() { m_onResourceChanged(); });
1134 }
1135 }
1136 ++it->useCount;
1137}
1138
1139void QQuick3DShaderResourceTracker::removeReference(QQuick3DObject *object)
1140{
1141 auto it = m_references.find(object);
1142 if (it == m_references.end() || --it->useCount > 0)
1143 return;
1144
1145 QObject::disconnect(it->destroyedConnection);
1146 QObject::disconnect(it->formatConnection);
1147 QObject::disconnect(it->shapeConnection);
1148 if (it->sceneManager)
1149 QQuick3DObjectPrivate::get(object)->derefSceneManager();
1150 m_references.erase(it);
1151}
1152
1153QQuick3DShaderUtilsBuffer::TextureFormat QQuick3DShaderUtilsBuffer::mapRenderTextureFormat(QSSGRenderTextureFormat::Format fmt)
1154{
1155 using TextureFormat = QQuick3DShaderUtilsBuffer::TextureFormat;
1156 switch (fmt) {
1157 case QSSGRenderTextureFormat::RGBA8: return TextureFormat::RGBA8;
1158 case QSSGRenderTextureFormat::RGBA16F: return TextureFormat::RGBA16F;
1159 case QSSGRenderTextureFormat::RGBA32F: return TextureFormat::RGBA32F;
1160 case QSSGRenderTextureFormat::R8: return TextureFormat::R8;
1161 case QSSGRenderTextureFormat::R16: return TextureFormat::R16;
1162 case QSSGRenderTextureFormat::R16F: return TextureFormat::R16F;
1163 case QSSGRenderTextureFormat::R32F: return TextureFormat::R32F;
1164 default:
1165 break;
1166 }
1167 return TextureFormat::Unknown;
1168}
1169
1170QSSGRenderTextureFormat::Format QQuick3DShaderUtilsBuffer::mapTextureFormat(QQuick3DShaderUtilsBuffer::TextureFormat fmt)
1171{
1172 using TextureFormat = QQuick3DShaderUtilsBuffer::TextureFormat;
1173 switch (fmt) {
1174 case TextureFormat::RGBA8: return QSSGRenderTextureFormat::RGBA8;
1175 case TextureFormat::RGBA16F: return QSSGRenderTextureFormat::RGBA16F;
1176 case TextureFormat::RGBA32F: return QSSGRenderTextureFormat::RGBA32F;
1177 case TextureFormat::R8: return QSSGRenderTextureFormat::R8;
1178 case TextureFormat::R16: return QSSGRenderTextureFormat::R16;
1179 case TextureFormat::R16F: return QSSGRenderTextureFormat::R16F;
1180 case TextureFormat::R32F: return QSSGRenderTextureFormat::R32F;
1181 default:
1182 break;
1183 }
1184 return QSSGRenderTextureFormat::Unknown;
1185}
1186
1187QQuick3DShaderUtilsBuffer::TextureFormat QQuick3DShaderUtilsBuffer::format() const
1188{
1189 return mapRenderTextureFormat(command.m_format.format);
1190}
1191
1192void QQuick3DShaderUtilsBuffer::setFormat(TextureFormat format)
1193{
1194 QSSGRenderTextureFormat::Format mappedTextureFormat = mapTextureFormat(format);
1195 if (command.m_format == mappedTextureFormat)
1196 return;
1197
1198 command.m_format = mappedTextureFormat;
1199 emit changed();
1200}
1201
1202void QQuick3DShaderUtilsBuffer::setTextureFilterOperation(TextureFilterOperation op)
1203{
1204 if (command.m_filterOp == QSSGRenderTextureFilterOp(op))
1205 return;
1206
1207 command.m_filterOp = QSSGRenderTextureFilterOp(op);
1208 emit changed();
1209}
1210
1211void QQuick3DShaderUtilsBuffer::setTextureCoordOperation(TextureCoordOperation texCoordOp)
1212{
1213 if (command.m_texCoordOp == QSSGRenderTextureCoordOp(texCoordOp))
1214 return;
1215
1216 command.m_texCoordOp = QSSGRenderTextureCoordOp(texCoordOp);
1217 emit changed();
1218}
1219
1220void QQuick3DShaderUtilsBuffer::setBufferFlags(AllocateBufferFlagValues flag)
1221{
1222 if (quint32(command.m_bufferFlags) == quint32(flag))
1223 return;
1224
1225 command.m_bufferFlags = quint32(flag);
1226 emit changed();
1227}
1228
1229QQuick3DShaderUtilsRenderPass::~QQuick3DShaderUtilsRenderPass()
1230{
1231
1232}
1233
1234void QQuick3DShaderUtilsRenderPass::qmlAppendCommand(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list,
1235 QQuick3DShaderUtilsRenderCommand *command)
1236{
1237 if (!command)
1238 return;
1239
1240 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1241 that->m_commands.push_back(command);
1242 emit that->changed();
1243}
1244
1245QQuick3DShaderUtilsRenderCommand *QQuick3DShaderUtilsRenderPass::qmlCommandAt(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list,
1246 qsizetype index)
1247{
1248 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1249 return that->m_commands.at(index);
1250}
1251
1252qsizetype QQuick3DShaderUtilsRenderPass::qmlCommandCount(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list)
1253{
1254 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1255 return that->m_commands.size();
1256}
1257
1258void QQuick3DShaderUtilsRenderPass::qmlCommandClear(QQmlListProperty<QQuick3DShaderUtilsRenderCommand> *list)
1259{
1260 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1261 that->m_commands.clear();
1262 emit that->changed();
1263}
1264
1265QQmlListProperty<QQuick3DShaderUtilsRenderCommand> QQuick3DShaderUtilsRenderPass::commands()
1266{
1267 return QQmlListProperty<QQuick3DShaderUtilsRenderCommand>(this,
1268 nullptr,
1269 QQuick3DShaderUtilsRenderPass::qmlAppendCommand,
1270 QQuick3DShaderUtilsRenderPass::qmlCommandCount,
1271 QQuick3DShaderUtilsRenderPass::qmlCommandAt,
1272 QQuick3DShaderUtilsRenderPass::qmlCommandClear);
1273}
1274
1275void QQuick3DShaderUtilsRenderPass::qmlAppendShader(QQmlListProperty<QQuick3DShaderUtilsShader> *list,
1276 QQuick3DShaderUtilsShader *shader)
1277{
1278 if (!shader)
1279 return;
1280
1281 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1282
1283 // An append implementation CANNOT rely on the object (shader in this case)
1284 // being complete. When the list references a Shader object living under
1285 // another Effect, its properties may not be set at the point of this
1286 // function being called, so accessing shader->stage is not allowed since
1287 // it may still have its default value, not what is set from QML...
1288
1289 // the only thing we can do is to append to our list, do not try to be clever
1290 that->m_shaders.append(shader);
1291
1292 connect(shader, &QQuick3DShaderUtilsShader::shaderChanged, that, &QQuick3DShaderUtilsRenderPass::changed);
1293 connect(shader, &QQuick3DShaderUtilsShader::stageChanged, that, &QQuick3DShaderUtilsRenderPass::changed);
1294
1295 emit that->changed();
1296}
1297
1298QQuick3DShaderUtilsShader *QQuick3DShaderUtilsRenderPass::qmlShaderAt(QQmlListProperty<QQuick3DShaderUtilsShader> *list,
1299 qsizetype index)
1300{
1301 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1302 return that->m_shaders.at(index);
1303}
1304
1305qsizetype QQuick3DShaderUtilsRenderPass::qmlShaderCount(QQmlListProperty<QQuick3DShaderUtilsShader> *list)
1306{
1307 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1308 return that->m_shaders.size();
1309}
1310
1311void QQuick3DShaderUtilsRenderPass::qmlShaderClear(QQmlListProperty<QQuick3DShaderUtilsShader> *list)
1312{
1313 QQuick3DShaderUtilsRenderPass *that = qobject_cast<QQuick3DShaderUtilsRenderPass *>(list->object);
1314
1315 for (QQuick3DShaderUtilsShader *shader : that->m_shaders)
1316 shader->disconnect(that);
1317
1318 that->m_shaders.clear();
1319
1320 emit that->changed();
1321}
1322
1323QQmlListProperty<QQuick3DShaderUtilsShader> QQuick3DShaderUtilsRenderPass::shaders()
1324{
1325 return QQmlListProperty<QQuick3DShaderUtilsShader>(this,
1326 nullptr,
1327 QQuick3DShaderUtilsRenderPass::qmlAppendShader,
1328 QQuick3DShaderUtilsRenderPass::qmlShaderCount,
1329 QQuick3DShaderUtilsRenderPass::qmlShaderAt,
1330 QQuick3DShaderUtilsRenderPass::qmlShaderClear);
1331}
1332
1333QQuick3DShaderUtilsTextureInput::QQuick3DShaderUtilsTextureInput(QQuick3DObject *p) : QQuick3DObject(p) {}
1334
1335QQuick3DShaderUtilsTextureInput::~QQuick3DShaderUtilsTextureInput()
1336{
1337}
1338
1339void QQuick3DShaderUtilsTextureInput::setTexture(QQuick3DTexture *texture)
1340{
1341 if (m_texture == texture)
1342 return;
1343
1344 QObject *p = parent();
1345 while (p != nullptr) {
1346 if (QQuick3DCustomMaterial *mat = qobject_cast<QQuick3DCustomMaterial *>(p)) {
1347 mat->setDynamicTextureMap(this);
1348 QQuick3DObjectPrivate::attachWatcherPriv(mat, this, &QQuick3DShaderUtilsTextureInput::setTexture, texture, m_texture);
1349 break;
1350 } else if (QQuick3DEffect *efx = qobject_cast<QQuick3DEffect *>(p)) {
1351 efx->setDynamicTextureMap(this);
1352 QQuick3DObjectPrivate::attachWatcherPriv(efx, this, &QQuick3DShaderUtilsTextureInput::setTexture, texture, m_texture);
1353 break;
1354 }
1355 p = p->parent();
1356 }
1357
1358 if (p == nullptr) {
1359 qWarning("A TextureInput was defined without a CustomMaterial or Effect ancestor. This should be avoided.");
1360 }
1361
1362 m_texture = texture;
1363 Q_EMIT textureChanged();
1364}
1365
1366/*!
1367 \qmltype RenderablesFilter
1368 \inherits Command
1369 \inqmlmodule QtQuick3D
1370 \brief Defines a filter for selecting which renderables to affect in a \l {RenderPass}{pass}.
1371 \since 6.11
1372
1373 The RenderablesFilter type is used to specify which renderables in the scene
1374 should be affected by a \l RenderPass. By setting the \c renderableTypes property,
1375 you can control whether the pass affects opaque objects, transparent objects, or
1376 no objects at all.
1377
1378 Setting \c renderableTypes to \c None is useful when a RenderPass acts as a container
1379 for \l SubRenderPass commands and should not render any scene objects itself.
1380
1381 In addition to filtering by renderable types, you can use the \l {RenderablesFilter::layerMask}{layerMask}
1382 to further refine which renderables are affected based on their assigned \l{Node::layers}{layers}.
1383
1384 \qml
1385 // A pass that renders only opaque scene objects
1386 RenderPass {
1387 id: opaquePass
1388 commands: [
1389 ColorAttachment { name: "color0"; target: opaqueColorTexture },
1390 DepthTextureAttachment { target: depthTexture },
1391 RenderablesFilter {
1392 renderableTypes: RenderablesFilter.Opaque
1393 }
1394 ]
1395 }
1396
1397 // A pass that renders only transparent objects on top
1398 RenderPass {
1399 id: transparentPass
1400 commands: [
1401 ColorAttachment { name: "color0"; target: transparentColorTexture },
1402 RenderablesFilter {
1403 renderableTypes: RenderablesFilter.Transparent
1404 }
1405 ]
1406 }
1407 \endqml
1408*/
1409
1410/*!
1411 \qmlproperty int RenderablesFilter::layerMask
1412 Sets the layer mask for the filter. Only renderables on the specified layers will be affected by the filter.
1413
1414 \sa Node::layers
1415*/
1416
1417/*!
1418 \qmlproperty enumeration RenderablesFilter::renderableTypes
1419 Sets the types of renderables that the filter will affect.
1420
1421 \value RenderablesFilter.None No renderables will be rendered. Useful for container passes that only have SubRenderPasses.
1422 \value RenderablesFilter.Opaque Only opaque renderables will be rendered.
1423 \value RenderablesFilter.Transparent Only transparent renderables will be rendered.
1424
1425 \note Multiple values can be combined using the | operator.
1426
1427 \default RenderablesFilter.Opaque | RenderablesFilter.Transparent
1428*/
1429QQuick3DShaderUtilsRenderablesFilter::RenderableTypes QQuick3DShaderUtilsRenderablesFilter::renderableTypes() const
1430{
1431 return static_cast<QQuick3DShaderUtilsRenderablesFilter::RenderableTypes>(command.renderableTypes);
1432}
1433
1434QQuick3DShaderUtilsRenderablesFilter::~QQuick3DShaderUtilsRenderablesFilter()
1435{
1436
1437}
1438
1439void QQuick3DShaderUtilsRenderablesFilter::setRenderableTypes(RenderableTypes types)
1440{
1441 command.renderableTypes = static_cast<QSSGRenderablesFilterCommand::RenderableTypeT>(types.toInt());
1442}
1443
1444QQuick3DShaderUtilsPipelineStateOverride::QQuick3DShaderUtilsPipelineStateOverride()
1445{
1446 // Forward all our own signals to the base class changed() signal so that
1447 // QQuick3DRenderPass can connect once and be notified of any change.
1448 const QMetaObject *mo = metaObject();
1449 const QMetaMethod changedSignal = QMetaMethod::fromSignal(&QQuick3DShaderUtilsRenderCommand::changed);
1450 for (int i = QQuick3DShaderUtilsRenderCommand::staticMetaObject.methodCount(); i < mo->methodCount(); ++i) {
1451 const QMetaMethod mm = mo->method(i);
1452 if (mm.methodType() == QMetaMethod::Signal)
1453 connect(this, mm, this, changedSignal);
1454 }
1455}
1456
1457QQuick3DShaderUtilsPipelineStateOverride::~QQuick3DShaderUtilsPipelineStateOverride()
1458{
1459
1460}
1461
1462/*!
1463 \qmlproperty bool PipelineStateOverride::depthTestEnabled
1464 If set to \c true, enables depth testing for the render pass. If set to \c false, disables depth testing.
1465 Setting this property to \c true requires a depth attachment for the render pass.
1466*/
1467bool QQuick3DShaderUtilsPipelineStateOverride::depthTestEnabled() const
1468{
1469 if (command.m_depthTestEnabled)
1470 return *command.m_depthTestEnabled;
1471 return false;
1472}
1473
1474void QQuick3DShaderUtilsPipelineStateOverride::setDepthTestEnabled(bool newDepthTestEnabled)
1475{
1476 if (command.m_depthTestEnabled && *command.m_depthTestEnabled == newDepthTestEnabled)
1477 return;
1478 command.m_depthTestEnabled = newDepthTestEnabled;
1479 emit depthTestEnabledChanged();
1480}
1481
1482void QQuick3DShaderUtilsPipelineStateOverride::resetDepthTestEnabled()
1483{
1484 command.m_depthTestEnabled.reset();
1485 emit depthTestEnabledChanged();
1486}
1487
1488/*!
1489 \qmlproperty bool PipelineStateOverride::depthWriteEnabled
1490 If set to \c true, enables depth writing for the render pass. If set to \c false, disables depth writing.
1491 Setting this property to \c true requires a depth attachment for the render pass.
1492*/
1493bool QQuick3DShaderUtilsPipelineStateOverride::depthWriteEnabled() const
1494{
1495 if (command.m_depthWriteEnabled)
1496 return *command.m_depthWriteEnabled;
1497 return false;
1498}
1499
1500void QQuick3DShaderUtilsPipelineStateOverride::setDepthWriteEnabled(bool newDepthWriteEnabled)
1501{
1502 if (command.m_depthWriteEnabled && *command.m_depthWriteEnabled == newDepthWriteEnabled)
1503 return;
1504 command.m_depthWriteEnabled = newDepthWriteEnabled;
1505 emit depthWriteEnabledChanged();
1506}
1507
1508void QQuick3DShaderUtilsPipelineStateOverride::resetDepthWriteEnabled()
1509{
1510 command.m_depthWriteEnabled.reset();
1511 emit depthWriteEnabledChanged();
1512}
1513
1514/*!
1515 \qmlproperty bool PipelineStateOverride::blendEnabled
1516 If set to \c true, enables blending for the render pass. If set to \c false, disables blending.
1517 For per-attachment blend settings, use the \c targetBlend0 through \c targetBlend7 properties.
1518*/
1519bool QQuick3DShaderUtilsPipelineStateOverride::blendEnabled() const
1520{
1521 if (command.m_blendEnabled)
1522 return *command.m_blendEnabled;
1523 return false;
1524}
1525
1526void QQuick3DShaderUtilsPipelineStateOverride::setBlendEnabled(bool newBlendEnabled)
1527{
1528 if (command.m_blendEnabled && *command.m_blendEnabled == newBlendEnabled)
1529 return;
1530 command.m_blendEnabled = newBlendEnabled;
1531 emit blendEnabledChanged();
1532}
1533
1534void QQuick3DShaderUtilsPipelineStateOverride::resetBlendEnabled()
1535{
1536 command.m_blendEnabled.reset();
1537 emit blendEnabledChanged();
1538}
1539
1540/*!
1541 \qmlproperty bool PipelineStateOverride::usesStencilReference
1542 If set to \c true, enables the use of the stencil reference value for the render pass. If set to \c false,
1543 disables the use of the stencil reference value.
1544*/
1545bool QQuick3DShaderUtilsPipelineStateOverride::usesStencilReference() const
1546{
1547 if (command.m_usesStencilReference)
1548 return *command.m_usesStencilReference;
1549 return false;
1550}
1551
1552void QQuick3DShaderUtilsPipelineStateOverride::setUsesStencilReference(bool newUsesStencilReference)
1553{
1554 if (command.m_usesStencilReference && *command.m_usesStencilReference == newUsesStencilReference)
1555 return;
1556 command.m_usesStencilReference = newUsesStencilReference;
1557 emit usesStencilReferenceChanged();
1558}
1559
1560void QQuick3DShaderUtilsPipelineStateOverride::resetUsesStencilReference()
1561{
1562 command.m_usesStencilReference.reset();
1563 emit usesStencilReferenceChanged();
1564}
1565
1566/*!
1567 \qmlproperty bool PipelineStateOverride::usesScissor
1568 If set to \c true, enables scissor testing for the render pass. If set to \c false,
1569 disables the scissor test. Use the \c scissor property to set the scissor rectangle.
1570*/
1571bool QQuick3DShaderUtilsPipelineStateOverride::usesScissor() const
1572{
1573 if (command.m_usesScissor)
1574 return *command.m_usesScissor;
1575 return false;
1576}
1577
1578void QQuick3DShaderUtilsPipelineStateOverride::setUsesScissor(bool newUsesScissor)
1579{
1580 if (command.m_usesScissor && *command.m_usesScissor == newUsesScissor)
1581 return;
1582 command.m_usesScissor = newUsesScissor;
1583 emit usesScissorChanged();
1584}
1585
1586void QQuick3DShaderUtilsPipelineStateOverride::resetUsesScissor()
1587{
1588 command.m_usesScissor.reset();
1589 emit usesScissorChanged();
1590}
1591
1592/*!
1593 \qmlproperty enumeration PipelineStateOverride::depthFunction
1594 Sets the depth comparison function for the render pass.
1595
1596 \value PipelineStateOverride.Never The depth test never passes.
1597 \value PipelineStateOverride.Less The depth test passes when the incoming depth is less than the stored depth.
1598 \value PipelineStateOverride.Equal The depth test passes when the incoming depth equals the stored depth.
1599 \value PipelineStateOverride.LessOrEqual The depth test passes when the incoming depth is less than or equal to the stored depth.
1600 \value PipelineStateOverride.Greater The depth test passes when the incoming depth is greater than the stored depth.
1601 \value PipelineStateOverride.NotEqual The depth test passes when the incoming depth does not equal the stored depth.
1602 \value PipelineStateOverride.GreaterOrEqual The depth test passes when the incoming depth is greater than or equal to the stored depth.
1603 \value PipelineStateOverride.Always The depth test always passes.
1604*/
1605QQuick3DShaderUtilsPipelineStateOverride::CompareOperation QQuick3DShaderUtilsPipelineStateOverride::depthFunction() const
1606{
1607 if (command.m_depthFunction)
1608 return CompareOperation(*command.m_depthFunction);
1609 return CompareOperation::Less;
1610}
1611
1612void QQuick3DShaderUtilsPipelineStateOverride::setDepthFunction(CompareOperation newDepthFunction)
1613{
1614 if (command.m_depthFunction && *command.m_depthFunction == QRhiGraphicsPipeline::CompareOp(newDepthFunction))
1615 return;
1616 command.m_depthFunction = QRhiGraphicsPipeline::CompareOp(newDepthFunction);
1617 emit depthFunctionChanged();
1618}
1619
1620void QQuick3DShaderUtilsPipelineStateOverride::resetDepthFunction()
1621{
1622 command.m_depthFunction.reset();
1623 emit depthFunctionChanged();
1624}
1625
1626/*!
1627 \qmlproperty enumeration PipelineStateOverride::cullMode
1628 Sets the face culling mode for the render pass.
1629
1630 \value PipelineStateOverride.None No face culling.
1631 \value PipelineStateOverride.Front Front-facing polygons are culled.
1632 \value PipelineStateOverride.Back Back-facing polygons are culled.
1633*/
1634QQuick3DShaderUtilsPipelineStateOverride::CullMode QQuick3DShaderUtilsPipelineStateOverride::cullMode() const
1635{
1636 if (command.m_cullMode)
1637 return CullMode(*command.m_cullMode);
1638 return CullMode::Back;
1639}
1640
1641void QQuick3DShaderUtilsPipelineStateOverride::setCullMode(CullMode newCullMode)
1642{
1643 if (command.m_cullMode && *command.m_cullMode == QRhiGraphicsPipeline::CullMode(newCullMode))
1644 return;
1645 command.m_cullMode = QRhiGraphicsPipeline::CullMode(newCullMode);
1646 emit cullModeChanged();
1647}
1648
1649void QQuick3DShaderUtilsPipelineStateOverride::resetCullMode()
1650{
1651 command.m_cullMode.reset();
1652 emit cullModeChanged();
1653}
1654
1655/*!
1656 \qmlproperty enumeration PipelineStateOverride::polygonMode
1657 Sets the polygon rasterization mode for the render pass.
1658
1659 \value PipelineStateOverride.Fill Polygons are filled (default).
1660 \value PipelineStateOverride.Line Polygon edges are drawn as lines (wireframe).
1661*/
1662QQuick3DShaderUtilsPipelineStateOverride::PolygonMode QQuick3DShaderUtilsPipelineStateOverride::polygonMode() const
1663{
1664 if (command.m_polygonMode)
1665 return PolygonMode(*command.m_polygonMode);
1666 return PolygonMode::Fill;
1667}
1668
1669void QQuick3DShaderUtilsPipelineStateOverride::setPolygonMode(PolygonMode newPolygonMode)
1670{
1671 if (command.m_polygonMode && *command.m_polygonMode == QRhiGraphicsPipeline::PolygonMode(newPolygonMode))
1672 return;
1673 command.m_polygonMode = QRhiGraphicsPipeline::PolygonMode(newPolygonMode);
1674 emit polygonModeChanged();
1675}
1676
1677void QQuick3DShaderUtilsPipelineStateOverride::resetPolygonMode()
1678{
1679 command.m_polygonMode.reset();
1680 emit polygonModeChanged();
1681}
1682
1683/*!
1684 \qmlproperty uint PipelineStateOverride::stencilWriteMask
1685 Sets the stencil write mask for the render pass. Each bit controls whether the corresponding
1686 bit in the stencil buffer can be written.
1687*/
1688quint32 QQuick3DShaderUtilsPipelineStateOverride::stencilWriteMask() const
1689{
1690 if (command.m_stencilWriteMask)
1691 return *command.m_stencilWriteMask;
1692 return 0;
1693}
1694
1695void QQuick3DShaderUtilsPipelineStateOverride::setStencilWriteMask(quint32 newStencilWriteMask)
1696{
1697 if (command.m_stencilWriteMask && *command.m_stencilWriteMask == newStencilWriteMask)
1698 return;
1699 command.m_stencilWriteMask = newStencilWriteMask;
1700 emit stencilWriteMaskChanged();
1701}
1702
1703void QQuick3DShaderUtilsPipelineStateOverride::resetStencilWriteMask()
1704{
1705 command.m_stencilWriteMask.reset();
1706 emit stencilWriteMaskChanged();
1707}
1708
1709/*!
1710 \qmlproperty uint PipelineStateOverride::stencilReference
1711 Sets the stencil reference value for the render pass. This value is used in stencil
1712 comparison operations when \c usesStencilReference is \c true.
1713*/
1714quint32 QQuick3DShaderUtilsPipelineStateOverride::stencilReference() const
1715{
1716 if (command.m_stencilReference)
1717 return *command.m_stencilReference;
1718 return 0;
1719}
1720
1721void QQuick3DShaderUtilsPipelineStateOverride::setStencilReference(quint32 newStencilReference)
1722{
1723 if (command.m_stencilReference && *command.m_stencilReference == newStencilReference)
1724 return;
1725 command.m_stencilReference = newStencilReference;
1726 emit stencilReferenceChanged();
1727}
1728
1729void QQuick3DShaderUtilsPipelineStateOverride::resetStencilReference()
1730{
1731 command.m_stencilReference.reset();
1732 emit stencilReferenceChanged();
1733}
1734
1735/*!
1736 \qmlproperty rect PipelineStateOverride::viewport
1737 Sets the viewport rectangle for the render pass. The rectangle specifies the region
1738 of the render target to draw into, in pixels (x, y, width, height).
1739 If not set, the full render target dimensions are used.
1740*/
1741QRectF QQuick3DShaderUtilsPipelineStateOverride::viewport() const
1742{
1743 if (command.m_viewport) {
1744 const QRhiViewport &vp = *command.m_viewport;
1745 return QRectF(vp.viewport()[0], vp.viewport()[1], vp.viewport()[2], vp.viewport()[3]);
1746 }
1747 return QRectF();
1748}
1749
1750void QQuick3DShaderUtilsPipelineStateOverride::setViewport(const QRectF &newViewport)
1751{
1752 if (command.m_viewport) {
1753 const QRhiViewport &vp = *command.m_viewport;
1754 if (vp.viewport()[0] == newViewport.x() &&
1755 vp.viewport()[1] == newViewport.y() &&
1756 vp.viewport()[2] == newViewport.width() &&
1757 vp.viewport()[3] == newViewport.height())
1758 return;
1759 }
1760 command.m_viewport = QRhiViewport(newViewport.x(), newViewport.y(), newViewport.width(), newViewport.height());
1761 emit viewportChanged();
1762}
1763
1764void QQuick3DShaderUtilsPipelineStateOverride::resetViewport()
1765{
1766 command.m_viewport.reset();
1767 emit viewportChanged();
1768}
1769
1770/*!
1771 \qmlproperty rect PipelineStateOverride::scissor
1772 Sets the scissor rectangle for the render pass. Fragments outside this rectangle are
1773 discarded. Requires \c usesScissor to be \c true.
1774*/
1775QRect QQuick3DShaderUtilsPipelineStateOverride::scissor() const
1776{
1777 if (command.m_scissor) {
1778 const QRhiScissor &sc = *command.m_scissor;
1779 return QRect(sc.scissor()[0], sc.scissor()[1], sc.scissor()[2], sc.scissor()[3]);
1780 }
1781 return QRect();
1782}
1783
1784void QQuick3DShaderUtilsPipelineStateOverride::setScissor(const QRect &newScissor)
1785{
1786 if (command.m_viewport) {
1787 const QRhiScissor &sc = *command.m_scissor;
1788 if (sc.scissor()[0] == newScissor.x() &&
1789 sc.scissor()[1] == newScissor.y() &&
1790 sc.scissor()[2] == newScissor.width() &&
1791 sc.scissor()[3] == newScissor.height())
1792 return;
1793 }
1794 command.m_scissor = QRhiScissor(newScissor.x(), newScissor.y(), newScissor.width(), newScissor.height());
1795 emit scissorChanged();
1796}
1797
1798void QQuick3DShaderUtilsPipelineStateOverride::resetScissor()
1799{
1800 command.m_scissor.reset();
1801}
1802
1803/*!
1804 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend0
1805 Sets the blending parameters for color attachment 0 of the render pass.
1806 \sa renderTargetBlend
1807*/
1808QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend0() const
1809{
1810 if (command.m_targetBlend0)
1811 return *command.m_targetBlend0;
1812 return {};
1813}
1814
1815void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend0(const QQuick3DRenderPassTargetBlend &newTargetBlend0)
1816{
1817 if (command.m_targetBlend0 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend0) == newTargetBlend0)
1818 return;
1819
1820 command.m_targetBlend0 = newTargetBlend0.toRhiTargetBlend();;
1821 emit targetBlend0Changed();
1822}
1823
1824void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend0()
1825{
1826 command.m_targetBlend0.reset();
1827 emit targetBlend0Changed();
1828}
1829
1830/*!
1831 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend1
1832 Sets the blending parameters for color attachment 1 of the render pass.
1833 \sa renderTargetBlend
1834*/
1835QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend1() const
1836{
1837 if (command.m_targetBlend1)
1838 return *command.m_targetBlend1;
1839 return {};
1840}
1841
1842void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend1(const QQuick3DRenderPassTargetBlend &newTargetBlend1)
1843{
1844 if (command.m_targetBlend1 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend1) == newTargetBlend1)
1845 return;
1846 command.m_targetBlend1 = newTargetBlend1.toRhiTargetBlend();
1847 emit targetBlend1Changed();
1848}
1849
1850void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend1()
1851{
1852 command.m_targetBlend1.reset();
1853 emit targetBlend1Changed();
1854}
1855
1856/*!
1857 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend2
1858 Sets the blending parameters for color attachment 2 of the render pass.
1859 \sa renderTargetBlend
1860*/
1861QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend2() const
1862{
1863 if (command.m_targetBlend2)
1864 return *command.m_targetBlend2;
1865 return {};
1866}
1867
1868void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend2(const QQuick3DRenderPassTargetBlend &newTargetBlend2)
1869{
1870 if (command.m_targetBlend2 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend2) == newTargetBlend2)
1871 return;
1872 command.m_targetBlend2 = newTargetBlend2.toRhiTargetBlend();
1873 emit targetBlend2Changed();
1874}
1875
1876void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend2()
1877{
1878 command.m_targetBlend2.reset();
1879 emit targetBlend2Changed();
1880}
1881
1882/*!
1883 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend3
1884 Sets the blending parameters for color attachment 3 of the render pass.
1885 \sa renderTargetBlend
1886*/
1887QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend3() const
1888{
1889 if (command.m_targetBlend3)
1890 return *command.m_targetBlend3;
1891 return {};
1892}
1893
1894void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend3(const QQuick3DRenderPassTargetBlend &newTargetBlend3)
1895{
1896 if (command.m_targetBlend3 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend3) == newTargetBlend3)
1897 return;
1898 command.m_targetBlend3 = newTargetBlend3.toRhiTargetBlend();
1899 emit targetBlend3Changed();
1900}
1901
1902void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend3()
1903{
1904 command.m_targetBlend3.reset();
1905 emit targetBlend3Changed();
1906}
1907
1908/*!
1909 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend4
1910 Sets the blending parameters for color attachment 4 of the render pass.
1911 \sa renderTargetBlend
1912*/
1913QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend4() const
1914{
1915 if (command.m_targetBlend4)
1916 return *command.m_targetBlend4;
1917 return {};
1918}
1919
1920void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend4(const QQuick3DRenderPassTargetBlend &newTargetBlend4)
1921{
1922 if (command.m_targetBlend4 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend4) == newTargetBlend4)
1923 return;
1924 command.m_targetBlend4 = newTargetBlend4.toRhiTargetBlend();
1925 emit targetBlend4Changed();
1926}
1927
1928void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend4()
1929{
1930 command.m_targetBlend4.reset();
1931 emit targetBlend4Changed();
1932}
1933
1934/*!
1935 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend5
1936 Sets the blending parameters for color attachment 5 of the render pass.
1937 \sa renderTargetBlend
1938*/
1939QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend5() const
1940{
1941 if (command.m_targetBlend5)
1942 return *command.m_targetBlend5;
1943 return {};
1944}
1945
1946void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend5(const QQuick3DRenderPassTargetBlend &newTargetBlend5)
1947{
1948 if (command.m_targetBlend5 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend5) == newTargetBlend5)
1949 return;
1950 command.m_targetBlend5 = newTargetBlend5.toRhiTargetBlend();
1951 emit targetBlend5Changed();
1952}
1953
1954void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend5()
1955{
1956 command.m_targetBlend5.reset();
1957 emit targetBlend5Changed();
1958}
1959
1960/*!
1961 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend6
1962 Sets the blending parameters for color attachment 6 of the render pass.
1963 \sa renderTargetBlend
1964*/
1965QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend6() const
1966{
1967 if (command.m_targetBlend6)
1968 return *command.m_targetBlend6;
1969 return {};
1970}
1971
1972void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend6(const QQuick3DRenderPassTargetBlend &newTargetBlend6)
1973{
1974 if (command.m_targetBlend6 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend6) == newTargetBlend6)
1975 return;
1976 command.m_targetBlend6 = newTargetBlend6.toRhiTargetBlend();
1977 emit targetBlend6Changed();
1978}
1979
1980void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend6()
1981{
1982 command.m_targetBlend6.reset();
1983 emit targetBlend6Changed();
1984}
1985
1986/*!
1987 \qmlproperty renderTargetBlend PipelineStateOverride::targetBlend7
1988 Sets the blending parameters for color attachment 7 of the render pass.
1989 \sa renderTargetBlend
1990*/
1991QQuick3DRenderPassTargetBlend QQuick3DShaderUtilsPipelineStateOverride::targetBlend7() const
1992{
1993 if (command.m_targetBlend7)
1994 return *command.m_targetBlend7;
1995 return {};
1996}
1997
1998void QQuick3DShaderUtilsPipelineStateOverride::setTargetBlend7(const QQuick3DRenderPassTargetBlend &newTargetBlend7)
1999{
2000 if (command.m_targetBlend7 && QQuick3DRenderPassTargetBlend(*command.m_targetBlend7) == newTargetBlend7)
2001 return;
2002 command.m_targetBlend7 = newTargetBlend7.toRhiTargetBlend();
2003 emit targetBlend7Changed();
2004}
2005
2006void QQuick3DShaderUtilsPipelineStateOverride::resetTargetBlend7()
2007{
2008 command.m_targetBlend7.reset();
2009 emit targetBlend7Changed();
2010}
2011
2012/*!
2013 \qmltype RenderPassTexture
2014 \inherits Object3D
2015 \inqmlmodule QtQuick3D
2016 \brief Defines a texture to be used as a render target in a \l {RenderPass}{pass}.
2017 \since 6.11
2018
2019 RenderPassTexture declares an off-screen texture that a \l RenderPass can
2020 render into. The texture is automatically created and managed by the
2021 rendering system. Its size tracks the \l View3D viewport by default.
2022
2023 Once declared, attach the texture to a pass via \l ColorAttachment (for
2024 color output) or \l DepthTextureAttachment (for depth output). The
2025 resulting texture can then be accessed from a subsequent pass or a
2026 \l Texture component using \l RenderOutputProvider.
2027
2028 \qml
2029 // Declare a float color buffer
2030 RenderPassTexture {
2031 id: hdrColorTexture
2032 format: RenderPassTexture.RGBA16F
2033 }
2034
2035 RenderPass {
2036 commands: [
2037 ColorAttachment {
2038 name: "color0"
2039 target: hdrColorTexture
2040 }
2041 ]
2042 }
2043 \endqml
2044
2045 \sa ColorAttachment, DepthTextureAttachment, RenderOutputProvider
2046*/
2047
2048/*!
2049 \qmlproperty enumeration RenderPassTexture::format
2050 Sets the format of the render target texture.
2051
2052 Available formats are:
2053
2054 \value RenderPassTexture.Unknown
2055 \value RenderPassTexture.RGBA8
2056 \value RenderPassTexture.RGBA16F
2057 \value RenderPassTexture.RGBA32F
2058 \value RenderPassTexture.R8
2059 \value RenderPassTexture.R16
2060 \value RenderPassTexture.R16F
2061 \value RenderPassTexture.R32F
2062 \value RenderPassTexture.Depth16
2063 \value RenderPassTexture.Depth24
2064 \value RenderPassTexture.Depth32
2065 \value RenderPassTexture.Depth24Stencil8
2066*/
2067
2068QQuick3DShaderUtilsRenderPassTexture::QQuick3DShaderUtilsRenderPassTexture(QQuick3DObject *parent)
2069 : QQuick3DObject(*(new QQuick3DObjectPrivate(QQuick3DObjectPrivate::Type::RenderPassTexture)), parent)
2070{
2071}
2072
2073QQuick3DShaderUtilsRenderPassTexture::~QQuick3DShaderUtilsRenderPassTexture()
2074{
2075
2076}
2077
2078QQuick3DShaderUtilsRenderPassTexture::TextureFormat QQuick3DShaderUtilsRenderPassTexture::format() const
2079{
2080 return m_format;
2081}
2082
2083void QQuick3DShaderUtilsRenderPassTexture::setFormat(TextureFormat newFormat)
2084{
2085 if (m_format == newFormat)
2086 return;
2087
2088 m_format = newFormat;
2089 update();
2090}
2091
2092QSSGAllocateTexturePtr QQuick3DShaderUtilsRenderPassTexture::command() const
2093{
2094 const auto *node = static_cast<QSSGRenderPassTexture *>(QQuick3DObjectPrivate::get(this)->spatialNode);
2095 return node ? node->command : nullptr;
2096}
2097
2098QSSGRenderGraphObject *QQuick3DShaderUtilsRenderPassTexture::updateSpatialNode(QSSGRenderGraphObject *node)
2099{
2100 auto *textureNode = static_cast<QSSGRenderPassTexture *>(node);
2101 if (!textureNode)
2102 textureNode = new QSSGRenderPassTexture;
2103
2104 // A pass rendering into the texture recreates it once the format no
2105 // longer matches.
2106 textureNode->command->setFormat(asRenderTextureFormat(m_format));
2107
2108 return textureNode;
2109}
2110
2111QSSGRenderTextureFormat QQuick3DShaderUtilsRenderPassTexture::asRenderTextureFormat(TextureFormat fmt)
2112{
2113 switch (fmt) {
2114 case TextureFormat::Unknown: return QSSGRenderTextureFormat::Unknown;
2115 case TextureFormat::RGBA8: return QSSGRenderTextureFormat::RGBA8;
2116 case TextureFormat::RGBA16F: return QSSGRenderTextureFormat::RGBA16F;
2117 case TextureFormat::RGBA32F: return QSSGRenderTextureFormat::RGBA32F;
2118 case TextureFormat::R8: return QSSGRenderTextureFormat::R8;
2119 case TextureFormat::R16: return QSSGRenderTextureFormat::R16;
2120 case TextureFormat::R16F: return QSSGRenderTextureFormat::R16F;
2121 case TextureFormat::R32F: return QSSGRenderTextureFormat::R32F;
2122 case TextureFormat::Depth16: return QSSGRenderTextureFormat::Depth16;
2123 case TextureFormat::Depth24: return QSSGRenderTextureFormat::Depth24;
2124 case TextureFormat::Depth32: return QSSGRenderTextureFormat::Depth32;
2125 case TextureFormat::Depth24Stencil8: return QSSGRenderTextureFormat::Depth24Stencil8;
2126 default:
2127 break;
2128 }
2129 return QSSGRenderTextureFormat::Unknown;
2130}
2131
2132/*!
2133 \qmltype ColorAttachment
2134 \inherits Command
2135 \inqmlmodule QtQuick3D
2136 \brief Defines a color attachment for a render pass.
2137 \since 6.11
2138
2139 The ColorAttachment type is used to specify a color attachment for a \l RenderPass.
2140 The \l name property is used to identify the attachment within the render pass.
2141 If the \l {RenderPass::materialMode}{RenderPass.AugmentMaterial} mode is used,
2142 the name will be exposed as an output with \c name in the fragment shader.
2143
2144 \sa RenderPassTexture
2145
2146 \qml
2147 RenderPass {
2148 // Define a render target texture
2149 RenderPassTexture {
2150 id: colorTexture
2151 format: RenderPassTexture.RGBA16F
2152 }
2153
2154 commands: [
2155 // Define a color attachment using the texture
2156 ColorAttachment {
2157 name: "color0"
2158 target: colorTexture
2159 }
2160 ]
2161 }
2162 \endqml
2163*/
2164
2165/*!
2166 \qmlproperty RenderPassTexture ColorAttachment::target
2167 The \l RenderPassTexture that will be used as the color attachment. The texture
2168 must have a color-compatible format (e.g. \c RGBA8, \c RGBA16F).
2169*/
2170
2171/*!
2172 \qmlproperty string ColorAttachment::name
2173 The name used to identify this color attachment within the render pass. When
2174 \l {RenderPass::materialMode}{materialMode} is set to \c AugmentMaterial, this name
2175 is exposed as a fragment shader output variable, allowing custom shader code to
2176 write to this attachment.
2177*/
2178
2179QQuick3DShaderUtilsRenderPassColorAttachment::~QQuick3DShaderUtilsRenderPassColorAttachment()
2180{
2181
2182}
2183
2184void QQuick3DShaderUtilsRenderPassColorAttachment::setTarget(QQuick3DShaderUtilsRenderPassTexture *target)
2185{
2186 if (m_target == target)
2187 return;
2188
2189 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DShaderUtilsRenderPassColorAttachment::setTarget, target, m_target);
2190
2191 m_target = target;
2192 emit changed();
2193}
2194
2195void QQuick3DShaderUtilsRenderPassColorAttachment::itemChange(ItemChange change, const ItemChangeData &value)
2196{
2197 if (change == QQuick3DObject::ItemSceneChange)
2198 updateSceneManager(value.sceneManager);
2199}
2200
2201void QQuick3DShaderUtilsRenderPassColorAttachment::updateSceneManager(QQuick3DSceneManager *sceneManager)
2202{
2203 if (sceneManager)
2204 QQuick3DObjectPrivate::refSceneManager(m_target, *sceneManager);
2205 else
2206 QQuick3DObjectPrivate::derefSceneManager(m_target);
2207}
2208
2209QByteArray QQuick3DShaderUtilsRenderPassColorAttachment::name() const
2210{
2211 return m_name;
2212}
2213
2214void QQuick3DShaderUtilsRenderPassColorAttachment::setName(const QByteArray &newName)
2215{
2216 m_name = newName;
2217}
2218
2219QSSGCommand *QQuick3DShaderUtilsRenderPassColorAttachment::cloneCommand()
2220{
2221 // Null until the target has been synchronized into the scene.
2222 // FIXME: There's no reason we should clone the command here, it's not accessed outside
2223 // the render thread anymore.
2224 if (auto textureCmd = m_target ? m_target->command() : nullptr) {
2225 QSSGColorAttachment *cmd = new QSSGColorAttachment(m_name);
2226 cmd->m_textureCmd = std::move(textureCmd);
2227 return cmd;
2228 }
2229
2230 return nullptr;
2231}
2232
2233QQuick3DPropertyChangedTracker::~QQuick3DPropertyChangedTracker()
2234{
2235 // Disconnect before releasing scene references, since that can change the
2236 // referenced objects while the owner's derived class is already destroyed.
2237 for (const Tracked &tracked : std::as_const(m_trackedProperties)) {
2238 QObject::disconnect(tracked.destroyedConnection);
2239 delete tracked.watcher;
2240 }
2241 for (const TextureWatch &watch : std::as_const(m_textureWatchers)) {
2242 for (const auto &connection : watch.textureInputConnections)
2243 QObject::disconnect(connection);
2244 for (const auto &connection : watch.textureConnections)
2245 QObject::disconnect(connection);
2246 QObject::disconnect(watch.textureProviderConnection);
2247 }
2248 updateTrackedSceneManager(nullptr);
2249}
2250
2251void QQuick3DPropertyChangedTracker::updateTrackedSceneManager(QQuick3DSceneManager *sceneManager)
2252{
2253 for (Tracked &tracked : m_trackedProperties) {
2254 if (tracked.sceneManager == sceneManager)
2255 continue;
2256
2257 if (tracked.object && tracked.sceneManager)
2258 QQuick3DObjectPrivate::get(tracked.object)->derefSceneManager();
2259 tracked.sceneManager = nullptr;
2260
2261 if (tracked.object && sceneManager) {
2262 QQuick3DObjectPrivate::get(tracked.object)->refSceneManager(*sceneManager);
2263 tracked.sceneManager = sceneManager;
2264 }
2265 addDirtyProperty(tracked.pid);
2266 }
2267}
2268
2269std::optional<QQuick3DPropertyChangedTracker::UniformProperty> QQuick3DPropertyChangedTracker::createOrUpdateTrackedProperty(const QMetaProperty property,
2270 bool addWatchers)
2271{
2272 Q_ASSERT(property.isValid());
2273
2274 std::optional<QQuick3DPropertyChangedTracker::UniformProperty> result;
2275 const int propertyIndex = property.propertyIndex();
2276
2277 // A texture property is always exposed as a sampler, also when there is no texture (yet).
2278 // The shader needs the sampler declared regardless, and the render side binds a dummy
2279 // texture for a null image. The watchers on the texture are (re)bound on every update
2280 // so that a texture assigned after the first extraction is tracked as well.
2281 const auto addTextureToUniforms = [&](const char *name, QQuick3DTexture *texture) -> UniformProperty {
2282 QSSGRenderImage *ri = nullptr;
2283 if (texture)
2284 ri = static_cast<QSSGRenderImage *>(QQuick3DObjectPrivate::get(texture)->spatialNode);
2285 watchTexture(property, texture);
2286 return UniformProperty(name, QSSGShaderUtils::samplerTypeName(texture), QVariant::fromValue(ri),
2287 QSSGRenderShaderValue::Texture, propertyIndex);
2288 };
2289
2290 const auto addTextureInputToUniforms =
2291 [&](const char *name, QQuick3DShaderUtilsTextureInput *textureInput) -> UniformProperty {
2292 watchTextureInput(property, textureInput);
2293 return addTextureToUniforms(name, textureInput ? textureInput->texture() : nullptr);
2294 };
2295
2296 const char *name = property.name();
2297 QMetaType propType = property.metaType();
2298 QVariant propValue = property.read(m_owner);
2299 if (propType == QMetaType(QMetaType::QVariant))
2300 propType = propValue.metaType();
2301
2302 const auto type = QSSGShaderUtils::uniformType(propType);
2303 if (type != QSSGRenderShaderValue::Unknown) {
2304 result = UniformProperty(name, QSSGShaderUtils::uniformTypeName(propType), propValue, type, propertyIndex);
2305 if (addWatchers)
2306 addPropertyWatcher(property, DirtyPropertyHint::Value);
2307 } else if (QSSGShaderUtils::isTextureType(propType)) {
2308 // Also covers properties declared with a subclass, such as CubeMapTexture.
2309 QQuick3DTexture *texture = QSSGShaderUtils::textureFromValue(propValue);
2310 result = addTextureToUniforms(name, texture);
2311 // A null texture has no sampler type of its own, but the declared type may have one.
2312 if (!texture && propType.metaObject()->inherits(&QQuick3DCubeMapTexture::staticMetaObject))
2313 result->typeName = QSSGBaseTypeHelpers::toString(QSSGRenderSamplerType::SamplerCube);
2314 if (addWatchers)
2315 addPropertyWatcher(property, DirtyPropertyHint::Reference, texture);
2316 } else if (propType.id() == qMetaTypeId<QQuick3DShaderUtilsTextureInput *>()) {
2317 // For compatibility, also check for texture input types
2318 auto *textureInput = propValue.value<QQuick3DShaderUtilsTextureInput *>();
2319 result = addTextureInputToUniforms(name, textureInput);
2320 if (addWatchers)
2321 addPropertyWatcher(property, DirtyPropertyHint::Reference, textureInput);
2322 } else if (propType.id() == qMetaTypeId<QQuick3DShaderStorageBuffer *>()) {
2323 // Watched by the owner's QQuick3DShaderResourceTracker, which also
2324 // notices when a null property gets assigned.
2325 if (propValue.value<QQuick3DShaderStorageBuffer *>())
2326 result = UniformProperty(name, {}, propValue, QSSGRenderShaderValue::StorageBuffer, propertyIndex);
2327 } else if (propType.id() == qMetaTypeId<QQuick3DShaderImage *>()) {
2328 if (propValue.value<QQuick3DShaderImage *>())
2329 result = UniformProperty(name, {}, propValue, QSSGRenderShaderValue::Image, propertyIndex);
2330 } else if (propType == QMetaType(QMetaType::QObjectStar)) {
2331 QObject *object = propValue.value<QObject *>();
2332 if (auto *texture = qobject_cast<QQuick3DTexture *>(object)) {
2333 result = addTextureToUniforms(name, texture);
2334 if (addWatchers)
2335 addPropertyWatcher(property, DirtyPropertyHint::Reference, texture);
2336 } else if (auto *textureInput = qobject_cast<QQuick3DShaderUtilsTextureInput *>(object)) {
2337 result = addTextureInputToUniforms(name, textureInput);
2338 if (addWatchers)
2339 addPropertyWatcher(property, DirtyPropertyHint::Reference, textureInput);
2340 } else if (auto *buffer = qobject_cast<QQuick3DShaderStorageBuffer *>(object)) {
2341 // Watched by the owner's QQuick3DShaderResourceTracker, like the typed case.
2342 result = UniformProperty(name, {}, QVariant::fromValue(buffer), QSSGRenderShaderValue::StorageBuffer,
2343 propertyIndex);
2344 } else if (auto *image = qobject_cast<QQuick3DShaderImage *>(object)) {
2345 result = UniformProperty(name, {}, QVariant::fromValue(image), QSSGRenderShaderValue::Image,
2346 propertyIndex);
2347 }
2348 }
2349
2350 return result;
2351}
2352
2353QList<QQuick3DPropertyChangedTracker::UniformProperty> QQuick3DPropertyChangedTracker::extractProperties()
2354{
2355 for (int propertyIndex : std::as_const(m_dirtyProperties)) {
2356 auto it = std::lower_bound(m_propertyList.begin(),
2357 m_propertyList.end(),
2358 propertyIndex,
2359 [](const UniformProperty &p, int index) { return p.pid < index; });
2360
2361 const bool found = (it != m_propertyList.end() && it->pid == propertyIndex);
2362 const QMetaProperty property = m_owner->metaObject()->property(propertyIndex);
2363 std::optional<UniformProperty> trackedProperty;
2364
2365 if (Q_LIKELY(property.isValid()))
2366 trackedProperty = createOrUpdateTrackedProperty(property, false);
2367
2368 if (trackedProperty.has_value()) {
2369 if (found)
2370 *it = *trackedProperty;
2371 else
2372 m_propertyList.insert(it, *trackedProperty); // keeps the list sorted by pid
2373 } else if (found) {
2374 m_propertyList.erase(it);
2375 }
2376 }
2377 m_dirtyProperties.clear();
2378
2379 if (m_extracted)
2380 return m_propertyList;
2381
2382 auto metaObject = m_owner->metaObject();
2383
2384 // Properties -> uniforms
2385 const int propCount = metaObject->propertyCount();
2386 int propOffset = metaObject->propertyOffset();
2387 m_propertyList.reserve(propCount);
2388
2389 // Classes can have multilayered inheritance structure, so find the actual propOffset by
2390 // walking up the inheritance chain.
2391 const QMetaObject *superClass = metaObject->superClass();
2392 while (superClass && qstrcmp(superClass->className(), m_superClassName) != 0) {
2393 propOffset = superClass->propertyOffset();
2394 superClass = superClass->superClass();
2395 }
2396
2397 for (int i = propOffset; i != propCount; ++i) {
2398 const QMetaProperty property = metaObject->property(i);
2399 if (Q_UNLIKELY(!property.isValid()))
2400 continue;
2401 if (auto uniformProperty = createOrUpdateTrackedProperty(property, true); uniformProperty.has_value()) {
2402 m_propertyList.push_back(*uniformProperty);
2403 }
2404 }
2405
2406 m_dirtyProperties.reserve(m_propertyList.size());
2407
2408 m_extracted = true;
2409 return m_propertyList;
2410}
2411
2412void QQuick3DPropertyChangedTracker::addPropertyWatcher(QMetaProperty property, DirtyPropertyHint hint, QQuick3DObject *object)
2413{
2414 if (property.isValid() && property.hasNotifySignal()) {
2415 // Check if we're already watching this property.
2416 const auto pid = property.propertyIndex();
2417 Q_ASSERT(pid != -1);
2418 auto it = m_trackedProperties.find(pid);
2419 const bool found = (it != m_trackedProperties.end());
2420 if (!found) {
2421 QQuick3DPropertyWatcher *watcher = new QQuick3DPropertyWatcher(this, property);
2422 it = m_trackedProperties.insert(pid, Tracked { watcher, nullptr, pid, {}, {} });
2423 }
2424
2425 if (hint == DirtyPropertyHint::Reference) {
2426 const auto &sm = QQuick3DObjectPrivate::get(m_owner)->sceneManager;
2427 if (it->object != object) {
2428 QObject::disconnect(it->destroyedConnection);
2429 if (it->object && it->sceneManager)
2430 QQuick3DObjectPrivate::get(it->object)->derefSceneManager();
2431 it->object = object;
2432 it->sceneManager = nullptr;
2433 if (object && sm) {
2434 QQuick3DObjectPrivate::get(object)->refSceneManager(*sm);
2435 it->sceneManager = sm;
2436 }
2437 if (object) {
2438 it->destroyedConnection = QObject::connect(object, &QObject::destroyed, m_owner, [this, property] {
2439 addPropertyWatcher(property, DirtyPropertyHint::Reference, nullptr);
2440 });
2441 }
2442 }
2443 }
2444
2445 markPropertyDirty(property, hint);
2446 }
2447}
2448
2449void QQuick3DPropertyChangedTracker::addDirtyProperty(int pid)
2450{
2451 // A plain vector rather than a set, so the storage is reused between frames
2452 if (std::find(m_dirtyProperties.cbegin(), m_dirtyProperties.cend(), pid) == m_dirtyProperties.cend())
2453 m_dirtyProperties.push_back(pid);
2454}
2455
2456void QQuick3DPropertyChangedTracker::markPropertyDirty(QMetaProperty property, DirtyPropertyHint hint)
2457{
2458 addDirtyProperty(property.propertyIndex());
2459 markTrackedPropertyDirty(property, hint);
2460}
2461
2462void QQuick3DPropertyChangedTracker::watchTextureInput(QMetaProperty property,
2463 QQuick3DShaderUtilsTextureInput *textureInput)
2464{
2465 TextureWatch &watch = m_textureWatchers[property.propertyIndex()];
2466 if (watch.textureInput == textureInput)
2467 return;
2468
2469 for (auto &connection : watch.textureInputConnections)
2470 QObject::disconnect(connection);
2471 watch.textureInput = textureInput;
2472 if (!textureInput)
2473 return;
2474
2475 // Changes to the TextureInput affect which texture is sampled, so report them as
2476 // reference changes on the property that holds the TextureInput.
2477 const auto onChanged = [this, property] { markPropertyDirty(property, DirtyPropertyHint::Reference); };
2478 watch.textureInputConnections[0] = QObject::connect(textureInput, &QQuick3DShaderUtilsTextureInput::enabledChanged,
2479 m_owner, onChanged);
2480 watch.textureInputConnections[1] = QObject::connect(textureInput, &QQuick3DShaderUtilsTextureInput::textureChanged,
2481 m_owner, onChanged);
2482}
2483
2484void QQuick3DPropertyChangedTracker::watchTexture(QMetaProperty property, QQuick3DTexture *texture)
2485{
2486 TextureWatch &watch = m_textureWatchers[property.propertyIndex()];
2487 if (watch.texture == texture)
2488 return;
2489
2490 for (auto &connection : watch.textureConnections)
2491 QObject::disconnect(connection);
2492 watch.texture = texture;
2493 watchTextureProvider(property, texture);
2494 if (!texture)
2495 return;
2496
2497 watch.textureConnections[0] = QObject::connect(texture, &QQuick3DTexture::textureProviderChanged, m_owner,
2498 [this, property, texture] {
2499 watchTextureProvider(property, texture);
2500 markPropertyDirty(property, DirtyPropertyHint::Reference);
2501 });
2502 // The render image is looked up when the property is extracted, so re-extract when the
2503 // texture backend node is (re)created.
2504 watch.textureConnections[1] = QObject::connect(texture, &QQuick3DTexture::textureInternalChange, m_owner,
2505 [this, property](QQuick3DTextureInternalChange change) {
2506 if (change.type == QQuick3DTextureInternalChange::Type::BackendNode)
2507 markPropertyDirty(property, DirtyPropertyHint::Reference);
2508 });
2509}
2510
2511void QQuick3DPropertyChangedTracker::watchTextureProvider(QMetaProperty property, QQuick3DTexture *texture)
2512{
2513 TextureWatch &watch = m_textureWatchers[property.propertyIndex()];
2514 QObject::disconnect(watch.textureProviderConnection);
2515 watch.textureProviderConnection = {};
2516
2517 QQuick3DTextureProviderExtension *textureProvider = nullptr;
2518 if (texture)
2519 textureProvider = qobject_cast<QQuick3DTextureProviderExtension *>(texture->textureProvider());
2520 if (!textureProvider)
2521 return;
2522
2523 // The sampler type follows the provider's sampler hint, so a new surface means re-extracting.
2524 watch.textureProviderConnection = QObject::connect(textureProvider,
2525 &QQuick3DTextureProviderExtension::surfaceChanged,
2526 m_owner, [this, property] {
2527 markPropertyDirty(property, DirtyPropertyHint::Reference);
2528 });
2529}
2530
2531void QQuick3DPropertyChangedTracker::markTrackedPropertyDirty(QMetaProperty property, DirtyPropertyHint hint)
2532{
2533 Q_UNUSED(property);
2534 Q_UNUSED(hint);
2535 QSSG_CHECK_X(false, "QQuick3DPropertyChangedTracker::onPropertyDirty implementation missing");
2536}
2537
2538QQuick3DPropertyWatcher::QQuick3DPropertyWatcher(QQuick3DPropertyChangedTracker *tracker, QMetaProperty property)
2539 : m_tracker(tracker)
2540 , m_property(property)
2541{
2542 Q_ASSERT(tracker != nullptr);
2543 Q_ASSERT(property.isValid() && property.hasNotifySignal());
2544
2545 // Ensure that the watcher is on the watched object's thread if it's not already there.
2546 // If not, the watcher will be created on the render thread and the notify connections
2547 // will be queued to the render thread, which is not what we want
2548 // (as can end-up concurrently mutating the dirty lists).
2549 if (thread() != tracker->m_owner->thread())
2550 moveToThread(tracker->m_owner->thread());
2551
2552 const bool isPointerType = (property.metaType().flags().testFlag(QMetaType::IsPointer));
2553
2554 if (!isPointerType) {
2555 // Value change notification
2556 const auto idx = staticMetaObject.indexOfSlot("onValuePropertyChanged()");
2557 if (QSSG_GUARD_X(idx != -1, "Method not found!")) {
2558 auto onPropertyChangedMethod = staticMetaObject.method(idx);
2559 connect(m_tracker->m_owner, property.notifySignal(), this, onPropertyChangedMethod);
2560 }
2561 } else {
2562 // Pointer value change notification
2563 const auto idx = staticMetaObject.indexOfSlot("onPointerPropertyChanged()");
2564 if (QSSG_GUARD_X(idx != -1, "Method not found!")) {
2565 auto onPointerPropertyChangedMethod = staticMetaObject.method(idx);
2566 connect(m_tracker->m_owner, property.notifySignal(), this, onPointerPropertyChangedMethod);
2567 }
2568 }
2569}
2570
2571void QQuick3DPropertyWatcher::onValuePropertyChanged()
2572{
2573 m_tracker->addDirtyProperty(m_property.propertyIndex());
2574 m_tracker->markTrackedPropertyDirty(m_property, QQuick3DPropertyChangedTracker::DirtyPropertyHint::Value);
2575}
2576
2578{
2579 // The referenced object changed, so the scene manager reference has to move with it
2580 // (otherwise e.g. a texture assigned later is never synchronized). This also marks the
2581 // property dirty.
2582 auto *object = m_property.read(m_tracker->m_owner).value<QQuick3DObject *>();
2583 m_tracker->addPropertyWatcher(m_property, QQuick3DPropertyChangedTracker::DirtyPropertyHint::Reference, object);
2584}
2585
2586/*!
2587 \qmltype AddDefine
2588 \inherits Command
2589 \inqmlmodule QtQuick3D
2590 \brief Adds a preprocessor define to the shader compilation for a \l {RenderPass}{pass}.
2591 \since 6.11
2592
2593 The AddDefine type is used to inject a \c {#define} into the shader
2594 compilation for a \l RenderPass. This lets you branch shader behavior
2595 at compile time depending on which pass is being executed.
2596
2597 In the shader code, the define can be used with the standard preprocessor
2598 \c {#ifdef} / \c {#if} directives:
2599 \badcode
2600 #ifdef CUSTOM_PASS_MODE
2601 // code compiled only when this define is present
2602 #endif
2603 \endcode
2604
2605 \qml
2606 RenderPass {
2607 commands: [
2608 ColorAttachment { name: "color0"; target: colorTexture },
2609 AddDefine { name: "CUSTOM_PASS_MODE" },
2610 AddDefine { name: "OUTPUT_VERSION"; value: 2 }
2611 ]
2612 }
2613 \endqml
2614*/
2615
2616/*!
2617 \qmlproperty string AddDefine::name
2618 The name of the preprocessor macro to define. This becomes the identifier
2619 used in \c {#ifdef} or \c {#if} checks in the shader code.
2620*/
2621
2622/*!
2623 \qmlproperty int AddDefine::value
2624 The integer value assigned to the preprocessor macro. Defaults to \c 1.
2625 When non-zero, \c {#if NAME} evaluates to \c true in the shader.
2626*/
2627
2628QQuick3DShaderUtilsRenderPassAddDefine::QQuick3DShaderUtilsRenderPassAddDefine()
2629{
2630
2631}
2632
2633QQuick3DShaderUtilsRenderPassAddDefine::~QQuick3DShaderUtilsRenderPassAddDefine() = default;
2634
2635QByteArray QQuick3DShaderUtilsRenderPassAddDefine::name() const
2636{
2637 return command.m_name;
2638}
2639
2640void QQuick3DShaderUtilsRenderPassAddDefine::setName(const QByteArray &newName)
2641{
2642 if (command.m_name != newName) {
2643 command.m_name = newName;
2644 emit nameChanged();
2645 emit changed();
2646 }
2647}
2648
2649int QQuick3DShaderUtilsRenderPassAddDefine::value() const
2650{
2651 return command.m_value;
2652}
2653
2654void QQuick3DShaderUtilsRenderPassAddDefine::setValue(int newValue)
2655{
2656 if (command.m_value != newValue) {
2657 command.m_value = newValue;
2658 emit valueChanged();
2659 emit changed();
2660 }
2661}
2662
2663QSSGCommand *QQuick3DShaderUtilsRenderPassAddDefine::cloneCommand() {
2664 QSSGAddShaderDefine *cmd = new QSSGAddShaderDefine(command);
2665 return cmd;
2666}
2667
2668/*!
2669 \qmltype SubRenderPass
2670 \inherits Command
2671 \inqmlmodule QtQuick3D
2672 \brief Renders a sub-section of work within the same render target as the parent RenderPass.
2673 \since 6.11
2674
2675 SubRenderPass is a \l Command that subdivides a \l RenderPass into
2676 smaller, independently configured pieces while sharing the same render
2677 target. Only the parent \l RenderPass controls which textures are
2678 rendered into (via \l ColorAttachment and \l DepthTextureAttachment)
2679 and when the pass begins (and therefore when the render target is
2680 cleared). A SubRenderPass cannot set its own render target or clear
2681 settings — those are always inherited from the parent pass.
2682
2683 What a SubRenderPass \e can control is \e what gets rendered and
2684 \e how: it has its own \l{RenderPass::commands}{commands}, so it can
2685 carry a \l RenderablesFilter to select a subset of objects, a
2686 \l PipelineStateOverride to change depth/blend state, a different
2687 \l{RenderPass::materialMode}{materialMode}, and so on.
2688
2689 A typical use is a forward-rendering pipeline where a single color
2690 pass uses separate SubRenderPasses for the background, opaque
2691 objects, and transparent objects. All three sub-passes write into the
2692 same color and depth textures, but each has different pipeline state:
2693
2694 \qml
2695 RenderPass {
2696 id: mainColorPass
2697 commands: [
2698 // Render targets are set at the parent RenderPass level only
2699 ColorAttachment { name: "color0"; target: colorTexture },
2700 DepthTextureAttachment { target: depthTexture },
2701
2702 // Sub-pass 1: render the skybox background
2703 SubRenderPass { renderPass: skyboxSubPass },
2704
2705 // Sub-pass 2: opaque objects with depth testing and writing
2706 SubRenderPass { renderPass: opaqueSubPass },
2707
2708 // Sub-pass 3: transparent objects with blending, no depth write
2709 SubRenderPass { renderPass: transparentSubPass }
2710 ]
2711 }
2712
2713 // Sub-passes share mainColorPass's render target
2714 RenderPass {
2715 id: skyboxSubPass
2716 passMode: RenderPass.SkyboxPass
2717 }
2718
2719 RenderPass {
2720 id: opaqueSubPass
2721 commands: [
2722 RenderablesFilter { renderableTypes: RenderablesFilter.Opaque }
2723 ]
2724 }
2725
2726 RenderPass {
2727 id: transparentSubPass
2728 commands: [
2729 RenderablesFilter { renderableTypes: RenderablesFilter.Transparent },
2730 PipelineStateOverride {
2731 blendEnabled: true
2732 depthWriteEnabled: false
2733 }
2734 ]
2735 }
2736 \endqml
2737
2738 \sa RenderPass, RenderablesFilter, PipelineStateOverride
2739*/
2740
2741/*!
2742 \qmlproperty RenderPass SubRenderPass::renderPass
2743 The RenderPass that will be executed as a sub-pass when this command is processed.
2744*/
2745
2746QQuick3DShaderUtilsSubRenderPass::~QQuick3DShaderUtilsSubRenderPass()
2747{
2748 if (m_renderPass)
2749 QQuick3DRenderPassPrivateHelper::subPassDeref(m_renderPass);
2750}
2751
2752QSSGCommand *QQuick3DShaderUtilsSubRenderPass::cloneCommand()
2753{
2754 QSSGSubRenderPass *cmd = nullptr;
2755
2756 if (!m_renderPass) {
2757 if (!m_hasWarnedAboutInvalidId) {
2758 qCWarning(lcSubRenderPass, "SubRenderPass: No render pass specified. Set the 'renderPass' property.");
2759 m_hasWarnedAboutInvalidId = true;
2760 }
2761 return nullptr;
2762 }
2763
2764 QSSGResourceId userPassId = QQuick3DExtensionHelpers::getResourceId(*m_renderPass);
2765 // Ensure we have a valid resource id before continuing.
2766 if (userPassId != QSSGResourceId::Invalid) {
2767 cmd = new QSSGSubRenderPass();
2768 cmd->setSubPass(userPassId);
2769 // Reset warning flag on success
2770 m_hasWarnedAboutInvalidId = false;
2771 } else {
2772 // Resource ID is not ready yet - this is expected during initialization
2773 qCDebug(lcSubRenderPass, "SubRenderPass: Render pass resource ID not yet available, will retry.");
2774 update();
2775 }
2776
2777 return cmd;
2778}
2779
2780QSSGRenderGraphObject *QQuick3DShaderUtilsSubRenderPass::updateSpatialNode(QSSGRenderGraphObject *node)
2781{
2782 return node;
2783}
2784
2785void QQuick3DShaderUtilsSubRenderPass::itemChange(ItemChange change, const ItemChangeData &value)
2786{
2787 if (change == QQuick3DObject::ItemSceneChange)
2788 updateSceneManager(value.sceneManager);
2789}
2790
2791void QQuick3DShaderUtilsSubRenderPass::updateSceneManager(QQuick3DSceneManager *sceneManager)
2792{
2793 if (sceneManager)
2794 QQuick3DObjectPrivate::refSceneManager(m_renderPass, *sceneManager);
2795 else
2796 QQuick3DObjectPrivate::derefSceneManager(m_renderPass);
2797}
2798
2799QQuick3DRenderPass *QQuick3DShaderUtilsSubRenderPass::renderPass() const
2800{
2801 return m_renderPass;
2802}
2803
2804void QQuick3DShaderUtilsSubRenderPass::setRenderPass(QQuick3DRenderPass *newRenderPass)
2805{
2806 if (m_renderPass == newRenderPass)
2807 return;
2808
2809 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DShaderUtilsSubRenderPass::setRenderPass, newRenderPass, m_renderPass.data());
2810
2811 if (newRenderPass)
2812 QQuick3DRenderPassPrivateHelper::subPassRef(newRenderPass);
2813
2814 // NOTE: When the watcher calls us because the referenced pass is being
2815 // destroyed, the QPointer is already null, so a dying pass is never deref'd.
2816 if (m_renderPass)
2817 QQuick3DRenderPassPrivateHelper::subPassDeref(m_renderPass);
2818
2819 m_renderPass = newRenderPass;
2820 m_hasWarnedAboutInvalidId = false; // Reset warning flag when property changes
2821 emit renderPassChanged();
2822 emit changed();
2823}
2824
2825/*!
2826 \qmltype DepthTextureAttachment
2827 \inherits Command
2828 \inqmlmodule QtQuick3D
2829 \brief Defines a depth texture attachment for a \l {RenderPass}{pass}.
2830 \since 6.11
2831
2832 DepthTextureAttachment attaches a \l RenderPassTexture with a depth
2833 format as the depth buffer for a \l RenderPass. Unlike
2834 \l DepthStencilAttachment (which uses an opaque render buffer), the
2835 resulting depth data is stored in a texture that can be read by
2836 subsequent passes via \l RenderOutputProvider.
2837
2838 \qml
2839 RenderPassTexture {
2840 id: depthTexture
2841 format: RenderPassTexture.Depth24
2842 }
2843
2844 RenderPass {
2845 id: myRenderPass
2846 commands: [
2847 ColorAttachment { name: "color0"; target: colorTexture },
2848 DepthTextureAttachment { target: depthTexture }
2849 ]
2850 }
2851
2852 // Expose the depth texture to a material via RenderOutputProvider
2853 Texture {
2854 textureProvider: RenderOutputProvider {
2855 textureSource: RenderOutputProvider.UserPassDepthTexture
2856 renderPass: myRenderPass
2857 }
2858 minFilter: Texture.Nearest
2859 magFilter: Texture.Nearest
2860 }
2861 \endqml
2862
2863 \sa RenderPassTexture, DepthStencilAttachment, RenderOutputProvider
2864*/
2865
2866/*!
2867 \qmlproperty RenderPassTexture DepthTextureAttachment::target
2868 The \l RenderPassTexture that will be used as the depth attachment. The texture
2869 must have a depth-compatible format (e.g. \c Depth16, \c Depth24, \c Depth32,
2870 or \c Depth24Stencil8).
2871*/
2872
2873QQuick3DShaderUtilsRenderPassDepthTextureAttachment::~QQuick3DShaderUtilsRenderPassDepthTextureAttachment()
2874{
2875
2876}
2877
2878void QQuick3DShaderUtilsRenderPassDepthTextureAttachment::setTarget(QQuick3DShaderUtilsRenderPassTexture *target)
2879{
2880 if (m_target == target)
2881 return;
2882
2883 QQuick3DObjectPrivate::attachWatcher(this, &QQuick3DShaderUtilsRenderPassDepthTextureAttachment::setTarget, target, m_target);
2884
2885 m_target = target;
2886 emit changed();
2887}
2888
2889void QQuick3DShaderUtilsRenderPassDepthTextureAttachment::itemChange(ItemChange change, const ItemChangeData &value)
2890{
2891 if (change == QQuick3DObject::ItemSceneChange)
2892 updateSceneManager(value.sceneManager);
2893}
2894
2895void QQuick3DShaderUtilsRenderPassDepthTextureAttachment::updateSceneManager(QQuick3DSceneManager *sceneManager)
2896{
2897 if (sceneManager)
2898 QQuick3DObjectPrivate::refSceneManager(m_target, *sceneManager);
2899 else
2900 QQuick3DObjectPrivate::derefSceneManager(m_target);
2901}
2902
2903QSSGCommand *QQuick3DShaderUtilsRenderPassDepthTextureAttachment::cloneCommand()
2904{
2905 // Null until the target has been synchronized into the scene.
2906 if (auto textureCmd = m_target ? m_target->command() : nullptr) {
2907 QSSGDepthTextureAttachment *cmd = new QSSGDepthTextureAttachment(QByteArrayLiteral("__depth__"));
2908 cmd->m_textureCmd = std::move(textureCmd);
2909 return cmd;
2910 }
2911
2912 return nullptr;
2913}
2914
2915QQuick3DShaderUtilsRenderPassDepthStencilAttachment::~QQuick3DShaderUtilsRenderPassDepthStencilAttachment()
2916{
2917
2918}
2919
2920QSSGCommand *QQuick3DShaderUtilsRenderPassDepthStencilAttachment::cloneCommand()
2921{
2922 QSSGDepthStencilAttachment *cmd = new QSSGDepthStencilAttachment;
2923 return cmd;
2924}
2925
2926
2927/*!
2928 \qmltype Dispatch
2929 \inherits Command
2930 \inqmlmodule QtQuick3D
2931 \brief Dispatches a compute shader.
2932 \since 6.13
2933
2934 A Dispatch command specifies how many work groups a \l ComputePass
2935 dispatches its compute shader with, along the X, Y, and Z dimensions.
2936 A ComputePass without a Dispatch command in its
2937 \l{ComputePass::commands}{commands} list does not execute its shader.
2938
2939 The total number of shader invocations is the group count multiplied by
2940 the shader's local work group size (declared with
2941 \c{layout(local_size_x = ..., local_size_y = ..., local_size_z = ...) in;}
2942 in the shader
2943 itself). For example, to run one invocation per texel of a
2944 \l ShaderImage when the shader declares a local size of 8x8x1:
2945
2946 \qml
2947 Dispatch {
2948 groupCountX: (myImage.width + 7) / 8
2949 groupCountY: (myImage.height + 7) / 8
2950 }
2951 \endqml
2952
2953 The group count dimensions are clamped to the maximum supported amount:
2954 \c QRhi::MaxThreadGroupsPerDimension, with a warning.
2955
2956 Setting any of the group counts to \c 0 disables the ComputePass: its
2957 shader is not executed until all group counts are non-zero again. This
2958 is useful for toggling a pass on and off without editing its
2959 \l{ComputePass::commands}{commands} list, for example:
2960
2961 \qml
2962 Dispatch {
2963 groupCountX: computeEnabled ? (myImage.width + 7) / 8 : 0
2964 groupCountY: (myImage.height + 7) / 8
2965 }
2966 \endqml
2967
2968 \sa ComputePass
2969*/
2970
2971/*!
2972 \qmlproperty int Dispatch::groupCountX
2973 This property holds the number of work groups to dispatch along the X
2974 dimension. The default value is \c 1. A value of \c 0 disables the
2975 \l ComputePass. Negative values are ignored.
2976*/
2977void QQuick3DShaderUtilsCommandDispatch::setGroupCountX(int groupCountX)
2978{
2979 if (m_groupCount.x == groupCountX || groupCountX < 0)
2980 return;
2981 m_groupCount.x = groupCountX;
2982 emit groupCountXChanged();
2983 emit changed();
2984}
2985
2986/*!
2987 \qmlproperty int Dispatch::groupCountY
2988 This property holds the number of work groups to dispatch along the Y
2989 dimension. The default value is \c 1. A value of \c 0 disables the
2990 \l ComputePass. Negative values are ignored.
2991*/
2992void QQuick3DShaderUtilsCommandDispatch::setGroupCountY(int groupCountY)
2993{
2994 if (m_groupCount.y == groupCountY || groupCountY < 0)
2995 return;
2996 m_groupCount.y = groupCountY;
2997 emit groupCountYChanged();
2998 emit changed();
2999}
3000
3001/*!
3002 \qmlproperty int Dispatch::groupCountZ
3003 This property holds the number of work groups to dispatch along the Z
3004 dimension. The default value is \c 1. A value of \c 0 disables the
3005 \l ComputePass. Negative values are ignored.
3006*/
3007void QQuick3DShaderUtilsCommandDispatch::setGroupCountZ(int groupCountZ)
3008{
3009 if (m_groupCount.z == groupCountZ || groupCountZ < 0)
3010 return;
3011 m_groupCount.z = groupCountZ;
3012 emit groupCountZChanged();
3013 emit changed();
3014}
3015
3016QSSGCommand *QQuick3DShaderUtilsCommandDispatch::cloneCommand()
3017{
3018 return new QSSGDispatch(m_groupCount);
3019}
3020
3021QT_END_NAMESPACE
\qmltype Shader \inherits QtObject \inqmlmodule QtQuick3D
bool handleBufferProperty(QQuick3DShaderStorageBuffer *buffer, const QByteArray &name, int i, QByteArrayList &metadata, QList< QSSGBaseTypeProperty > &properties)
void updateImageProperty(QQuick3DShaderImage *image, const QSSGBaseTypeProperty &property)
ResolveFunction resolveShaderOverride
QByteArray toShaderImageType(QQuick3DShaderImage::ImageShape shape, QQuick3DShaderImage::ImageFormat imageFormat)
QByteArray toShaderFormat(QQuick3DShaderImage::ImageFormat imageFormat)
QSSGRenderShaderValue::Type uniformType(QMetaType type)
QByteArray uniformTypeName(QMetaType type)
bool(*)(const QUrl &url, const QQmlContext *context, QByteArray &shaderData, QByteArray &shaderPathKey) ResolveFunction
QByteArray uniformTypeName(QSSGRenderShaderValue::Type type)
static constexpr QMetaType::Type qssg_metatype_list[]
void updateBufferProperty(QQuick3DShaderStorageBuffer *buffer, const QSSGBaseTypeProperty &property)
bool handleImageProperty(QQuick3DShaderImage *image, const QByteArray &name, int i, QByteArrayList &metadata, QList< QSSGBaseTypeProperty > &properties)
QByteArray resolveShader(const QUrl &fileUrl, const QQmlContext *context, QByteArray &shaderPathKey)
bool isTextureType(QMetaType type)
bool resolveResourceProperties(const QObject *owner, const QList< QSSGBaseTypeProperty > &properties, QByteArrayList &metadata)
MetaTypeList supportedMetatypes()
QQuick3DTexture * textureFromValue(const QVariant &value)
QByteArray samplerTypeName(const QQuick3DTexture *texture)
void updateResourceProperties(const QObject *owner, const QList< QSSGBaseTypeProperty > &properties)
void setResolveFunction(ResolveFunction fn)
Combined button and popup list for selecting options.