1 | // Copyright (C) 2015 Klaralvdalens Datakonsult AB (KDAB). |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qforwardrenderer.h" |
5 | #include "qforwardrenderer_p.h" |
6 | |
7 | #include <Qt3DCore/qentity.h> |
8 | #include <Qt3DRender/qviewport.h> |
9 | #include <Qt3DRender/qcameraselector.h> |
10 | #include <Qt3DRender/qclearbuffers.h> |
11 | #include <Qt3DRender/qfilterkey.h> |
12 | #include <Qt3DRender/qfrustumculling.h> |
13 | #include <Qt3DRender/qrendersurfaceselector.h> |
14 | #include <Qt3DRender/qdebugoverlay.h> |
15 | |
16 | static void initResources() |
17 | { |
18 | #ifdef QT_STATIC |
19 | Q_INIT_RESOURCE(extras); |
20 | #endif |
21 | } |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | using namespace Qt3DRender; |
26 | |
27 | namespace Qt3DExtras { |
28 | |
29 | QForwardRendererPrivate::() |
30 | : QTechniqueFilterPrivate() |
31 | , m_surfaceSelector(new QRenderSurfaceSelector) |
32 | , m_viewport(new QViewport()) |
33 | , m_cameraSelector(new QCameraSelector()) |
34 | , m_clearBuffer(new QClearBuffers()) |
35 | , m_frustumCulling(new QFrustumCulling()) |
36 | , m_debugOverlay(new QDebugOverlay()) |
37 | { |
38 | } |
39 | |
40 | void QForwardRendererPrivate::() |
41 | { |
42 | Q_Q(QForwardRenderer); |
43 | |
44 | initResources(); |
45 | |
46 | m_debugOverlay->setParent(m_frustumCulling); |
47 | m_debugOverlay->setEnabled(false); |
48 | m_frustumCulling->setParent(m_clearBuffer); |
49 | m_clearBuffer->setParent(m_cameraSelector); |
50 | m_cameraSelector->setParent(m_viewport); |
51 | m_viewport->setParent(m_surfaceSelector); |
52 | m_surfaceSelector->setParent(q); |
53 | |
54 | m_viewport->setNormalizedRect(QRectF(0.0, 0.0, 1.0, 1.0)); |
55 | m_clearBuffer->setClearColor(Qt::white); |
56 | m_clearBuffer->setBuffers(QClearBuffers::ColorDepthBuffer); |
57 | |
58 | QFilterKey *forwardRenderingStyle = new QFilterKey(q); |
59 | forwardRenderingStyle->setName(QStringLiteral("renderingStyle" )); |
60 | forwardRenderingStyle->setValue(QStringLiteral("forward" )); |
61 | q->addMatch(filterKey: forwardRenderingStyle); |
62 | } |
63 | |
64 | /*! |
65 | \class Qt3DExtras::QForwardRenderer |
66 | \brief The QForwardRenderer provides a default \l{Qt 3D Render Framegraph}{FrameGraph} |
67 | implementation of a forward renderer. |
68 | \inmodule Qt3DExtras |
69 | \since 5.7 |
70 | \inherits Qt3DRender::QTechniqueFilter |
71 | |
72 | Forward rendering is what OpenGL traditionally uses. It renders directly to the backbuffer |
73 | one object at a time shading each one as it goes. |
74 | |
75 | QForwardRenderer is a single leaf \l{Qt 3D Render Framegraph}{FrameGraph} tree which contains |
76 | a Qt3DRender::QViewport, a Qt3DRender::QCameraSelector, and a Qt3DRender::QClearBuffers. |
77 | The QForwardRenderer has a default requirement filter key whose name is "renderingStyle" and |
78 | value "forward". |
79 | If you need to filter out your techniques, you should do so based on that filter key. |
80 | |
81 | By default the viewport occupies the whole screen and the clear color is white. |
82 | Frustum culling is also enabled. |
83 | */ |
84 | /*! |
85 | \qmltype ForwardRenderer |
86 | \brief The ForwardRenderer provides a default \l{Qt 3D Render Framegraph}{FrameGraph} |
87 | implementation of a forward renderer. |
88 | \since 5.7 |
89 | \inqmlmodule Qt3D.Extras |
90 | \instantiates Qt3DExtras::QForwardRenderer |
91 | |
92 | Forward rendering is what OpenGL traditionally uses. It renders directly to the backbuffer |
93 | one object at a time shading each one as it goes. |
94 | |
95 | ForwardRenderer is a single leaf \l{Qt 3D Render Framegraph}{FrameGraph} tree which contains |
96 | a Viewport, a CameraSelector, and a ClearBuffers. |
97 | The ForwardRenderer has a default requirement filter key whose name is "renderingStyle" and |
98 | value "forward". |
99 | If you need to filter out your techniques, you should do so based on that filter key. |
100 | |
101 | By default the viewport occupies the whole screen and the clear color is white. |
102 | Frustum culling is also enabled. |
103 | */ |
104 | |
105 | QForwardRenderer::(QNode *parent) |
106 | : QTechniqueFilter(*new QForwardRendererPrivate, parent) |
107 | { |
108 | Q_D(QForwardRenderer); |
109 | QObject::connect(sender: d->m_clearBuffer, signal: &QClearBuffers::clearColorChanged, context: this, slot: &QForwardRenderer::clearColorChanged); |
110 | QObject::connect(sender: d->m_clearBuffer, signal: &QClearBuffers::buffersChanged, context: this, slot: &QForwardRenderer::buffersToClearChanged); |
111 | QObject::connect(sender: d->m_viewport, signal: &QViewport::normalizedRectChanged, context: this, slot: &QForwardRenderer::viewportRectChanged); |
112 | QObject::connect(sender: d->m_cameraSelector, signal: &QCameraSelector::cameraChanged, context: this, slot: &QForwardRenderer::cameraChanged); |
113 | QObject::connect(sender: d->m_surfaceSelector, signal: &QRenderSurfaceSelector::surfaceChanged, context: this, slot: &QForwardRenderer::surfaceChanged); |
114 | QObject::connect(sender: d->m_surfaceSelector, signal: &QRenderSurfaceSelector::externalRenderTargetSizeChanged, context: this, slot: &QForwardRenderer::externalRenderTargetSizeChanged); |
115 | QObject::connect(sender: d->m_frustumCulling, signal: &QFrustumCulling::enabledChanged, context: this, slot: &QForwardRenderer::frustumCullingEnabledChanged); |
116 | QObject::connect(sender: d->m_viewport, signal: &QViewport::gammaChanged, context: this, slot: &QForwardRenderer::gammaChanged); |
117 | QObject::connect(sender: d->m_debugOverlay, signal: &QDebugOverlay::enabledChanged, context: this, slot: &QForwardRenderer::showDebugOverlayChanged); |
118 | d->init(); |
119 | } |
120 | |
121 | QForwardRenderer::() |
122 | { |
123 | } |
124 | |
125 | void QForwardRenderer::(const QRectF &viewportRect) |
126 | { |
127 | Q_D(QForwardRenderer); |
128 | d->m_viewport->setNormalizedRect(viewportRect); |
129 | } |
130 | |
131 | void QForwardRenderer::(const QColor &clearColor) |
132 | { |
133 | Q_D(QForwardRenderer); |
134 | d->m_clearBuffer->setClearColor(clearColor); |
135 | } |
136 | |
137 | void QForwardRenderer::(QClearBuffers::BufferType buffers) |
138 | { |
139 | Q_D(QForwardRenderer); |
140 | d->m_clearBuffer->setBuffers(buffers); |
141 | } |
142 | |
143 | void QForwardRenderer::(Qt3DCore::QEntity *camera) |
144 | { |
145 | Q_D(QForwardRenderer); |
146 | d->m_cameraSelector->setCamera(camera); |
147 | } |
148 | |
149 | void QForwardRenderer::(QObject *surface) |
150 | { |
151 | Q_D(QForwardRenderer); |
152 | d->m_surfaceSelector->setSurface(surface); |
153 | } |
154 | |
155 | void QForwardRenderer::(const QSize &size) |
156 | { |
157 | Q_D(QForwardRenderer); |
158 | d->m_surfaceSelector->setExternalRenderTargetSize(size); |
159 | } |
160 | |
161 | void QForwardRenderer::(bool enabled) |
162 | { |
163 | Q_D(QForwardRenderer); |
164 | d->m_frustumCulling->setEnabled(enabled); |
165 | } |
166 | |
167 | void QForwardRenderer::(float gamma) |
168 | { |
169 | Q_D(QForwardRenderer); |
170 | d->m_viewport->setGamma(gamma); |
171 | } |
172 | |
173 | void QForwardRenderer::(bool showDebugOverlay) |
174 | { |
175 | Q_D(QForwardRenderer); |
176 | d->m_debugOverlay->setEnabled(showDebugOverlay); |
177 | } |
178 | |
179 | /*! |
180 | \qmlproperty rect ForwardRenderer::viewportRect |
181 | |
182 | Holds the current normalized viewport rectangle. |
183 | */ |
184 | /*! |
185 | \property QForwardRenderer::viewportRect |
186 | |
187 | Holds the current normalized viewport rectangle. |
188 | */ |
189 | QRectF QForwardRenderer::() const |
190 | { |
191 | Q_D(const QForwardRenderer); |
192 | return d->m_viewport->normalizedRect(); |
193 | } |
194 | |
195 | /*! |
196 | \qmlproperty color ForwardRenderer::clearColor |
197 | |
198 | Holds the current clear color of the scene. The frame buffer is initialized to the clear color |
199 | before rendering. |
200 | */ |
201 | /*! |
202 | \property QForwardRenderer::clearColor |
203 | |
204 | Holds the current clear color of the scene. The frame buffer is initialized to the clear color |
205 | before rendering. |
206 | */ |
207 | QColor QForwardRenderer::() const |
208 | { |
209 | Q_D(const QForwardRenderer); |
210 | return d->m_clearBuffer->clearColor(); |
211 | } |
212 | |
213 | /*! |
214 | \qmlproperty color ForwardRenderer::buffersToClear |
215 | |
216 | Holds the current buffers to be cleared. Default value is ColorDepthBuffer |
217 | \since 5.14 |
218 | */ |
219 | /*! |
220 | \property QForwardRenderer::buffersToClear |
221 | |
222 | Holds the current buffers to be cleared. Default value is ColorDepthBuffer |
223 | \since 5.14 |
224 | */ |
225 | QClearBuffers::BufferType QForwardRenderer::() const |
226 | { |
227 | Q_D(const QForwardRenderer); |
228 | return d->m_clearBuffer->buffers(); |
229 | } |
230 | |
231 | /*! |
232 | \qmlproperty Entity ForwardRenderer::camera |
233 | |
234 | Holds the current camera entity used to render the scene. |
235 | |
236 | \note A camera is an Entity that has a CameraLens as one of its components. |
237 | */ |
238 | /*! |
239 | \property QForwardRenderer::camera |
240 | |
241 | Holds the current camera entity used to render the scene. |
242 | |
243 | \note A camera is a QEntity that has a QCameraLens as one of its components. |
244 | */ |
245 | Qt3DCore::QEntity *QForwardRenderer::() const |
246 | { |
247 | Q_D(const QForwardRenderer); |
248 | return d->m_cameraSelector->camera(); |
249 | } |
250 | |
251 | /*! |
252 | \qmlproperty QtObject ForwardRenderer::window |
253 | |
254 | Holds the current render surface. |
255 | |
256 | \deprecated |
257 | */ |
258 | /*! |
259 | \property QForwardRenderer::window |
260 | |
261 | Holds the current render surface. |
262 | |
263 | \deprecated |
264 | */ |
265 | |
266 | /*! |
267 | \qmlproperty QtObject ForwardRenderer::surface |
268 | |
269 | Holds the current render surface. |
270 | */ |
271 | /*! |
272 | \property QForwardRenderer::surface |
273 | |
274 | Holds the current render surface. |
275 | */ |
276 | QObject *QForwardRenderer::() const |
277 | { |
278 | Q_D(const QForwardRenderer); |
279 | return d->m_surfaceSelector->surface(); |
280 | } |
281 | |
282 | /*! |
283 | \qmlproperty QSize ForwardRenderer::externalRenderTargetSize |
284 | |
285 | Contains the size of the external render target. External render |
286 | targets are relevant when rendering does not target a window |
287 | surface (as set in \l {surface}). |
288 | */ |
289 | /*! |
290 | \property QForwardRenderer::externalRenderTargetSize |
291 | |
292 | Contains the size of the external render target. External render |
293 | targets are relevant when rendering does not target a window |
294 | surface (as set in \l {surface}). |
295 | */ |
296 | QSize QForwardRenderer::() const |
297 | { |
298 | Q_D(const QForwardRenderer); |
299 | return d->m_surfaceSelector->externalRenderTargetSize(); |
300 | } |
301 | |
302 | /*! |
303 | \qmlproperty bool ForwardRenderer::frustumCulling |
304 | |
305 | Indicates if the renderer applies frustum culling to the scene. |
306 | */ |
307 | /*! |
308 | \property QForwardRenderer::frustumCulling |
309 | |
310 | Indicates if the renderer applies frustum culling to the scene. |
311 | */ |
312 | bool QForwardRenderer::() const |
313 | { |
314 | Q_D(const QForwardRenderer); |
315 | return d->m_frustumCulling->isEnabled(); |
316 | } |
317 | |
318 | /*! |
319 | \qmlproperty real ForwardRenderer::gamma |
320 | |
321 | Holds the gamma value the renderer applies to the scene. |
322 | */ |
323 | /*! |
324 | \property QForwardRenderer::gamma |
325 | |
326 | Holds the gamma value the renderer applies to the scene. |
327 | */ |
328 | float QForwardRenderer::() const |
329 | { |
330 | Q_D(const QForwardRenderer); |
331 | return d->m_viewport->gamma(); |
332 | } |
333 | |
334 | /*! |
335 | \qmlproperty bool ForwardRenderer::showDebugOverlay |
336 | |
337 | If true, a debug overlay will be rendered over the scene. It will show |
338 | detailed information about the runtime rendering state, let the user |
339 | turn logging on and off, etc. |
340 | |
341 | \since 5.15 |
342 | */ |
343 | /*! |
344 | \property QForwardRenderer::showDebugOverlay |
345 | |
346 | If true, a debug overlay will be rendered over the scene. It will show |
347 | detailed information about the runtime rendering state, let the user |
348 | turn logging on and off, etc. |
349 | |
350 | \since 5.15 |
351 | */ |
352 | bool QForwardRenderer::() const |
353 | { |
354 | Q_D(const QForwardRenderer); |
355 | return d->m_debugOverlay->isEnabled(); |
356 | } |
357 | |
358 | } // namespace Qt3DExtras |
359 | |
360 | QT_END_NAMESPACE |
361 | |
362 | #include "moc_qforwardrenderer.cpp" |
363 | |