QGIS API Documentation 3.43.0-Master (32433f7016e)
qgsframegraph.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsframegraph.h
3 --------------------------------------
4 Date : August 2020
5 Copyright : (C) 2020 by Belgacem Nedjima
6 Email : gb underscore nedjima at esi dot dz
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSFRAMEGRAPH_H
17#define QGSFRAMEGRAPH_H
18
19#include <map>
20#include <QWindow>
21#include <Qt3DRender/QCamera>
22#include <Qt3DRender/QRenderSurfaceSelector>
23#include <Qt3DRender/QViewport>
24#include <Qt3DRender/QCameraSelector>
25#include <Qt3DRender/QLayerFilter>
26#include <Qt3DRender/QLayer>
27#include <Qt3DRender/QRenderTargetSelector>
28#include <Qt3DRender/QRenderTarget>
29#include <Qt3DRender/QTexture>
30#include <Qt3DRender/QClearBuffers>
31#include <Qt3DRender/QParameter>
32#include <Qt3DRender/QFrustumCulling>
33#include <Qt3DRender/QRenderStateSet>
34#include <Qt3DRender/QDepthTest>
35#include <Qt3DRender/QCullFace>
36#include <Qt3DRender/QPolygonOffset>
37#include <Qt3DRender/QRenderCapture>
38#include <Qt3DRender/QDebugOverlay>
39
41
44class QgsRectangle;
47class QgsPreviewQuad;
54
55#define SIP_NO_FILE
56
67class QgsFrameGraph : public Qt3DCore::QEntity
68{
69 Q_OBJECT
70
71 public:
73 QgsFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
74
76 Qt3DRender::QFrameGraphNode *frameGraphRoot() { return mRenderSurfaceSelector; }
77
82 Qt3DRender::QTexture2D *blurredAmbientOcclusionFactorMap() { return mAmbientOcclusionBlurTexture; }
83
85 Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
86
88 Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
90 QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
91
93 Qt3DCore::QEntity *rubberBandsRootEntity() { return mRubberBandsRootEntity; }
94
96 Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
97
99 Qt3DRender::QRenderCapture *depthRenderCapture();
100
102 void setFrustumCullingEnabled( bool enabled );
103
108 void setAmbientOcclusionEnabled( bool enabled );
109
114 bool ambientOcclusionEnabled() const { return mAmbientOcclusionEnabled; }
115
120 void setAmbientOcclusionIntensity( float intensity );
121
126 float ambientOcclusionIntensity() const { return mAmbientOcclusionIntensity; }
127
132 void setAmbientOcclusionRadius( float radius );
133
138 float ambientOcclusionRadius() const { return mAmbientOcclusionRadius; }
139
144 void setAmbientOcclusionThreshold( float threshold );
145
150 float ambientOcclusionThreshold() const { return mAmbientOcclusionThreshold; }
151
153 void setClearColor( const QColor &clearColor );
155 QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
156
158 void setupEyeDomeLighting( bool enabled, double strength, int distance );
160 void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
162 void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
164 void setSize( QSize s );
165
170 void setRenderCaptureEnabled( bool enabled );
171
176 bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
177
182 void setDebugOverlayEnabled( bool enabled );
183
185 QString dumpFrameGraph() const;
186
188 QString dumpSceneGraph() const;
189
197 void addClipPlanes( int nrClipPlanes );
198
205 void removeClipPlanes();
206
213 bool registerRenderView( std::unique_ptr<QgsAbstractRenderView> renderView, const QString &name );
214
219 void unregisterRenderView( const QString &name );
220
225 void setRenderViewEnabled( const QString &name, bool enable );
226
231 bool isRenderViewEnabled( const QString &name );
232
237 QgsAbstractRenderView *renderView( const QString &name );
238
244
250
256
261 void updateShadowSettings( const QgsShadowSettings &shadowSettings, const QList<QgsLightSource *> &lightSources );
262
263 static const QString FORWARD_RENDERVIEW;
264 static const QString SHADOW_RENDERVIEW;
265 static const QString AXIS3D_RENDERVIEW;
266 static const QString DEPTH_RENDERVIEW;
267
268 private:
269 Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
270 Qt3DRender::QViewport *mMainViewPort = nullptr;
271
272 Qt3DRender::QCamera *mMainCamera = nullptr;
273
274 // Post processing pass branch nodes:
275 Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
276 Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
277 // Post processing pass texture related objects:
278 Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
279 Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
280
281 // Ambient occlusion factor generation pass
282 Qt3DRender::QCameraSelector *mAmbientOcclusionRenderCameraSelector = nullptr;
283 Qt3DRender::QRenderStateSet *mAmbientOcclusionRenderStateSet = nullptr;
284 Qt3DRender::QLayerFilter *mAmbientOcclusionRenderLayerFilter = nullptr;
285 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionRenderCaptureTargetSelector = nullptr;
286 // Ambient occlusion factor generation pass texture related objects:
287 Qt3DRender::QTexture2D *mAmbientOcclusionRenderTexture = nullptr;
288
289 // Ambient occlusion factor blur pass
290 Qt3DRender::QCameraSelector *mAmbientOcclusionBlurCameraSelector = nullptr;
291 Qt3DRender::QRenderStateSet *mAmbientOcclusionBlurStateSet = nullptr;
292 Qt3DRender::QLayerFilter *mAmbientOcclusionBlurLayerFilter = nullptr;
293 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionBlurRenderCaptureTargetSelector = nullptr;
294 // Ambient occlusion factor blur pass texture related objects:
295 Qt3DRender::QTexture2D *mAmbientOcclusionBlurTexture = nullptr;
296
297 // Rubber bands pass
298 Qt3DRender::QCameraSelector *mRubberBandsCameraSelector = nullptr;
299 Qt3DRender::QLayerFilter *mRubberBandsLayerFilter = nullptr;
300 Qt3DRender::QRenderStateSet *mRubberBandsStateSet = nullptr;
301 Qt3DRender::QRenderTargetSelector *mRubberBandsRenderTargetSelector = nullptr;
302
303 // Ambient occlusion related settings
304 bool mAmbientOcclusionEnabled = false;
305 float mAmbientOcclusionIntensity = 0.5f;
306 float mAmbientOcclusionRadius = 25.f;
307 float mAmbientOcclusionThreshold = 0.5f;
308
309 QSize mSize = QSize( 1024, 768 );
310
311 bool mEyeDomeLightingEnabled = false;
312 double mEyeDomeLightingStrength = 1000.0;
313 int mEyeDomeLightingDistance = 1;
314
315 QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
316 QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
317
318 QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
319
320 Qt3DCore::QEntity *mRootEntity = nullptr;
321
322 Qt3DRender::QLayer *mPreviewLayer = nullptr;
323 Qt3DRender::QLayer *mRubberBandsLayer = nullptr;
324
325 QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
326 QgsAmbientOcclusionRenderEntity *mAmbientOcclusionRenderEntity = nullptr;
327 QgsAmbientOcclusionBlurEntity *mAmbientOcclusionBlurEntity = nullptr;
328
329 Qt3DCore::QEntity *mRubberBandsRootEntity = nullptr;
330
331 QVector<QgsPreviewQuad *> mPreviewQuads;
332
333 void constructShadowRenderPass();
334 void constructForwardRenderPass();
335 Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
336 Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
337 void constructDepthRenderPass();
338 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionRenderPass();
339 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionBlurPass();
340 Qt3DRender::QFrameGraphNode *constructRubberBandsPass();
341
342 Qt3DRender::QFrameGraphNode *constructSubPostPassForProcessing();
343 Qt3DRender::QFrameGraphNode *constructSubPostPassForRenderCapture();
344 Qt3DRender::QFrameGraphNode *constructSubPostPassForTexturesPreview();
345
346 bool mRenderCaptureEnabled = false;
347
348 // holds renderviews according to their name
349 std::map<QString, std::unique_ptr<QgsAbstractRenderView>> mRenderViewMap;
350
351 Q_DISABLE_COPY( QgsFrameGraph )
352};
353
354#endif // QGSFRAMEGRAPH_H
Base class for 3D render view.
An entity that is responsible for blurring the ambient occlusion factor texture.
An entity that is responsible for producing an ambient occlusion factor map.
Object that controls camera movement based on user input.
Container class that holds different objects related to depth rendering.
Definition of a directional light in a 3D map scene.
Container class that holds different objects related to forward rendering.
Container class that holds different objects related to frame graphs of 3D scenes.
bool renderCaptureEnabled() const
Returns whether it will be possible to render to an image.
bool isRenderViewEnabled(const QString &name)
Returns true if the render view named name is found and enabled.
void setRenderViewEnabled(const QString &name, bool enable)
Enables or disables the render view named name according to enable.
void updateShadowSettings(const QgsShadowSettings &shadowSettings, const QList< QgsLightSource * > &lightSources)
Updates shadow bias, light and texture size according to shadowSettings and lightSources.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void unregisterRenderView(const QString &name)
Unregisters the render view named name, if any.
QString dumpFrameGraph() const
Dumps frame graph as string.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
QgsAbstractRenderView * renderView(const QString &name)
Returns the render view named name, if any.
void removeClipPlanes()
Disables OpenGL clipping.
bool ambientOcclusionEnabled() const
Returns whether Screen Space Ambient Occlusion is enabled.
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
bool registerRenderView(std::unique_ptr< QgsAbstractRenderView > renderView, const QString &name)
Registers a new the render view renderView with name name.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
QgsDepthRenderView & depthRenderView()
Returns depth renderview.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
QgsPreviewQuad * addTexturePreviewOverlay(Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector< Qt3DRender::QParameter * > additionalShaderParameters=QVector< Qt3DRender::QParameter * >())
Adds an preview entity that shows a texture in real time for debugging purposes.
void setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
static const QString FORWARD_RENDERVIEW
Qt3DCore::QEntity * rubberBandsRootEntity()
Returns entity for all rubber bands (to show them always on top)
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
static const QString SHADOW_RENDERVIEW
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
Qt3DRender::QLayer * previewLayer()
Returns a layer object used to indicate that an entity is to be rendered during the preview textures ...
float ambientOcclusionRadius() const
Returns the ambient occlusion radius.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
static const QString AXIS3D_RENDERVIEW
QgsForwardRenderView & forwardRenderView()
Returns forward renderview.
float ambientOcclusionIntensity() const
Returns the ambient occlusion intensity.
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
Qt3DRender::QTexture2D * blurredAmbientOcclusionFactorMap()
Returns blurred ambient occlusion factor values texture.
QString dumpSceneGraph() const
Dumps scene graph as string.
float ambientOcclusionThreshold() const
Returns the ambient occlusion threshold.
QgsShadowRenderView & shadowRenderView()
Returns shadow renderview.
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
static const QString DEPTH_RENDERVIEW
void setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
An entity that is responsible for applying post processing effects.
Rectangular quad entity used for debugging depth maps.
A rectangle specified with double values.
Container class that holds different objects related to shadow rendering.
Contains configuration for rendering shadows.