Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qssgrenderer_p.h
Go to the documentation of this file.
1// Copyright (C) 2008-2012 NVIDIA Corporation.
2// Copyright (C) 2019 The Qt Company Ltd.
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
4
5#ifndef QSSG_RENDERER_H
6#define QSSG_RENDERER_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQuick3DRuntimeRender/private/qssgrenderableobjects_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrendermesh_p.h>
21#include <QtQuick3DRuntimeRender/private/qssgrendermodel_p.h>
22#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterial_p.h>
23#include <QtQuick3DRuntimeRender/private/qssgrenderlayer_p.h>
24#include <QtQuick3DRuntimeRender/private/qssgrenderray_p.h>
25#include <QtQuick3DRuntimeRender/private/qssgrendercamera_p.h>
26#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
27#include <QtQuick3DRuntimeRender/private/qssgrenderclippingfrustum_p.h>
28#include <QtQuick3DRuntimeRender/private/qssgrendershaderkeys_p.h>
29#include <QtQuick3DRuntimeRender/private/qssgrendershadercache_p.h>
30#include <QtQuick3DRuntimeRender/private/qssgrenderdefaultmaterialshadergenerator_p.h>
31#include <QtQuick3DRuntimeRender/private/qssgrenderbuffermanager_p.h>
32#include <QtQuick3DRuntimeRender/private/qssgrenderpickresult_p.h>
33#include <QtQuick3DRuntimeRender/private/qssgshadermapkey_p.h>
34#include <QtQuick3DRuntimeRender/private/qssgrenderpass_p.h>
35
36#include <QtQuick3DUtils/private/qssgbounds3_p.h>
37#include <QtQuick3DUtils/private/qssgdataref_p.h>
38
40
43struct QSSGRenderItem2D;
45
46class Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderer
47{
48 Q_DISABLE_COPY(QSSGRenderer)
49 using PickResultList = QVarLengthArray<QSSGRenderPickResult, 20>; // Lets assume most items are filtered out already
50public:
53
55 {
56 return m_defaultMaterialShaderKeyProperties;
57 }
58
59 void setRenderContextInterface(QSSGRenderContextInterface *ctx);
60
61 // Returns true if this layer or a sibling was dirty.
62 bool prepareLayerForRender(QSSGRenderLayer &inLayer);
63
64 void rhiPrepare(QSSGRenderLayer &inLayer);
65 void rhiRender(QSSGRenderLayer &inLayer);
66
67 void cleanupResources(QList<QSSGRenderGraphObject*> &resources);
68 void cleanupResources(QSet<QSSGRenderGraphObject*> &resources);
69
70 QSSGLayerRenderData *getOrCreateLayerRenderData(QSSGRenderLayer &layer);
71
72 // The QSSGRenderContextInterface calls these, clients should not.
73 void beginFrame(QSSGRenderLayer *layer);
74 void endFrame(QSSGRenderLayer *layer);
75
76 PickResultList syncPickAll(const QSSGRenderLayer &layer,
77 QSSGBufferManager &bufferManager,
78 const QSSGRenderRay &ray);
79
81 QSSGBufferManager &bufferManager,
82 const QSSGRenderRay &ray,
83 QSSGRenderNode *target = nullptr);
84
85 // Setting this true enables picking for all the models, regardless of
86 // the models pickable property.
87 bool isGlobalPickingEnabled() const;
88 void setGlobalPickingEnabled(bool isEnabled);
89
90 QSSGRhiQuadRenderer *rhiQuadRenderer();
91 QSSGRhiCubeRenderer *rhiCubeRenderer();
92
93 // Callback during the layer render process.
94 void beginLayerRender(QSSGLayerRenderData &inLayer);
95 void endLayerRender();
96 void addMaterialDirtyClear(QSSGRenderGraphObject *material);
97
98 static QSSGRhiShaderPipelinePtr generateRhiShaderPipelineImpl(QSSGSubsetRenderable &renderable, QSSGShaderLibraryManager &shaderLibraryManager,
99 QSSGShaderCache &shaderCache,
100 QSSGProgramGenerator &shaderProgramGenerator,
101 QSSGShaderDefaultMaterialKeyProperties &shaderKeyProperties,
102 const QSSGShaderFeatures &featureSet,
103 QByteArray &shaderString);
104
105 QSSGRhiShaderPipelinePtr getShaderPipelineForDefaultMaterial(QSSGSubsetRenderable &inRenderable,
106 const QSSGShaderFeatures &inFeatureSet);
107
108 QSSGLayerGlobalRenderProperties getLayerGlobalRenderProperties();
109
110 QSSGRenderContextInterface *contextInterface() const { return m_contextInterface; }
111
112 // Returns true if the renderer expects new frame to be rendered
113 // Happens when progressive AA is enabled
114 bool rendererRequestsFrames() const;
115
117 Default,
118 Uv,
119 UvTangent
120 };
121
122 // shader implementations, RHI, implemented in qssgrendererimplshaders_rhi.cpp
123 QSSGRhiShaderPipelinePtr getRhiCubemapShadowBlurXShader();
124 QSSGRhiShaderPipelinePtr getRhiCubemapShadowBlurYShader();
125 QSSGRhiShaderPipelinePtr getRhiGridShader();
126 QSSGRhiShaderPipelinePtr getRhiOrthographicShadowBlurXShader();
127 QSSGRhiShaderPipelinePtr getRhiOrthographicShadowBlurYShader();
128 QSSGRhiShaderPipelinePtr getRhiSsaoShader();
129 QSSGRhiShaderPipelinePtr getRhiSkyBoxCubeShader();
130 QSSGRhiShaderPipelinePtr getRhiSkyBoxShader(QSSGRenderLayer::TonemapMode tonemapMode, bool isRGBE);
131 QSSGRhiShaderPipelinePtr getRhiSupersampleResolveShader();
132 QSSGRhiShaderPipelinePtr getRhiProgressiveAAShader();
133 QSSGRhiShaderPipelinePtr getRhiTexturedQuadShader();
134 QSSGRhiShaderPipelinePtr getRhiParticleShader(QSSGRenderParticles::FeatureLevel featureLevel);
135 QSSGRhiShaderPipelinePtr getRhiSimpleQuadShader();
136 QSSGRhiShaderPipelinePtr getRhiLightmapUVRasterizationShader(LightmapUVRasterizationShaderMode mode);
137 QSSGRhiShaderPipelinePtr getRhiLightmapDilateShader();
138 QSSGRhiShaderPipelinePtr getRhiDebugObjectShader();
139
140 static void setTonemapFeatures(QSSGShaderFeatures &features, QSSGRenderLayer::TonemapMode tonemapMode);
141
142protected:
143 static void getLayerHitObjectList(const QSSGRenderLayer &layer,
144 QSSGBufferManager &bufferManager,
145 const QSSGRenderRay &ray,
146 bool inPickEverything,
147 PickResultList &outIntersectionResult);
148 static void intersectRayWithSubsetRenderable(QSSGBufferManager &bufferManager,
149 const QSSGRenderRay &inRay,
150 const QSSGRenderNode &node,
151 PickResultList &outIntersectionResultList);
152 static void intersectRayWithItem2D(const QSSGRenderRay &inRay, const QSSGRenderItem2D &item2D, PickResultList &outIntersectionResultList);
153
154private:
157
158 void releaseCachedResources();
159 QSSGRhiShaderPipelinePtr getBuiltinRhiShader(const QByteArray &name,
161 QSSGRhiShaderPipelinePtr generateRhiShaderPipeline(QSSGSubsetRenderable &inRenderable, const QSSGShaderFeatures &inFeatureSet);
162
163 QSSGRenderContextInterface *m_contextInterface = nullptr; // We're own by the context interface
164
165 // The shader refs are non-null if we have attempted to generate the
166 // shader. This does not mean we were successul, however.
167
168 // RHI
169 QSSGRhiShaderPipelinePtr m_cubemapShadowBlurXRhiShader;
170 QSSGRhiShaderPipelinePtr m_cubemapShadowBlurYRhiShader;
171 QSSGRhiShaderPipelinePtr m_gridShader;
172 QSSGRhiShaderPipelinePtr m_orthographicShadowBlurXRhiShader;
173 QSSGRhiShaderPipelinePtr m_orthographicShadowBlurYRhiShader;
174 QSSGRhiShaderPipelinePtr m_ssaoRhiShader;
175 QSSGRhiShaderPipelinePtr m_skyBoxRhiShader;
176 QSSGRhiShaderPipelinePtr m_skyBoxCubeRhiShader;
177 QSSGRhiShaderPipelinePtr m_supersampleResolveRhiShader;
178 QSSGRhiShaderPipelinePtr m_progressiveAARhiShader;
179 QSSGRhiShaderPipelinePtr m_texturedQuadRhiShader;
180 QSSGRhiShaderPipelinePtr m_simpleQuadRhiShader;
181 QSSGRhiShaderPipelinePtr m_lightmapUVRasterShader;
182 QSSGRhiShaderPipelinePtr m_lightmapUVRasterShader_uv;
183 QSSGRhiShaderPipelinePtr m_lightmapUVRasterShader_uv_tangent;
184 QSSGRhiShaderPipelinePtr m_lightmapDilateShader;
185 QSSGRhiShaderPipelinePtr m_debugObjectShader;
186
187 QSSGRhiShaderPipelinePtr m_particlesNoLightingSimpleRhiShader;
188 QSSGRhiShaderPipelinePtr m_particlesNoLightingMappedRhiShader;
189 QSSGRhiShaderPipelinePtr m_particlesNoLightingAnimatedRhiShader;
190 QSSGRhiShaderPipelinePtr m_particlesVLightingSimpleRhiShader;
191 QSSGRhiShaderPipelinePtr m_particlesVLightingMappedRhiShader;
192 QSSGRhiShaderPipelinePtr m_particlesVLightingAnimatedRhiShader;
193 QSSGRhiShaderPipelinePtr m_lineParticlesRhiShader;
194 QSSGRhiShaderPipelinePtr m_lineParticlesMappedRhiShader;
195 QSSGRhiShaderPipelinePtr m_lineParticlesAnimatedRhiShader;
196 QSSGRhiShaderPipelinePtr m_lineParticlesVLightRhiShader;
197 QSSGRhiShaderPipelinePtr m_lineParticlesMappedVLightRhiShader;
198 QSSGRhiShaderPipelinePtr m_lineParticlesAnimatedVLightRhiShader;
199
200 bool m_globalPickingEnabled = false;
201
202 // Temporary information stored only when rendering a particular layer.
203 QSSGLayerRenderData *m_currentLayer = nullptr;
204 QMatrix4x4 m_viewProjection;
205 QByteArray m_generatedShaderString;
206
207 bool m_progressiveAARenderRequest = false;
208 QSSGShaderDefaultMaterialKeyProperties m_defaultMaterialShaderKeyProperties;
209
210 QSet<QSSGRenderGraphObject *> m_materialClearDirty;
211
212 QSSGRhiQuadRenderer *m_rhiQuadRenderer = nullptr;
213 QSSGRhiCubeRenderer *m_rhiCubeRenderer = nullptr;
214
216
217 // Skybox shader state
219 bool m_isSkyboxRGBE = false;
220};
221
223{
224
225std::pair<QSSGBoxPoints, QSSGBoxPoints> calculateSortedObjectBounds(const QVector<QSSGRenderableObjectHandle> &sortedOpaqueObjects,
226 const QVector<QSSGRenderableObjectHandle> &sortedTransparentObjects);
227
228void rhiRenderShadowMap(QSSGRhiContext *rhiCtx, QSSGPassKey passKey,
230 QSSGRenderShadowMap &shadowMapManager,
232 const QSSGShaderLightList &globalLights,
233 const QVector<QSSGRenderableObjectHandle> &sortedOpaqueObjects,
235 const QSSGBoxPoints &castingObjectsBox,
236 const QSSGBoxPoints &receivingObjectsBox);
237
239 QSSGPassKey passKey,
241 QSSGRenderReflectionMap &reflectionMapManager,
242 const QVector<QSSGRenderReflectionProbe *> &reflectionProbes,
243 const QVector<QSSGRenderableObjectHandle> &reflectionPassObjects,
245
247 const QSSGRhiGraphicsPipelineState &basePipelineState,
249 QSSGLayerRenderData &inData,
250 const QVector<QSSGRenderableObjectHandle> &sortedOpaqueObjects,
251 const QVector<QSSGRenderableObjectHandle> &sortedTransparentObjects,
253 int samples);
254
256 const QVector<QSSGRenderableObjectHandle> &sortedOpaqueObjects,
257 const QVector<QSSGRenderableObjectHandle> &sortedTransparentObjects,
258 bool *needsSetViewport);
259
260bool rhiPrepareAoTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex);
261
264 const QSSGRenderCamera &camera);
265
266bool rhiPrepareScreenTexture(QSSGRhiContext *rhiCtx, const QSize &size, bool wantsMips, QSSGRhiRenderableTexture *renderableTex);
267
270
271
272void rhiPrepareSkyBox(QSSGRhiContext *rhiCtx, QSSGPassKey passKey,
274 QSSGRenderCamera &inCamera,
276
279 QSSGRenderCamera &inCamera,
282 int cubeFace);
283
284Q_QUICK3DRUNTIMERENDER_EXPORT void rhiPrepareRenderable(QSSGRhiContext *rhiCtx, QSSGPassKey passKey,
285 const QSSGLayerRenderData &inData,
286 QSSGRenderableObject &inObject,
287 QRhiRenderPassDescriptor *renderPassDescriptor,
289 QSSGShaderFeatures featureSet,
290 int samples,
291 QSSGRenderCamera *inCamera = nullptr,
292 QMatrix4x4 *alteredModelViewProjection = nullptr,
293 int cubeFace = -1,
294 QSSGReflectionMapEntry *entry = nullptr);
295
296Q_QUICK3DRUNTIMERENDER_EXPORT void rhiRenderRenderable(QSSGRhiContext *rhiCtx,
298 QSSGRenderableObject &object,
299 bool *needsSetViewport,
300 int cubeFace = -1);
301
302bool rhiPrepareDepthTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex);
303
304inline QRect correctViewportCoordinates(const QRectF &layerViewport, const QRect &deviceRect)
305{
306 const int y = deviceRect.bottom() - layerViewport.bottom() + 1;
307 return QRect(layerViewport.x(), y, layerViewport.width(), layerViewport.height());
308}
309}
310
312
313#endif
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore
Definition qhash.h:818
Definition qlist.h:74
The QMatrix4x4 class represents a 4x4 transformation matrix in 3D space.
Definition qmatrix4x4.h:25
\inmodule QtCore\reentrant
Definition qrect.h:483
constexpr qreal bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:499
constexpr qreal height() const noexcept
Returns the height of the rectangle.
Definition qrect.h:718
constexpr qreal width() const noexcept
Returns the width of the rectangle.
Definition qrect.h:715
constexpr qreal x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:655
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr int bottom() const noexcept
Returns the y-coordinate of the rectangle's bottom edge.
Definition qrect.h:181
\inmodule QtGui
Definition qrhi.h:1119
QSSGShaderDefaultMaterialKeyProperties & defaultMaterialShaderKeyProperties()
QSSGRenderContextInterface * contextInterface() const
Definition qset.h:18
\inmodule QtCore
Definition qsize.h:25
EGLContext ctx
QCamera * camera
Definition camera.cpp:19
else opt state
[0]
Combined button and popup list for selecting options.
void rhiRenderDepthPass(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &ps, const QVector< QSSGRenderableObjectHandle > &sortedOpaqueObjects, const QVector< QSSGRenderableObjectHandle > &sortedTransparentObjects, bool *needsSetViewport)
Q_QUICK3DRUNTIMERENDER_EXPORT void rhiRenderRenderable(QSSGRhiContext *rhiCtx, const QSSGRhiGraphicsPipelineState &state, QSSGRenderableObject &object, bool *needsSetViewport, int cubeFace=-1)
bool rhiPrepareScreenTexture(QSSGRhiContext *rhiCtx, const QSize &size, bool wantsMips, QSSGRhiRenderableTexture *renderableTex)
void rhiRenderShadowMap(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, QSSGRhiGraphicsPipelineState &ps, QSSGRenderShadowMap &shadowMapManager, const QSSGRenderCamera &camera, const QSSGShaderLightList &globalLights, const QVector< QSSGRenderableObjectHandle > &sortedOpaqueObjects, QSSGRenderer &renderer, const QSSGBoxPoints &castingObjectsBox, const QSSGBoxPoints &receivingObjectsBox)
void rhiRenderReflectionMap(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGLayerRenderData &inData, QSSGRhiGraphicsPipelineState *ps, QSSGRenderReflectionMap &reflectionMapManager, const QVector< QSSGRenderReflectionProbe * > &reflectionProbes, const QVector< QSSGRenderableObjectHandle > &reflectionPassObjects, QSSGRenderer &renderer)
bool rhiPrepareAoTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex)
void rhiPrepareSkyBoxForReflectionMap(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, QSSGRenderLayer &layer, QSSGRenderCamera &inCamera, QSSGRenderer &renderer, QSSGReflectionMapEntry *entry, int cubeFace)
Q_QUICK3DRUNTIMERENDER_EXPORT void rhiPrepareRenderable(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGLayerRenderData &inData, QSSGRenderableObject &inObject, QRhiRenderPassDescriptor *renderPassDescriptor, QSSGRhiGraphicsPipelineState *ps, QSSGShaderFeatures featureSet, int samples, QSSGRenderCamera *inCamera=nullptr, QMatrix4x4 *alteredModelViewProjection=nullptr, int cubeFace=-1, QSSGReflectionMapEntry *entry=nullptr)
bool rhiPrepareDepthTexture(QSSGRhiContext *rhiCtx, const QSize &size, QSSGRhiRenderableTexture *renderableTex)
void rhiRenderAoTexture(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, QSSGRenderer &renderer, QSSGRhiShaderPipeline &shaderPipeline, QSSGRhiGraphicsPipelineState &ps, const SSAOMapPass::AmbientOcclusion &ao, const QSSGRhiRenderableTexture &rhiAoTexture, const QSSGRhiRenderableTexture &rhiDepthTexture, const QSSGRenderCamera &camera)
std::pair< QSSGBoxPoints, QSSGBoxPoints > calculateSortedObjectBounds(const QVector< QSSGRenderableObjectHandle > &sortedOpaqueObjects, const QVector< QSSGRenderableObjectHandle > &sortedTransparentObjects)
void rhiPrepareSkyBox(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, QSSGRenderLayer &layer, QSSGRenderCamera &inCamera, QSSGRenderer &renderer)
QRect correctViewportCoordinates(const QRectF &layerViewport, const QRect &deviceRect)
bool rhiPrepareDepthPass(QSSGRhiContext *rhiCtx, QSSGPassKey passKey, const QSSGRhiGraphicsPipelineState &basePipelineState, QRhiRenderPassDescriptor *rpDesc, QSSGLayerRenderData &inData, const QVector< QSSGRenderableObjectHandle > &sortedOpaqueObjects, const QVector< QSSGRenderableObjectHandle > &sortedTransparentObjects, QSSGRhiDrawCallDataKey::Selector ubufSel, int samples)
void rhiPrepareGrid(QSSGRhiContext *rhiCtx, QSSGRenderLayer &layer, QSSGRenderCamera &inCamera, QSSGRenderer &renderer)
EGLOutputLayerEXT layer
GLsizei samples
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum target
GLuint name
GLint y
GLuint entry
static QT_BEGIN_NAMESPACE const uint Default
Definition qsplitter_p.h:25
std::array< QVector3D, 8 > QSSGBoxPoints
std::shared_ptr< QSSGRhiShaderPipeline > QSSGRhiShaderPipelinePtr
const void * QSSGPassKey
QStorageInfo storage
[1]
QSvgRenderer * renderer
[0]