7#ifndef QSSG_RENDERER_P_H
8#define QSSG_RENDERER_P_H
21#include <private/qssgrenderpickresult_p.h>
22#include <private/qssgrhicontext_p.h>
23#include <private/qssgrhiquadrenderer_p.h>
25#include <QtCore/qpointer.h>
32class QSSGProgramGenerator;
33class QSSGShaderLibraryManager;
34class QSSGBufferManager;
38struct QSSGRenderItem2D;
40class QSSGSubsetRenderable;
42struct QSSGShaderFeatures;
44class QSGRenderContext;
50 Q_DISABLE_COPY(QSSGRenderer)
56 bool prepareLayerForRender(QSSGRenderLayer &inLayer);
58 void rhiPrepare(QSSGRenderLayer &inLayer);
59 void rhiRender(QSSGRenderLayer &inLayer);
63 void beginFrame(QSSGRenderLayer &layer,
bool allowRecursion =
true);
68 bool endFrame(QSSGRenderLayer &layer,
bool allowRecursion =
true);
73 void setViewport(QRect inViewport) { m_viewport = inViewport; }
76 void setDpr(
float dpr) { m_dpr = dpr; }
77 float dpr()
const {
return m_dpr; }
99 void cleanupResources(QList<QSSGRenderGraphObject*> &resources);
103 friend class QSSGRendererPrivate;
113 void endLayerRender();
114 void addMaterialDirtyClear(QSSGRenderGraphObject *material);
115 void cleanupUnreferencedBuffers(QSSGRenderLayer *inLayer);
116 void resetResourceCounters(QSSGRenderLayer *inLayer);
117 void releaseCachedResources();
124 bool m_globalPickingEnabled =
false;
129 QSet<QSSGRenderGraphObject *> m_materialClearDirty;
131 QPointer<QSGRenderContext> m_qsgRenderContext;
135 std::vector<QSSGRenderItem2DData *> m_item2DDatas;
137 mutable std::unique_ptr<QSSGRhiQuadRenderer> m_rhiQuadRenderer;
138 mutable std::unique_ptr<QSSGRhiCubeRenderer> m_rhiCubeRenderer;
140 quint32 m_activeFrameRef = 0;
141 quint32 m_frameCount = 0;
151 QSSGRendererPrivate() =
default;
153 using PickResultList = QVarLengthArray<QSSGRenderPickResult, 20>;
155 static QSSGRhiShaderPipelinePtr generateRhiShaderPipelineImpl(QSSGSubsetRenderable &renderable,
156 QSSGShaderLibraryManager &shaderLibraryManager,
157 QSSGShaderCache &shaderCache,
158 QSSGProgramGenerator &shaderProgramGenerator,
159 const QSSGShaderDefaultMaterialKeyProperties &shaderKeyProperties,
160 const QSSGShaderFeatures &featureSet,
161 const QSSGUserShaderAugmentation &shaderAugmentation,
162 QByteArray &shaderString);
163 static QSSGRhiShaderPipelinePtr generateRhiShaderPipeline(QSSGRenderer &renderer,
164 QSSGSubsetRenderable &inRenderable,
165 const QSSGShaderFeatures &inFeatureSet,
166 const QSSGUserShaderAugmentation &shaderAugmentation);
168 static QSSGRhiShaderPipelinePtr getShaderPipelineForDefaultMaterial(QSSGRenderer &renderer,
169 QSSGSubsetRenderable &inRenderable,
170 const QSSGShaderFeatures &inFeatureSet,
171 const QSSGUserShaderAugmentation &shaderAugmentation);
173 static void getLayerHitObjectList(
const QSSGRenderLayer &layer,
174 QSSGBufferManager &bufferManager,
175 const QSSGRenderRay &ray,
176 bool inPickEverything,
177 PickResultList &outIntersectionResult);
178 static void intersectRayWithSubsetRenderable(
const QSSGRenderLayer &layer, QSSGBufferManager &bufferManager,
179 const QSSGRenderRay &inRay,
180 const QSSGRenderNode &node,
181 PickResultList &outIntersectionResultList);
182 static void intersectRayWithItem2D(
const QSSGRenderLayer &layer,
const QSSGRenderRay &inRay,
183 const QSSGRenderItem2D &item2D,
184 PickResultList &outIntersectionResultList);
186 static std::optional<QSSGRenderPickResult> closestPointOnSubsetRenderable(
const QSSGRenderLayer &layer,
187 QSSGBufferManager &bufferManager,
188 const QVector3D ¢er,
190 const QSSGRenderNode &node);
192 static PickResultList syncPickAll(
const QSSGRenderContextInterface &ctx,
193 const QSSGRenderLayer &layer,
194 const QSSGRenderRay &ray);
196 static PickResultList syncPick(
const QSSGRenderContextInterface &ctx,
197 const QSSGRenderLayer &layer,
198 const QSSGRenderRay &ray,
199 QSSGRenderNode *target =
nullptr);
201 static PickResultList syncPickSubset(
const QSSGRenderLayer &layer,
202 QSSGBufferManager &bufferManager,
203 const QSSGRenderRay &ray,
204 QVarLengthArray<QSSGRenderNode *> subset);
206 static std::optional<QSSGRenderPickResult> syncPickClosestPoint(
const QSSGRenderContextInterface &ctx,
207 const QSSGRenderLayer &layer,
208 const QVector3D ¢er,
209 const float radiusSquared,
210 QSSGRenderNode *target =
nullptr);
212 static QList<
const QSSGRenderNode *> syncPickInFrustum(
const QSSGRenderContextInterface &ctx,
213 const QSSGRenderLayer &layer,
214 const QSSGFrustum &frustum);
218 static bool isGlobalPickingEnabled(
const QSSGRenderer &renderer) {
return renderer.m_globalPickingEnabled; }
219 static void setGlobalPickingEnabled(QSSGRenderer &renderer,
bool isEnabled);
221 static void setRenderContextInterface(QSSGRenderer &renderer, QSSGRenderContextInterface *ctx);
222 static void setSgRenderContext(QSSGRenderer &renderer, QSGRenderContext *sgRenderCtx);
224 static QSSGLayerRenderData *getCurrentRenderData(
const QSSGRenderer &renderer) {
return renderer.m_currentLayer; }
226 static QSGRenderContext *getSgRenderContext(
const QSSGRenderer &renderer);
228 static constexpr float minimumRenderOpacity = .01f;
QSSGRhiShaderPipelinePtr debugObjectShader
QSSGRhiGraphicsPipelineState ps
Type passType() const final
void resetForFrame() final
QSSGRhiGraphicsPipelineState ps
QSSGRhiShaderPipelinePtr gridShader
void resetForFrame() final
Type passType() const final
Type passType() const final
std::vector< QSGRenderer * > prepdItem2DRenderers
void resetForFrame() final
static constexpr int MaxBuckets
QSSGRhiGraphicsPipelineState ps
QSSGRenderMotionVectorMapPtr motionVectorMapManager
QSSGRenderableObjectList motionVectorPassObjects[MaxBuckets]
Type passType() const final
QSSGRhiRenderableTexture * rhiMotionVectorTexture
QSSGRenderCamera * camera
void resetForFrame() final
QSSGShaderFeatures shaderFeatures
QSSGRhiRenderableTexture * rhiABufferImage
QSSGRhiRenderableTexture * rhiAccumTexture
QRhiShaderResourceBindings * compositeSrb
QSSGRhiShaderPipelinePtr compositeShaderPipeline
QRhiBuffer * rhiAuxBuffer
QSSGRhiRenderableTexture * rhiAuxiliaryImage
QSSGRenderLayer::OITMethod method
void resetForFrame() final
Type passType() const final
QSSGRhiRenderableTexture * rhiRevealageTexture
QSSGRhiGraphicsPipelineState ps
void setMethod(QSSGRenderLayer::OITMethod m)
QSSGRhiRenderableTexture * rhiRevealageTexture
QRhiResourceUpdateBatch * rub
void setMethod(QSSGRenderLayer::OITMethod m)
QSSGRhiRenderableTexture * rhiABufferImage
QList< QRhiReadbackResult * > results
quint32 reportedNodeCount
QSSGShaderFeatures shaderFeatures
QSSGRenderLayer::OITMethod method
QRhiShaderResourceBindings * clearSrb
QSSGRenderableObjectList sortedTransparentObjects
QSSGRhiRenderableTexture * rhiAuxiliaryImage
QSSGRhiRenderableTexture * rhiCounterImage
QRhiTextureRenderTarget * renderTarget
QRhiBuffer * rhiAuxBuffer
void resetForFrame() final
QSSGRhiShaderPipelinePtr clearPipeline
QSSGRhiRenderableTexture * rhiDepthTexture
QSSGRhiGraphicsPipelineState ps
QRhiTexture * readbackImage
Type passType() const final
QRhiBuffer * rhiCounterBuffer
QSSGRhiRenderableTexture * rhiAccumTexture
static void prep(const QSSGRenderContextInterface &ctx, QSSGLayerRenderData &data, QSSGPassKey passKey, QSSGRhiGraphicsPipelineState &ps, QSSGShaderFeatures shaderFeatures, QRhiRenderPassDescriptor *rpDesc, const QSSGRenderableObjectList &sortedOpaqueObjects)
void resetForFrame() final
Type passType() const final
QSSGShaderFeatures shaderFeatures
QSSGRhiGraphicsPipelineState ps
static void render(const QSSGRenderContextInterface &ctx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedOpaqueObjects)
QSSGRenderableObjectList sortedOpaqueObjects
QRect viewport() const
Returns the viewport rectangle.
bool isLayerVisible() const
QSSGLayerRenderPreparationResult(const QRectF &inViewport, QSSGRenderLayer &inLayer)
QSize textureDimensions() const
void setState(State state)
QRectF getViewport() const
QSSGRenderLayer * getLayer() const
const QSSGLayerRenderPreparationResultFlags & getFlags() const
QSSGLayerRenderPreparationResult()=default
friend class QSSGLayerRenderData
friend class QSSGRenderer
friend class QQuick3DWindowAttachment
virtual ~QSSGRenderPass()
virtual void resetForFrame()=0
virtual Type passType() const =0
friend class QSSGParticleRenderer
void releaseItem2DData(const QSSGRenderItem2D &item2D)
const std::unique_ptr< QSSGRhiQuadRenderer > & rhiQuadRenderer() const
quint32 frameDepth() const
friend class QSSGRenderContextInterface
QRect scissorRect() const
void cleanupResources(QSet< QSSGRenderGraphObject * > &resources)
void setViewport(QRect inViewport)
void beginSubLayerRender(QSSGLayerRenderData &inLayer)
const std::unique_ptr< QSSGRhiCubeRenderer > & rhiCubeRenderer() const
void setScissorRect(QRect inScissorRect)
void endSubLayerRender(QSSGLayerRenderData &inLayer)
QSSGRenderContextInterface * contextInterface() const
void resetForFrame() final
std::shared_ptr< QSSGRenderReflectionMap > reflectionMapManager
QSSGRenderableObjectList reflectionPassObjects
QSSGRhiGraphicsPipelineState ps
QList< QSSGRenderReflectionProbe * > reflectionProbes
Type passType() const final
Type passType() const final
QSSGRhiRenderableTexture * rhiAoTexture
const QSSGRhiRenderableTexture * rhiDepthTexture
void resetForFrame() final
QSSGRhiShaderPipelinePtr ssaoShaderPipeline
QSSGAmbientOcclusionSettings aoSettings
const QSSGRenderCamera * camera
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
QSSGRhiGraphicsPipelineState ps
Type passType() const final
std::optional< SkyboxPass > skyboxPass
QSSGShaderFeatures shaderFeatures
QSSGRenderableObjectList sortedOpaqueObjects
std::optional< SkyboxCubeMapPass > skyboxCubeMapPass
QSSGRhiRenderableTexture * rhiScreenTexture
QSSGRenderableObjectList sortedScreenTextureObjects
const QSSGRhiRenderableTexture * rhiScreenTexture
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
Type passType() const final
QSSGRenderCamera * camera
QSSGBounds3 castingObjectsBox
QSSGShaderLightList globalLights
QSSGRenderableObjectList shadowPassObjects
QSSGRhiGraphicsPipelineState ps
QSSGBounds3 receivingObjectsBox
void resetForFrame() final
std::unique_ptr< QSSGRenderCamera > debugCamera
Type passType() const final
std::shared_ptr< QSSGRenderShadowMap > shadowMapManager
QRhiRenderPassDescriptor * rpDesc
QSSGRhiShaderPipelinePtr skyBoxCubeShader
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
Type passType() const final
void resetForFrame() final
QRhiRenderPassDescriptor * rpDesc
Type passType() const final
QSSGRhiGraphicsPipelineState ps
static void prep(const QSSGRenderContextInterface &ctx, QSSGLayerRenderData &data, QSSGPassKey passKey, QSSGRhiGraphicsPipelineState &ps, QSSGShaderFeatures shaderFeatures, QRhiRenderPassDescriptor *rpDesc, const QSSGRenderableObjectList &sortedTransparentObjects, bool oit=false)
QSSGRenderableObjectList sortedTransparentObjects
static void render(const QSSGRenderContextInterface &ctx, const QSSGRhiGraphicsPipelineState &ps, const QSSGRenderableObjectList &sortedTransparentObjects)
QSSGShaderFeatures shaderFeatures
QSSGRhiGraphicsPipelineState ps
void resetForFrame() final
Type passType() const final
Type passType() const final
QList< QSSGRenderExtension * > extensions
void resetForFrame() final
void resetForFrame() final
static constexpr size_t MAX_SUBPASS_DEPTH
QList< QSSGRenderUserPass * > userPasses
std::vector< UserPassData > userPassData
Type passType() const final
std::set< QSSGResourceId > visitedPasses
void resetForFrame() final
QSSGRenderableObjectList renderedOpaqueDepthPrepassObjects
Type passType() const final
QSSGRhiGraphicsPipelineState ps
QSSGRenderableObjectList renderedDepthWriteObjects
QSSGRenderResult::Key toInternalRenderResultKey(QSSGFrameData::RenderResult id)
Combined button and popup list for selecting options.
QSSGLayerRenderPreparationResultFlag
@ RequiresMotionVectorPass
@ MaterialHasCustomBlendMode
@ RequiresMipmapsForScreenTexture
static const char * effect_fragment_main_with_tonemapping
static const char * effect_vertex_main_post
static const char * effect_vertex_main_pre
static const char * effect_vertex_main_position
static const char * effect_fragment_main
QVector< QSSGRenderableObjectHandle > renderables
QSSGBakedLightingModel(const QSSGRenderModel *model, const QVector< QSSGRenderableObjectHandle > &renderables)
const QSSGRenderModel * model
QSSGDefaultMaterialPreparationResult(QSSGShaderDefaultMaterialKey inMaterialKey)
QSSGRenderableImage * firstImage
QSSGRenderableObjectFlags renderableFlags
QSSGShaderDefaultMaterialKey materialKey
bool requiresDepthTextureMS() const
void setRequiresSsaoPass(bool inValue)
void setRequiresMotionVectorPass(bool inValue)
void setRequiresScreenTexture(bool inValue)
bool wasLayerDataDirty() const
void setRequiresDepthTextureMS(bool inValue)
bool requiresDepthTexture() const
void setLayerDataDirty(bool inValue)
void setWasDirty(bool inValue)
bool requiresMipmapsForScreenTexture() const
bool requiresScreenTexture() const
bool hasCustomBlendMode() const
void setRequiresNormalTexture(bool inValue)
bool requiresMotionVectorPass() const
bool requiresShadowMapPass() const
void setRequiresMipmapsForScreenTexture(bool inValue)
void setRequiresDepthTexture(bool inValue)
bool requiresSsaoPass() const
void setRequiresShadowMapPass(bool inValue)
void setHasCustomBlendMode(bool inValue)
bool requiresNormalTexture() const
QRhiBuffer * counterBuffer
QRhiTextureRenderTarget * oitRenderTarget
QRhiTexture * copyTexture
QRhiRenderPassDescriptor * renderPassDescriptor
QSSGRhiRenderableTextureV2Ptr renderableTexture
std::optional< SkyboxCubeMapPass > skyboxCubeMapPass
std::vector< UserPassData > subPassData
QSSGRhiGraphicsPipelineState ps
QSSGShaderDefineList shaderDefines
QRhiDepthStencilClearValue depthStencilClearValue
QSSGRenderableObjectList renderables
std::optional< SkyboxPass > skyboxPass
std::optional< Item2DPass > item2DPass