1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qssgrenderextensions_p.h" |
5 | #include "private/qssgassert_p.h" |
6 | #include "private/qssglayerrenderdata_p.h" |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | |
10 | /*! |
11 | \class QSSGFrameData |
12 | \inmodule QtQuick3DRuntimeRender |
13 | \since 6.6 |
14 | |
15 | \brief Storage class containing data collected for a frame. |
16 | */ |
17 | |
18 | /*! |
19 | \brief QSSGFrameData::getRenderPassResult(QSSGFrameData::RenderResult id) |
20 | \return The renderable texture result from \a id. Null if no matching \a id was found. |
21 | |
22 | \note Even if the function returns a non-null result, the returned \l QSSGRhiRenderableTexture |
23 | might not be ready unless the pass rendering to the texture has been executed. |
24 | |
25 | \note The returned value is only valid within the current frame. On each new frame |
26 | the renderable will be reset and should therefore be queried again. |
27 | */ |
28 | const QSSGRhiRenderableTexture *QSSGFrameData::getRenderResult(RenderResult id) const |
29 | { |
30 | const QSSGRhiRenderableTexture *res = nullptr; |
31 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
32 | if (QSSG_GUARD(data && (std::size(data->renderResults) > RenderResultT(id)))) |
33 | res = data->getRenderResult(id); |
34 | |
35 | return res; |
36 | } |
37 | |
38 | /*! |
39 | \fn QSSGFrameData::getPipelineState() const |
40 | \return Base pipeline state for this frame |
41 | */ |
42 | |
43 | QSSGRhiGraphicsPipelineState QSSGFrameData::getPipelineState() const |
44 | { |
45 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
46 | QSSG_ASSERT(data, return {}); |
47 | return data->getPipelineState(); |
48 | } |
49 | |
50 | /*! |
51 | \fn QSSGFrameData::getNode(QSSGNodeId id) const |
52 | \a id a \c QSSGNodeId |
53 | \return The \l {QSSGRenderableNodeEntry}{renderable entry} that corresponds to the \c QSSGNodeId. |
54 | |
55 | \note This function does not remove the renderable entry which means any other extension or internal |
56 | code processed after this extension will be able to process it as well. |
57 | |
58 | \sa QSSGFrameData::takeNode(), QQuick3DExtensionHelpers::getNodeId(), QSSGRenderableNodeEntry |
59 | */ |
60 | |
61 | QSSGRenderableNodeEntry QSSGFrameData::getNode(QSSGNodeId id) const |
62 | { |
63 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
64 | QSSG_ASSERT(data, return {}); |
65 | return data->getNode(id); |
66 | } |
67 | |
68 | /*! |
69 | \fn QSSGFrameData::takeNode(QSSGNodeId id) |
70 | \a id a \c QSSGNodeId |
71 | \return The \l {QSSGRenderableNodeEntry}{renderable entry} that corresponds to the provided \c QSSGNodeId. |
72 | |
73 | \note This function \b removes the renderable entry which means it won't be available for any other |
74 | extension or internal code executed after this extension. |
75 | |
76 | \sa QSSGFrameData::takeNode(), QQuick3DExtensionHelpers::getNodeId(), QSSGRenderableNodeEntry |
77 | */ |
78 | QSSGRenderableNodeEntry QSSGFrameData::takeNode(QSSGNodeId id) |
79 | { |
80 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
81 | QSSG_ASSERT(data, return {}); |
82 | return data->takeNode(id); |
83 | } |
84 | |
85 | /*! |
86 | \fn QSSGFrameData::getResource(QSSGResourceId id) const |
87 | \a id a \c QSSGNodeId |
88 | \return The \l {QSSGRenderGraphObject}{resource object} that corresponds to the provided \c QSSGResourceId. |
89 | |
90 | \sa QQuick3DExtensionHelpers::getResourceId() |
91 | */ |
92 | QSSGRenderGraphObject *QSSGFrameData::getResource(QSSGResourceId id) const |
93 | { |
94 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
95 | QSSG_ASSERT(data, return {}); |
96 | return data->getResource(id); |
97 | } |
98 | |
99 | /*! |
100 | \fn QSSGFrameData::camera() const |
101 | |
102 | \return The main camera for the scene, or null if non could be found. |
103 | |
104 | \sa QSSGRenderCamera |
105 | */ |
106 | QSSGRenderCamera *QSSGFrameData::camera() const |
107 | { |
108 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
109 | QSSG_ASSERT(data, return {}); |
110 | return data->activeCamera(); |
111 | } |
112 | |
113 | void QSSGFrameData::clear() |
114 | { |
115 | |
116 | } |
117 | |
118 | QSSGLayerRenderData *QSSGFrameData::getCurrent() const |
119 | { |
120 | return QSSGLayerRenderData::getCurrent(renderer: *m_renderer); |
121 | } |
122 | |
123 | QSSGFrameData::QSSGFrameData(QSSGRenderer *renderer) |
124 | : m_renderer(renderer) |
125 | { |
126 | |
127 | } |
128 | |
129 | QSSGRenderExtension::QSSGRenderExtension() |
130 | : QSSGRenderGraphObject(QSSGRenderGraphObject::Type::RenderExtension) |
131 | { |
132 | |
133 | } |
134 | |
135 | QSSGRenderExtension::~QSSGRenderExtension() |
136 | { |
137 | |
138 | } |
139 | |
140 | /*! |
141 | \enum QSSGRenderExtension::Type |
142 | |
143 | Specifies the render extension type. |
144 | |
145 | \value Standalone The rendering code is recorded in full during the render prepare phase. |
146 | This will usually imply that there are some output crated for a preceding render extension(s). |
147 | When this type is used the \l prepareRender() and \l render() functions are both called during |
148 | the frame's prepare phase. |
149 | |
150 | \value Main The rendering code is recorded within the main render pass. In this mode the |
151 | \l prepareRender() is called in the frame's prepare phase while \l render() is called the frame's render phase. |
152 | |
153 | */ |
154 | |
155 | /*! |
156 | \enum QSSGRenderExtension::Mode |
157 | |
158 | Specifies the order the extension will be called. |
159 | |
160 | \value Underlay The rendering code is recorded and executed before the main (color) pass. |
161 | \value Overlay The rendering code is recorded and executed after the main (color) pass. |
162 | */ |
163 | |
164 | |
165 | /*! |
166 | \fn bool QSSGRenderExtension::prepareData(QSSGFrameData &data) |
167 | |
168 | Called after scene data is collected, but before any render data or rendering in the current |
169 | frame has been done. |
170 | |
171 | \return Dirty state. Return \c true if the there are dirty data |
172 | that needs to be rendered. |
173 | |
174 | \note Much of the data created/collected from the engine during the prepare and render phases |
175 | is per-frame and should be released or assumed released at the start of the next frame |
176 | |
177 | \sa QSSGFrameData |
178 | */ |
179 | bool QSSGRenderExtension::prepareData(QSSGFrameData &data) |
180 | { |
181 | Q_UNUSED(data); |
182 | return false; |
183 | } |
184 | |
185 | /*! |
186 | \fn void QSSGRenderExtension::prepareRender(const QSSGRenderer &renderer, QSSGFrameData &data) |
187 | |
188 | Prepare data for rendering. Build and collect data needed for rendering. Any render extension |
189 | scheduled before this one has been processed. In addition; any render extension of |
190 | type \l Type::Standalon will, if successful, have been completed in full. |
191 | |
192 | \note Much of the data created/collected from the engine during the prepare and render phases |
193 | is per-frame and should be released or assumed released at the start of the next frame |
194 | |
195 | \sa QSSGFrameData, QSSGRenderer |
196 | */ |
197 | void QSSGRenderExtension::prepareRender(const QSSGRenderer &renderer, QSSGFrameData &data) |
198 | { |
199 | Q_UNUSED(renderer); |
200 | Q_UNUSED(data); |
201 | } |
202 | |
203 | /*! |
204 | \fn QSSGRenderExtension::render(const QSSGRenderer &renderer) |
205 | \a renderer handle to the QtQuick3D's render object. |
206 | |
207 | Record the render pass. Depending on the extensions \l {Type}{type} this function will be called |
208 | during the frame's prepare or render phase. |
209 | |
210 | \sa QSSGRenderExtension::Type, QSSGRenderer |
211 | */ |
212 | void QSSGRenderExtension::render(const QSSGRenderer &renderer) |
213 | { |
214 | Q_UNUSED(renderer); |
215 | } |
216 | |
217 | /*! |
218 | \fn QSSGRenderExtension::release() |
219 | |
220 | Called each time a new frame starts. Any data from the previous frame should be cleared at |
221 | this point. |
222 | */ |
223 | void QSSGRenderExtension::release() |
224 | { |
225 | |
226 | } |
227 | |
228 | /*! |
229 | \fn QSSGRenderExtension::type() const |
230 | \return The render extension type. |
231 | |
232 | \sa QSSGRenderExtension::Type |
233 | */ |
234 | QSSGRenderExtension::Type QSSGRenderExtension::type() const |
235 | { |
236 | return Type::Main; |
237 | } |
238 | |
239 | /*! |
240 | \fn QSSGRenderExtension::mode() const |
241 | \return The mode that should used for this render extension. |
242 | |
243 | \sa QSSGRenderExtension::RenderMode |
244 | */ |
245 | QSSGRenderExtension::RenderMode QSSGRenderExtension::mode() const |
246 | { |
247 | return RenderMode::Overlay; |
248 | } |
249 | |
250 | QT_END_NAMESPACE |
251 | |