1 | // Copyright (C) 2023 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "qssgrenderextensions.h" |
5 | #include "private/qssgassert_p.h" |
6 | #include "private/qssglayerrenderdata_p.h" |
7 | #include "qssgrendercontextcore.h" |
8 | |
9 | QT_BEGIN_NAMESPACE |
10 | |
11 | /*! |
12 | \class QSSGFrameData |
13 | \inmodule QtQuick3D |
14 | \since 6.7 |
15 | |
16 | \brief Storage class containing data collected for a frame. |
17 | */ |
18 | |
19 | /*! |
20 | \return The renderable texture result from \a id. \nullptr if no matching \a id was found. |
21 | |
22 | \note Even if the function returns a non-null result, the returned 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 | QSSGFrameData::Result QSSGFrameData::getRenderResult(RenderResult id) const |
29 | { |
30 | using RenderResultT = std::underlying_type_t<RenderResult>; |
31 | const QSSGRhiRenderableTexture *res = nullptr; |
32 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_ctx->renderer()); |
33 | if (QSSG_GUARD(data && (std::size(data->renderResults) > RenderResultT(id)))) |
34 | res = data->getRenderResult(id); |
35 | |
36 | return res ? Result{ .texture: res->texture, .buffer: res->depthStencil } : Result{}; |
37 | } |
38 | |
39 | /*! |
40 | \return Base pipeline state for this frame |
41 | */ |
42 | QSSGRhiGraphicsPipelineState QSSGFrameData::getPipelineState() const |
43 | { |
44 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_ctx->renderer()); |
45 | QSSG_ASSERT(data, return {}); |
46 | return data->getPipelineState(); |
47 | } |
48 | |
49 | /*! |
50 | \return The active camera for the scene, or null if non could be found. |
51 | */ |
52 | QSSGCameraId QSSGFrameData::activeCamera() const |
53 | { |
54 | QSSGCameraId ret { QSSGCameraId::Invalid }; |
55 | auto *data = QSSGLayerRenderData::getCurrent(renderer: *m_ctx->renderer()); |
56 | QSSG_ASSERT(data, return ret); |
57 | if (auto *ac = data->activeCamera()) |
58 | ret = QSSGRenderGraphObjectUtils::getCameraId(o: *ac); |
59 | |
60 | return ret; |
61 | } |
62 | |
63 | QSSGRenderContextInterface *QSSGFrameData::contextInterface() const |
64 | { |
65 | return m_ctx; |
66 | } |
67 | |
68 | void QSSGFrameData::clear() |
69 | { |
70 | |
71 | } |
72 | |
73 | QSSGLayerRenderData *QSSGFrameData::getCurrent() const |
74 | { |
75 | return QSSGLayerRenderData::getCurrent(renderer: *m_ctx->renderer()); |
76 | } |
77 | |
78 | QSSGFrameData::QSSGFrameData(QSSGRenderContextInterface *ctx) |
79 | : m_ctx(ctx) |
80 | { |
81 | |
82 | } |
83 | |
84 | /*! |
85 | \class QSSGRenderExtension |
86 | \inmodule QtQuick3D |
87 | \since 6.7 |
88 | |
89 | \brief Base class for extension backend node implementations. |
90 | |
91 | \sa QQuick3DRenderExtension |
92 | */ |
93 | |
94 | QSSGRenderExtension::QSSGRenderExtension() |
95 | : QSSGRenderGraphObject(QSSGRenderGraphObject::Type::RenderExtension, FlagT(Flags::HasGraphicsResources)) |
96 | { |
97 | |
98 | } |
99 | |
100 | QSSGRenderExtension::~QSSGRenderExtension() |
101 | { |
102 | |
103 | } |
104 | |
105 | /*! |
106 | \enum QSSGRenderExtension::RenderMode |
107 | |
108 | Specifies the render extension mode. |
109 | |
110 | \value Standalone The rendering code is recorded in full during the render prepare phase. |
111 | This will usually imply that there are some output crated for a preceding render extension(s). |
112 | When this mode is used the \l prepareRender() and \l render() functions are both called during |
113 | the frame's prepare phase. |
114 | |
115 | \value Main The rendering code is recorded within the main render pass. In this mode the |
116 | \l prepareRender() is called in the frame's prepare phase while \l render() is called the frame's render phase. |
117 | |
118 | */ |
119 | |
120 | /*! |
121 | \enum QSSGRenderExtension::RenderStage |
122 | |
123 | Specifies the order the extension will be called. |
124 | |
125 | \value PreColor The rendering code is recorded and executed before the main (color) pass. |
126 | \value PostColor The rendering code is recorded and executed after the main (color) pass. |
127 | */ |
128 | |
129 | |
130 | /*! |
131 | Called after scene \a data is collected, but before any render data or rendering in the current |
132 | frame has been done. |
133 | |
134 | \return Dirty state. Return \c true if the there are dirty data |
135 | that needs to be rendered. |
136 | |
137 | \note Much of the data created/collected from the engine during the prepare and render phases |
138 | is per-frame and should be released or assumed released at the start of the next frame |
139 | |
140 | \sa QSSGFrameData |
141 | */ |
142 | bool QSSGRenderExtension::prepareData(QSSGFrameData &data) |
143 | { |
144 | Q_UNUSED(data); |
145 | return false; |
146 | } |
147 | |
148 | /*! |
149 | Prepare data for rendering. Build and collect \a data needed for rendering. Any render extension |
150 | scheduled before this one has been processed. In addition; any render extension of |
151 | mode \l RenderMode::Standalone will, if successful, have been completed in full. |
152 | |
153 | \note Much of the data created/collected from the engine during the prepare and render phases |
154 | is per-frame and should be released or assumed released at the start of the next frame |
155 | |
156 | \sa QSSGFrameData |
157 | */ |
158 | void QSSGRenderExtension::prepareRender(QSSGFrameData &data) |
159 | { |
160 | Q_UNUSED(data); |
161 | } |
162 | |
163 | /*! |
164 | Record the render pass. Depending on the extensions \l {RenderMode}{mode} this function will be called |
165 | during the frame's prepare or render phase. |
166 | |
167 | Use \a data to gain access to the render context from which the active QRhi object can be queried. |
168 | |
169 | \sa QSSGRenderExtension::RenderMode |
170 | */ |
171 | void QSSGRenderExtension::render(QSSGFrameData &data) |
172 | { |
173 | Q_UNUSED(data); |
174 | } |
175 | |
176 | /*! |
177 | Called each time a new frame starts. Any data from the previous frame should be cleared at |
178 | this point. |
179 | */ |
180 | void QSSGRenderExtension::resetForFrame() |
181 | { |
182 | |
183 | } |
184 | |
185 | /*! |
186 | \return The render mode used for this extension. |
187 | */ |
188 | QSSGRenderExtension::RenderMode QSSGRenderExtension::mode() const |
189 | { |
190 | return RenderMode::Main; |
191 | } |
192 | |
193 | /*! |
194 | \return The stage in which this render extension will be used. |
195 | */ |
196 | QSSGRenderExtension::RenderStage QSSGRenderExtension::stage() const |
197 | { |
198 | return RenderStage::PostColor; |
199 | } |
200 | |
201 | QT_END_NAMESPACE |
202 | |