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
4#ifndef QSSGSCENERENDERER_H
5#define QSSGSCENERENDERER_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <ssg/qssgrendercontextcore.h>
19
20#include <qsgtextureprovider.h>
21#include <qsgrendernode.h>
22#include <QSGSimpleTextureNode>
23
24#include <QtQuick3D/private/qquick3dviewport_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgrenderlayer_p.h>
26#include <QtQuick3DRuntimeRender/private/qssgrhieffectsystem_p.h>
27#include <QtQuick3DRuntimeRender/private/qssgrenderer_p.h>
28
29#include <QtCore/qpointer.h>
30
31#include <optional>
32
34
36
37
38class QQuick3DSceneManager;
39class QQuick3DViewport;
40
42{
44public:
45 explicit QQuick3DSceneRenderer(const std::shared_ptr<QSSGRenderContextInterface> &rci);
47
48 static QSSGRenderLayer::TonemapMode getTonemapMode(const QQuick3DSceneEnvironment &environment)
49 {
50 if (environment.useBuiltinTonemapper())
51 return QSSGRenderLayer::TonemapMode(environment.tonemapMode());
52
53 // Special case for the extend scene environment...
54 return (environment.tonemapMode() != QQuick3DSceneEnvironment::QQuick3DEnvironmentTonemapModes::TonemapModeNone) ? QSSGRenderLayer::TonemapMode::Custom
55 : QSSGRenderLayer::TonemapMode::None;
56 }
57
58protected:
59 QRhiTexture *renderToRhiTexture(QQuickWindow *qw);
60 void beginFrame();
61 void endFrame();
62 void rhiPrepare(const QRect &viewport, qreal displayPixelRatio);
63 void rhiRender();
64 void synchronize(QQuick3DViewport *view3D, const QSize &size, float dpr);
66 QSize surfaceSize() const { return m_surfaceSize; }
68
69 std::optional<QSSGRenderRay> getRayFromViewportPos(const QPointF &pos);
70 PickResultList syncPick(const QSSGRenderRay &ray);
71 PickResultList syncPickOne(const QSSGRenderRay &ray, QSSGRenderNode *node);
72 PickResultList syncPickSubset(const QSSGRenderRay &ray, QVarLengthArray<QSSGRenderNode *> subset);
73 PickResultList syncPickAll(const QSSGRenderRay &ray);
74 std::optional<QSSGRenderPickResult> syncPickClosestPoint(const QVector3D &center, float radiusSquared, QSSGRenderNode *node);
75
76 void setGlobalPickingEnabled(bool isEnabled);
77
79
80private:
81 void releaseAaDependentRhiResources();
82 void updateLayerNode(QSSGRenderLayer &layerNode,
83 const QQuick3DViewport &view3D,
84 const QList<QSSGRenderGraphObject *> &resourceLoaders);
85 void addNodeToLayer(QSSGRenderNode *node);
86 void removeNodeFromLayer(QSSGRenderNode *node);
87 void maybeSetupLightmapBaking(QQuick3DViewport *view3D);
88 std::shared_ptr<QSSGRenderContextInterface> m_sgContext;
89 QSSGRenderLayer *m_layer = nullptr;
90 QPointer<QQuick3DWindowAttachment> winAttacment;
91 QSize m_surfaceSize;
92 SGFramebufferObjectNode *fboNode = nullptr;
93 bool m_aaIsDirty = true;
94 bool m_temporalIsDirty = false;
95 bool m_timeBasedAA = false;
96
97 // RHI
98 QRhiTexture *m_texture = nullptr;
99 // the rt is set up to output into m_texture or m_ssaaTexture or m_msaaRenderBuffer(+resolve into m_texture)
100 QRhiTextureRenderTarget *m_textureRenderTarget = nullptr;
101 QRhiRenderPassDescriptor *m_textureRenderPassDescriptor = nullptr;
102 // used by the draw quad that does m_ssaaTexture -> m_texture
103 QRhiTextureRenderTarget *m_ssaaTextureToTextureRenderTarget = nullptr;
104 QRhiRenderPassDescriptor *m_ssaaTextureToTextureRenderPassDescriptor = nullptr;
105 QRhiRenderBuffer *m_msaaRenderBufferLegacy = nullptr;
106 QRhiTexture *m_msaaRenderTexture = nullptr;
107 QRhiTexture *m_msaaMultiViewRenderBuffer = nullptr;
108 QRhiTexture *m_ssaaTexture = nullptr;
109 QRhiTexture *m_temporalAATexture = nullptr;
110 QRhiTexture *m_prevTempAATexture = nullptr;
111 QRhiTextureRenderTarget *m_temporalAARenderTarget = nullptr;
112 QRhiRenderPassDescriptor *m_temporalAARenderPassDescriptor = nullptr;
113 QRhiRenderBuffer *m_depthStencilBuffer = nullptr;
114 QRhiTexture *m_multiViewDepthStencilBuffer = nullptr;
115 bool m_textureNeedsFlip = true;
116 QSSGRenderLayer::Background m_backgroundMode = QSSGRenderLayer::Background::Unspecified;
117 QColor m_userBackgroundColor = Qt::black;
118 QColor m_linearBackgroundColor = Qt::black;
119 QColor m_tonemappedBackgroundColor = Qt::black;
120 int m_samples = 1;
121 QSSGRhiEffectSystem *m_effectSystem = nullptr;
122
123 QPointer<QQuick3DRenderStats> m_renderStats;
124
125 QSSGRenderNode *m_sceneRootNode = nullptr;
126 QSSGRenderNode *m_importSceneRootNode = nullptr;
127
128 bool m_prepared = false;
129
130 QSSGLightmapperOptions lmOptions;
131 bool m_lightmapBakingFromCmdRequested = false;
132 bool m_lightmapDenoisingFromCmdRequested = false;
133
134 int m_requestedFramesCount = 0;
135 bool m_postProcessingStack = false;
136 bool m_useFBO = false;
138
140 friend class QQuick3DSGRenderNode;
142 friend class QQuick3DViewport;
144 friend class QQuick3DRenderLayerHelpers;
145};
146
147class Q_QUICK3D_EXPORT QQuick3DRenderLayerHelpers
148{
149public:
150 static void updateLayerNodeHelper(const QQuick3DViewport &view3D,
151 const std::shared_ptr<QSSGRenderContextInterface> &rci,
152 QSSGRenderLayer &layerNode,
153 bool &aaIsDirty,
154 bool &temporalIsDirty);
155};
156
158{
160
161public:
164
165 void scheduleRender();
166
167 QSGTexture *texture() const override;
168
169 void preprocess() override;
170
171public Q_SLOTS:
172 void render();
173
174 void handleScreenChange();
175
176public:
179 QQuick3DViewport *quickFbo;
180
183
185};
186
187class QQuick3DSGRenderNode final : public QSGRenderNode
188{
189public:
191 void prepare() override;
192 StateFlags changedStates() const override;
193 void render(const RenderState *state) override;
195 RenderingFlags flags() const override;
196public:
199};
200
202{
204public:
209 QQuick3DSGDirectRenderer(QQuick3DSceneRenderer *renderer, QQuickWindow *window, QQuick3DSGDirectRendererMode mode = Underlay);
211
212 QQuick3DSceneRenderer *renderer() { return m_renderer; }
213 void setViewport(const QRectF &viewport);
214
215 void requestRender();
216 void setVisibility(bool visible);
217
218 void preSynchronize();
219
220private Q_SLOTS:
221 void prepare();
222 void render();
223
224private:
225 QQuick3DSceneRenderer *m_renderer = nullptr;
226 QQuickWindow *m_window = nullptr;
227 QRectF m_viewport;
228 bool m_isVisible = true;
229 QRhiTexture *m_rhiTexture = nullptr;
230 bool renderPending = false;
231};
232
233QT_END_NAMESPACE
234
235#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)
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)