QGIS API Documentation 3.43.0-Master (58029bba303)
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;
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::QCamera *mainCamera() { return mMainCamera; }
86
88 QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
89
91 Qt3DCore::QEntity *rubberBandsRootEntity() { return mRubberBandsRootEntity; }
92
94 Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
95
97 Qt3DRender::QRenderCapture *depthRenderCapture();
98
100 void setFrustumCullingEnabled( bool enabled );
101
106 void setAmbientOcclusionEnabled( bool enabled );
107
112 bool ambientOcclusionEnabled() const { return mAmbientOcclusionEnabled; }
113
118 void setAmbientOcclusionIntensity( float intensity );
119
124 float ambientOcclusionIntensity() const { return mAmbientOcclusionIntensity; }
125
130 void setAmbientOcclusionRadius( float radius );
131
136 float ambientOcclusionRadius() const { return mAmbientOcclusionRadius; }
137
142 void setAmbientOcclusionThreshold( float threshold );
143
148 float ambientOcclusionThreshold() const { return mAmbientOcclusionThreshold; }
149
151 void setClearColor( const QColor &clearColor );
152
154 void setupEyeDomeLighting( bool enabled, double strength, int distance );
156 void setSize( QSize s );
157
162 void setRenderCaptureEnabled( bool enabled );
163
168 bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
169
174 void setDebugOverlayEnabled( bool enabled );
175
177 QString dumpFrameGraph() const;
178
180 QString dumpSceneGraph() const;
181
189 void addClipPlanes( int nrClipPlanes );
190
197 void removeClipPlanes();
198
206 bool registerRenderView( std::unique_ptr<QgsAbstractRenderView> renderView, const QString &name, Qt3DRender::QFrameGraphNode *topNode = nullptr );
207
212 void unregisterRenderView( const QString &name );
213
218 void setRenderViewEnabled( const QString &name, bool enable );
219
224 bool isRenderViewEnabled( const QString &name );
225
230 QgsAbstractRenderView *renderView( const QString &name );
231
237
243
249
254 void updateShadowSettings( const QgsShadowSettings &shadowSettings, const QList<QgsLightSource *> &lightSources );
255
260 void updateDebugShadowMapSettings( const Qgs3DMapSettings &settings );
261
266 void updateDebugDepthMapSettings( const Qgs3DMapSettings &settings );
267
268 static const QString FORWARD_RENDERVIEW;
269 static const QString SHADOW_RENDERVIEW;
270 static const QString AXIS3D_RENDERVIEW;
271 static const QString DEPTH_RENDERVIEW;
272 static const QString DEBUG_RENDERVIEW;
273
274 private:
275 Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
276 Qt3DRender::QViewport *mMainViewPort = nullptr;
277
278 Qt3DRender::QCamera *mMainCamera = nullptr;
279
280 // Post processing pass branch nodes:
281 Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
282 Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
283 // Post processing pass texture related objects:
284 Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
285 Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
286
287 // Ambient occlusion factor generation pass
288 Qt3DRender::QCameraSelector *mAmbientOcclusionRenderCameraSelector = nullptr;
289 Qt3DRender::QRenderStateSet *mAmbientOcclusionRenderStateSet = nullptr;
290 Qt3DRender::QLayerFilter *mAmbientOcclusionRenderLayerFilter = nullptr;
291 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionRenderCaptureTargetSelector = nullptr;
292 // Ambient occlusion factor generation pass texture related objects:
293 Qt3DRender::QTexture2D *mAmbientOcclusionRenderTexture = nullptr;
294
295 // Ambient occlusion factor blur pass
296 Qt3DRender::QCameraSelector *mAmbientOcclusionBlurCameraSelector = nullptr;
297 Qt3DRender::QRenderStateSet *mAmbientOcclusionBlurStateSet = nullptr;
298 Qt3DRender::QLayerFilter *mAmbientOcclusionBlurLayerFilter = nullptr;
299 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionBlurRenderCaptureTargetSelector = nullptr;
300 // Ambient occlusion factor blur pass texture related objects:
301 Qt3DRender::QTexture2D *mAmbientOcclusionBlurTexture = nullptr;
302
303 // Rubber bands pass
304 Qt3DRender::QCameraSelector *mRubberBandsCameraSelector = nullptr;
305 Qt3DRender::QLayerFilter *mRubberBandsLayerFilter = nullptr;
306 Qt3DRender::QRenderStateSet *mRubberBandsStateSet = nullptr;
307 Qt3DRender::QRenderTargetSelector *mRubberBandsRenderTargetSelector = nullptr;
308
309 // Ambient occlusion related settings
310 bool mAmbientOcclusionEnabled = false;
311 float mAmbientOcclusionIntensity = 0.5f;
312 float mAmbientOcclusionRadius = 25.f;
313 float mAmbientOcclusionThreshold = 0.5f;
314
315 QSize mSize = QSize( 1024, 768 );
316
317 bool mEyeDomeLightingEnabled = false;
318 double mEyeDomeLightingStrength = 1000.0;
319 int mEyeDomeLightingDistance = 1;
320
321 QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
322
323 Qt3DCore::QEntity *mRootEntity = nullptr;
324
325 Qt3DRender::QLayer *mRubberBandsLayer = nullptr;
326
327 QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
328 QgsAmbientOcclusionRenderEntity *mAmbientOcclusionRenderEntity = nullptr;
329 QgsAmbientOcclusionBlurEntity *mAmbientOcclusionBlurEntity = nullptr;
330
331 Qt3DCore::QEntity *mRubberBandsRootEntity = nullptr;
332
334 QgsDebugTextureEntity *mShadowTextureDebugging = nullptr;
336 QgsDebugTextureEntity *mDepthTextureDebugging = nullptr;
337
338 void constructShadowRenderPass();
339 void constructForwardRenderPass();
340 void constructDebugTexturePass( Qt3DRender::QFrameGraphNode *topNode = nullptr );
341 Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
342 void constructDepthRenderPass();
343 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionRenderPass();
344 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionBlurPass();
345 Qt3DRender::QFrameGraphNode *constructRubberBandsPass();
346
347 Qt3DRender::QFrameGraphNode *constructSubPostPassForProcessing();
348 Qt3DRender::QFrameGraphNode *constructSubPostPassForRenderCapture();
349 Qt3DRender::QFrameGraphNode *constructSubPostPassForTexturesPreview();
350
351 bool mRenderCaptureEnabled = false;
352
353 // holds renderviews according to their name
354 std::map<QString, std::unique_ptr<QgsAbstractRenderView>> mRenderViewMap;
355
356 Q_DISABLE_COPY( QgsFrameGraph )
357};
358
359#endif // QGSFRAMEGRAPH_H
Definition of the world.
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.
An entity that is responsible for debugging texture.
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.
bool registerRenderView(std::unique_ptr< QgsAbstractRenderView > renderView, const QString &name, Qt3DRender::QFrameGraphNode *topNode=nullptr)
Registers a new the render view renderView with name name.
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.
void updateDebugShadowMapSettings(const Qgs3DMapSettings &settings)
Updates settings for shadows debug map.
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.
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.
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.
float ambientOcclusionRadius() const
Returns the ambient occlusion radius.
void updateDebugDepthMapSettings(const Qgs3DMapSettings &settings)
Updates settings for depth debug map.
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.
static const QString DEBUG_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.
A rectangle specified with double values.
Container class that holds different objects related to shadow rendering.
Contains configuration for rendering shadows.