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
qquick3drenderoutputprovider.cpp
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
5
6#include <ssg/qssgrenderextensions.h>
7#include <ssg/qssgrenderhelpers.h>
8#include <ssg/qssgrendercontextcore.h>
9#include <ssg/qssgrhicontext.h>
10#include <ssg/qquick3dextensionhelpers.h>
11
13
14/*!
15 \qmltype RenderOutputProvider
16 \inqmlmodule QtQuick3D.Helpers
17 \inherits TextureProviderExtension
18 \since 6.11
19 \brief Used as a bridge to use access textures provided by passes.
20
21 This type is used to provide textures that are the results of passes in the rendering pipeline.
22 Some example of when this is useful is when you want to access the depth texture result of the ZPrePass,
23 or the ambient occlusion texture result of the SSAO pass. This type can be used to access these results
24 textures and use them in materials or effects.
25
26 \code
27 Texture {
28 textureProvider: RenderOutputProvider {
29 // Specify the built-in buffer texture you want to access
30 textureSource: RenderOutputProvider.DepthTexture
31 }
32 }
33 \endcode
34*/
35
36/*!
37 \qmlproperty RenderOutputProvider::TextureSource textureSource
38 This property holds which pass buffer texture to use.
39
40 \value RenderOutputProvider.AoTexture The ambient occlusion texture created by the SSAO pass.
41 \value RenderOutputProvider.DepthTexture The depth texture created by the ZPrePass.
42 \value RenderOutputProvider.ScreenTexture The texture containing the rendered scene.
43 \value RenderOutputProvider.UserPassTexture A user defined pass. If this is used to access a user defined pass.
44
45*/
46
71
73 : m_ext(ext)
74{
75
76}
77
82
84{
85 // Get a handle the requested texture, then register that as the render result for this provider
86 QSSGExtensionId extensionId = QQuick3DExtensionHelpers::getExtensionId(*m_ext);
87 Q_ASSERT(!QQuick3DExtensionHelpers::isNull(extensionId));
88
89 const bool wasDirty = m_isDirty;
90
91 switch (m_sourceType) {
93 // Nothing to do
94 break;
96 {
97 // Make sure we schedule the pass to run this frame
98 data.scheduleRenderResults(QSSGFrameData::RenderResults(m_builtInPass));
99
100 // Check if a texture exists for the result already
101 QSSGFrameData::Result extResult = data.getRenderResult(m_builtInPass);
102 if (extResult.texture) {
103 QSSGRenderExtensionHelpers::registerRenderResult(data, extensionId, extResult.texture);
104 m_isDirty = false;
105 }
106 // No "else" in this case since its likely the texture for the pass doesn't exist yet, try again in prepareRender.
107 }
108 break;
109 }
110
111 return wasDirty;
112}
113
115{
116 // Get a handle the requested texture, then register that as the render result for this provider
117 QSSGExtensionId extensionId = QQuick3DExtensionHelpers::getExtensionId(*m_ext);
118 Q_ASSERT(!QQuick3DExtensionHelpers::isNull(extensionId));
119
121 QSSGFrameData::Result extResult = data.getRenderResult(m_builtInPass);
122 if (extResult.texture) {
123 QSSGRenderExtensionHelpers::registerRenderResult(data, extensionId, extResult.texture);
124 m_isDirty = false;
125 } else {
126 qWarning() << "couldn't find texture";
127 }
128 }
129}
130
132{
133 // Nothing to render
134}
135
137{
138 // Nothing to reset
139}
140
141
142/*!
143 \qmltype RenderOutputProvider
144 \nativetype QQuick3DRenderOutputProvider
145 \inqmlmodule QtQuick3D.Helpers
146 \inherits TextureProviderExtension
147 \since 6.11
148 \brief Used as a bridge to access textures provided in passes.
149
150 This type is used to provide textures that are generated by passes in the rendering pipeline.
151
152 Some example of when this is useful is when you want to access the depth texture generated by the ZPrePass,
153 or the ambient occlusion texture generated by the SSAO pass. This type can be used to access these generated
154 textures and use them in materials or effects.
155
156 \qml
157 Texture {
158 textureProvider: RenderOutputProvider {
159 // Specify the pass buffer texture you want to access
160 textureSource: RenderOutputProvider.DepthTexture
161 }
162 }
163 \endqml
164
165
166 \sa QQuick3DTextureProviderExtension, QSSGRenderExtension
167*/
168
169
170QQuick3DRenderOutputProvider::QQuick3DRenderOutputProvider(QQuick3DObject *parent)
171 : QQuick3DTextureProviderExtension(parent)
172{
173 update();
174}
175
176QSSGRenderGraphObject *QQuick3DRenderOutputProvider::updateSpatialNode(QSSGRenderGraphObject *node)
177{
178 // Create new node if needed
179 if (!node)
180 node = new QSSGRenderOutputProviderExtension(this);
181
182 QQuick3DTextureProviderExtension::updateSpatialNode(node);
183
184 QSSGRenderOutputProviderExtension *providerNode = static_cast<QSSGRenderOutputProviderExtension *>(node);
185
186 if (m_dirtyAttributes & TextureSourceDirty) {
187 providerNode->m_isDirty = true;
188 switch (m_textureSource) {
189 case QQuick3DRenderOutputProvider::TextureSource::None:
190 break;
191 case QQuick3DRenderOutputProvider::TextureSource::AoTexture:
192 providerNode->m_sourceType = QSSGRenderOutputProviderExtension::SourceType::BuiltInPass;
193 providerNode->m_builtInPass = QSSGFrameData::RenderResult::AoTexture;
194 break;
195 case QQuick3DRenderOutputProvider::TextureSource::DepthTexture:
196 providerNode->m_sourceType = QSSGRenderOutputProviderExtension::SourceType::BuiltInPass;
197 providerNode->m_builtInPass = QSSGFrameData::RenderResult::DepthTexture;
198 break;
199 case QQuick3DRenderOutputProvider::TextureSource::ScreenTexture:
200 providerNode->m_sourceType = QSSGRenderOutputProviderExtension::SourceType::BuiltInPass;
201 providerNode->m_builtInPass = QSSGFrameData::RenderResult::ScreenTexture;
202 break;
203 }
204 }
205
206 m_dirtyAttributes = 0;
207
208 return node;
209}
210
211void QQuick3DRenderOutputProvider::markAllDirty()
212{
213 m_dirtyAttributes = AllDirty;
214 QQuick3DTextureProviderExtension::markAllDirty();
215}
216
217void QQuick3DRenderOutputProvider::markDirty(QQuick3DRenderOutputProvider::DirtyType type)
218{
219 if (!(m_dirtyAttributes & quint32(type))) {
220 m_dirtyAttributes |= quint32(type);
221 update();
222 }
223}
224
225QQuick3DRenderOutputProvider::TextureSource QQuick3DRenderOutputProvider::textureSource() const
226{
227 return m_textureSource;
228}
229
230void QQuick3DRenderOutputProvider::setTextureSource(TextureSource newTextureSource)
231{
232 if (m_textureSource == newTextureSource)
233 return;
234 m_textureSource = newTextureSource;
235 emit textureSourceChanged();
236 markDirty(TextureSourceDirty);
237}
238
239QT_END_NAMESPACE
\qmltype RenderOutputProvider \inqmlmodule QtQuick3D.Helpers \inherits TextureProviderExtension
QSSGRenderOutputProviderExtension(QQuick3DRenderOutputProvider *ext)
void prepareRender(QSSGFrameData &data) override
Prepare data for rendering.
bool prepareData(QSSGFrameData &data) override
Called after scene data is collected, but before any render data or rendering in the current frame ha...
QPointer< QQuick3DRenderOutputProvider > m_ext
void render(QSSGFrameData &data) override
Record the render pass.
void resetForFrame() override
Called each time a new frame starts.