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
qquick3dscenerenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2019 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
6#ifndef QSSGSCENERENDERER_H
7#define QSSGSCENERENDERER_H
8
9//
10// W A R N I N G
11// -------------
12//
13// This file is not part of the Qt API. It exists purely as an
14// implementation detail. This header file may change from version to
15// version without notice, or even be removed.
16//
17// We mean it.
18//
19
20#include <ssg/qssgrendercontextcore.h>
21
22#include <qsgtextureprovider.h>
23#include <qsgrendernode.h>
24#include <QSGSimpleTextureNode>
25
26#include <QtQuick3D/private/qquick3dviewport_p.h>
27#include <QtQuick3DRuntimeRender/private/qssgrenderlayer_p.h>
28#include <QtQuick3DRuntimeRender/private/qssgrhieffectsystem_p.h>
29#include <QtQuick3DRuntimeRender/private/qssgrenderer_p.h>
30
31#include <QtCore/qpointer.h>
32
33#include <optional>
34
36
38
39
40class QQuick3DSceneManager;
41class QQuick3DViewport;
42
44{
46public:
47 explicit QQuick3DSceneRenderer(const std::shared_ptr<QSSGRenderContextInterface> &rci);
49
50 static QSSGRenderLayer::TonemapMode getTonemapMode(const QQuick3DSceneEnvironment &environment)
51 {
52 if (environment.useBuiltinTonemapper())
53 return QSSGRenderLayer::TonemapMode(environment.tonemapMode());
54
55 // Special case for the extend scene environment...
56 return (environment.tonemapMode() != QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes::TonemapModeNone) ? QSSGRenderLayer::TonemapMode::Custom
57 : QSSGRenderLayer::TonemapMode::None;
58 }
59
60protected:
61 QRhiTexture *renderToRhiTexture(QQuickWindow *qw);
62 void beginFrame();
63 void endFrame();
64 void rhiPrepare(const QRect &viewport, qreal displayPixelRatio);
65 void rhiRender();
66 void synchronize(QQuick3DViewport *view3D, const QSize &size, float dpr);
68 QSize surfaceSize() const { return m_surfaceSize; }
70
71 std::optional<QSSGRenderRay> getRayFromViewportPos(const QPointF &pos);
72 PickResultList syncPick(const QSSGRenderRay &ray);
73 PickResultList syncPickOne(const QSSGRenderRay &ray, QSSGRenderNode *node);
74 PickResultList syncPickSubset(const QSSGRenderRay &ray, QVarLengthArray<QSSGRenderNode *> subset);
75 PickResultList syncPickAll(const QSSGRenderRay &ray);
76 std::optional<QSSGRenderPickResult> syncPickClosestPoint(const QVector3D &center, float radiusSquared, QSSGRenderNode *node);
77 QList<const QSSGRenderNode *> syncPickInFrustum(const QSSGFrustum &frustum);
78
79 void setGlobalPickingEnabled(bool isEnabled);
80
82
83private:
84 void releaseAaDependentRhiResources();
85 void updateLayerNode(QSSGRenderLayer &layerNode,
86 const QQuick3DViewport &view3D,
87 const QList<QSSGRenderGraphObject *> &resourceLoaders);
88 void addNodeToLayer(QSSGRenderNode *node);
89 void removeNodeFromLayer(QSSGRenderNode *node);
90 void maybeSetupLightmapBaking(QQuick3DViewport *view3D);
91 std::shared_ptr<QSSGRenderContextInterface> m_sgContext;
92 QSSGRenderLayer *m_layer = nullptr;
93 QPointer<QQuick3DWindowAttachment> winAttacment;
94 QSize m_surfaceSize;
95 SGFramebufferObjectNode *fboNode = nullptr;
96 bool m_aaIsDirty = true;
97 bool m_temporalIsDirty = false;
98 bool m_timeBasedAA = false;
99
100 // RHI
101 QRhiTexture *m_texture = nullptr;
102 // the rt is set up to output into m_texture or m_ssaaTexture or m_msaaRenderBuffer(+resolve into m_texture)
103 QRhiTextureRenderTarget *m_textureRenderTarget = nullptr;
104 QRhiRenderPassDescriptor *m_textureRenderPassDescriptor = nullptr;
105 // used by the draw quad that does m_ssaaTexture -> m_texture
106 QRhiTextureRenderTarget *m_ssaaTextureToTextureRenderTarget = nullptr;
107 QRhiRenderPassDescriptor *m_ssaaTextureToTextureRenderPassDescriptor = nullptr;
108 QRhiRenderBuffer *m_msaaRenderBufferLegacy = nullptr;
109 QRhiTexture *m_msaaRenderTexture = nullptr;
110 QRhiTexture *m_msaaMultiViewRenderBuffer = nullptr;
111 QRhiTexture *m_ssaaTexture = nullptr;
112 QRhiTexture *m_temporalAATexture = nullptr;
113 QRhiTexture *m_prevTempAATexture = nullptr;
114 QRhiTextureRenderTarget *m_temporalAARenderTarget = nullptr;
115 QRhiRenderPassDescriptor *m_temporalAARenderPassDescriptor = nullptr;
116 QRhiRenderBuffer *m_depthStencilBuffer = nullptr;
117 QRhiTexture *m_multiViewDepthStencilBuffer = nullptr;
118 bool m_textureNeedsFlip = true;
119 QSSGRenderLayer::Background m_backgroundMode = QSSGRenderLayer::Background::Unspecified;
120 QColor m_userBackgroundColor = Qt::black;
121 QColor m_linearBackgroundColor = Qt::black;
122 QColor m_tonemappedBackgroundColor = Qt::black;
123 int m_samples = 1;
124 QSSGRhiEffectSystem *m_effectSystem = nullptr;
125
126 QPointer<QQuick3DRenderStats> m_renderStats;
127
128 QSSGRenderNode *m_sceneRootNode = nullptr;
129 QSSGRenderNode *m_importSceneRootNode = nullptr;
130
131 bool m_prepared = false;
132
133 QSSGLightmapperOptions lmOptions;
134 bool m_lightmapBakingFromCmdRequested = false;
135 bool m_lightmapDenoisingFromCmdRequested = false;
136
137 int m_requestedFramesCount = 0;
138 bool m_postProcessingStack = false;
139 bool m_useFBO = false;
141
143 friend class QQuick3DSGRenderNode;
145 friend class QQuick3DViewport;
147 friend class QQuick3DRenderLayerHelpers;
148};
149
150class Q_QUICK3D_EXPORT QQuick3DRenderLayerHelpers
151{
152public:
153 static void updateLayerNodeHelper(const QQuick3DViewport &view3D,
154 const std::shared_ptr<QSSGRenderContextInterface> &rci,
155 QSSGRenderLayer &layerNode,
156 bool &aaIsDirty,
157 bool &temporalIsDirty);
158};
159
161{
163
164public:
167
168 void scheduleRender();
169
170 QSGTexture *texture() const override;
171
172 void preprocess() override;
173
174public Q_SLOTS:
175 void render();
176
177 void handleScreenChange();
178
179public:
182 QQuick3DViewport *quickFbo;
183
186
188};
189
190class QQuick3DSGRenderNode final : public QSGRenderNode
191{
192public:
194 void prepare() override;
195 StateFlags changedStates() const override;
196 void render(const RenderState *state) override;
198 RenderingFlags flags() const override;
199public:
202};
203
205{
207public:
212 QQuick3DSGDirectRenderer(QQuick3DSceneRenderer *renderer, QQuickWindow *window, QQuick3DSGDirectRendererMode mode = Underlay);
214
215 QQuick3DSceneRenderer *renderer() { return m_renderer; }
216 void setViewport(const QRectF &viewport);
217
218 void requestRender();
219 void setVisibility(bool visible);
220
221 void preSynchronize();
222
223private Q_SLOTS:
224 void prepare();
225 void render();
226
227private:
228 QQuick3DSceneRenderer *m_renderer = nullptr;
229 QQuickWindow *m_window = nullptr;
230 QRectF m_viewport;
231 bool m_isVisible = true;
232 QRhiTexture *m_rhiTexture = nullptr;
233 bool renderPending = false;
234};
235
236QT_END_NAMESPACE
237
238#endif // QSSGSCENERENDERER_H
QQuick3DSceneRenderer * renderer()
void setViewport(const QRectF &viewport)
QQuick3DSGDirectRenderer(QQuick3DSceneRenderer *renderer, QQuickWindow *window, QQuick3DSGDirectRendererMode mode=Underlay)
void render(const RenderState *state) override
This function is called by the renderer and should paint this node with directly invoking commands vi...
void releaseResources() override
This function is called when all custom graphics resources allocated by this node have to be freed im...
RenderingFlags flags() const override
void prepare() override
Called from the frame preparation phase.
QQuick3DSceneRenderer * renderer
StateFlags changedStates() const override
This function should return a mask where each bit represents graphics states changed by the \l render...
QRhiTexture * renderToRhiTexture(QQuickWindow *qw)
PickResultList syncPick(const QSSGRenderRay &ray)
QQuick3DSceneRenderer(const std::shared_ptr< QSSGRenderContextInterface > &rci)
void rhiPrepare(const QRect &viewport, qreal displayPixelRatio)
PickResultList syncPickSubset(const QSSGRenderRay &ray, QVarLengthArray< QSSGRenderNode * > subset)
void synchronize(QQuick3DViewport *view3D, const QSize &size, float dpr)
std::optional< QSSGRenderRay > getRayFromViewportPos(const QPointF &pos)
PickResultList syncPickAll(const QSSGRenderRay &ray)
static QSSGRenderLayer::TonemapMode getTonemapMode(const QQuick3DSceneEnvironment &environment)
void setGlobalPickingEnabled(bool isEnabled)
QQuick3DRenderStats * renderStats()
std::optional< QSSGRenderPickResult > syncPickClosestPoint(const QVector3D &center, float radiusSquared, QSSGRenderNode *node)
QList< const QSSGRenderNode * > syncPickInFrustum(const QSSGFrustum &frustum)
PickResultList syncPickOne(const QSSGRenderRay &ray, QSSGRenderNode *node)
QQuick3DSceneRenderer * renderer
QSGTexture * texture() const override
Returns a pointer to the texture object.
void preprocess() override
Override this function to do processing on the node before it is rendered.
Combined button and popup list for selecting options.
Q_TRACE_POINT(qtcore, QCoreApplication_postEvent_exit)
Q_TRACE_POINT(qtcore, QFactoryLoader_update, const QString &fileName)
Q_TRACE_POINT(qtquick3d, QSSG_renderFrame_entry, int width, int height)
static void bfs(In *inExtension, QList< Out * > &outList)
static const QVector2D s_ProgressiveAABlendFactors[QSSGLayerRenderData::MAX_AA_LEVELS]
static QVector3D tonemapRgb(const QVector3D &c, QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes tonemapMode)
static bool dumpRenderTimes()
Q_TRACE_POINT(qtquick3d, QSSG_synchronize_entry, QQuick3DViewport *view3D, const QSize &size, float dpr)
static const QVector2D s_TemporalAABlendFactors
static void requestFullUpdate(QQuickWindow *window)