QGIS API Documentation 4.3.0-Master (bed6b413c04)
Loading...
Searching...
No Matches
qgsframegraph.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsframegraph.cpp
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#include "qgsframegraph.h"
17
18#include "qgs3dutils.h"
21#include "qgsbloomrenderview.h"
22#include "qgsdepthrenderview.h"
25#include "qgsframegraphutils.h"
32#include "qgsshadowrenderview.h"
33#include "qgssunlightsettings.h"
34
35#include <Qt3DCore/QAttribute>
36#include <Qt3DCore/QBuffer>
37#include <Qt3DCore/QGeometry>
38#include <Qt3DRender/QAbstractTexture>
39#include <Qt3DRender/QBlendEquation>
40#include <Qt3DRender/QBlendEquationArguments>
41#include <Qt3DRender/QBlitFramebuffer>
42#include <Qt3DRender/QColorMask>
43#include <Qt3DRender/QGeometryRenderer>
44#include <Qt3DRender/QGraphicsApiFilter>
45#include <Qt3DRender/QNoDepthMask>
46#include <Qt3DRender/QNoDraw>
47#include <Qt3DRender/QSortPolicy>
48#include <Qt3DRender/QTechnique>
49
50#ifdef HAVE_TRACY
51#include "tracy/Tracy.hpp"
52#endif
53
54#include "moc_qgsframegraph.cpp"
55
56const QString QgsFrameGraph::sForwardRenderView = "forward";
57const QString QgsFrameGraph::sShadowRenderView = "shadow";
58const QString QgsFrameGraph::sAxiS3DRenderView = "3daxis";
59const QString QgsFrameGraph::sDepthRenderView = "depth";
60const QString QgsFrameGraph::sOverlayRenderView = "overlay_texture";
61const QString QgsFrameGraph::sAmbientOcclusionRenderView = "ambient_occlusion";
62const QString QgsFrameGraph::sBloomRenderView = "bloom";
63const QString QgsFrameGraph::sPostprocRenderView = "post_processing";
64const QString QgsFrameGraph::sHighlightsRenderView = "highlights";
65const QString QgsFrameGraph::sRubberRenderView = "rubber_band";
66
67void QgsFrameGraph::constructForwardRenderPass()
68{
69 registerRenderView( std::make_unique<QgsForwardRenderView>( sForwardRenderView, mMainCamera ), sForwardRenderView );
70}
71
72void QgsFrameGraph::constructHighlightsPass()
73{
74 registerRenderView( std::make_unique<QgsHighlightsRenderView>( sHighlightsRenderView, forwardRenderView().renderTargetSelector()->target(), mMainCamera ), sHighlightsRenderView );
75}
76
77void QgsFrameGraph::constructShadowRenderPass()
78{
79 registerRenderView( std::make_unique<QgsShadowRenderView>( sShadowRenderView, mRootEntity ), sShadowRenderView );
80}
81
82void QgsFrameGraph::constructOverlayTexturePass( Qt3DRender::QFrameGraphNode *topNode )
83{
84 registerRenderView( std::make_unique<QgsOverlayTextureRenderView>( sOverlayRenderView ), sOverlayRenderView, topNode );
85}
86
87void QgsFrameGraph::constructPostprocessingPass( Qt3DRender::QFrameGraphNode *topNode )
88{
89 // create post processing render view and register it
90 QgsPostprocessingRenderView *pprv = new QgsPostprocessingRenderView( sPostprocRenderView, this, mSize, mRootEntity );
91 registerRenderView( std::unique_ptr<QgsPostprocessingRenderView>( pprv ), sPostprocRenderView, topNode );
92}
93
94void QgsFrameGraph::updateThumbnailTextureSize()
95{
96 // Tracy requires width/height to be multiples of 4, otherwise it will show
97 // just a black rectangle.
98 const int width = ( mSize.width() / 10 ) & ~3;
99 const int height = ( mSize.height() / 10 ) & ~3;
100 mThumbnailTexture->setSize( width, height );
101}
102
103void QgsFrameGraph::constructThumbnailCapturePass()
104{
105 // Diagram of the nodes we're creating:
106 // mMainViewPort
107 // ├── QBlitFramebuffer (copy from forwardRenderView to mThumbnailTexture)
108 // └── QRenderTargetSelector (set to mThumbnailTexture)
109 // └── QRenderCapture (mThumbnailCapture)
110
111 mThumbnailTexture = new Qt3DRender::QTexture2D( this );
112 mThumbnailTexture->setFormat( Qt3DRender::QAbstractTexture::RGBA8_UNorm );
113 updateThumbnailTextureSize();
114
115 Qt3DRender::QRenderTargetOutput *renderTargetOutput = new Qt3DRender::QRenderTargetOutput( this );
116 renderTargetOutput->setTexture( mThumbnailTexture );
117
118 Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget( this );
119 renderTarget->addOutput( renderTargetOutput );
120
121 // Copy from forward render pass to thumbnail texture
122 Qt3DRender::QBlitFramebuffer *blit = new Qt3DRender::QBlitFramebuffer( mMainViewPort );
123 blit->setObjectName( "Framebuffer copy for thumbnail" );
124 blit->setSource( forwardRenderView().renderTargetSelector()->target() );
125 blit->setDestination( renderTarget );
126 blit->setSourceRect( QRectF( 0, 0, 1, 1 ) );
127 blit->setDestinationRect( QRectF( 0, 0, 1, 1 ) );
128 blit->setInterpolationMethod( Qt3DRender::QBlitFramebuffer::Linear );
129
130 Qt3DRender::QRenderTargetSelector *targetSelector = new Qt3DRender::QRenderTargetSelector( mMainViewPort );
131 targetSelector->setObjectName( "Thumbnail capture target selector" );
132 targetSelector->setTarget( renderTarget );
133
134 mThumbnailCapture = new Qt3DRender::QRenderCapture( targetSelector );
135 mThumbnailCapture->setObjectName( "Thumbnail capture" );
136
137 // Request initial capture
138 // Ugly hack: Requesting just once results in a capture every two frames.
139 // "Buffering" an extra capture like this works around that.
140 Qt3DRender::QRenderCaptureReply *reply1 = mThumbnailCapture->requestCapture();
141 Qt3DRender::QRenderCaptureReply *reply2 = mThumbnailCapture->requestCapture();
142 for ( Qt3DRender::QRenderCaptureReply *reply : { reply1, reply2 } )
143 connect( reply, &Qt3DRender::QRenderCaptureReply::completed, this, [this, reply]() { onThumbnailCaptureCompleted( reply ); } );
144}
145
146void QgsFrameGraph::onThumbnailCaptureCompleted( Qt3DRender::QRenderCaptureReply *reply )
147{
148 reply->deleteLater();
149
150#ifdef HAVE_TRACY
151 // Convert to RGBA8888 format (required by Tracy)
152 QImage rgbaImage = reply->image().convertToFormat( QImage::Format_RGBA8888 );
153
154 // Send to Tracy
155 FrameImage(
156 rgbaImage.constBits(),
157 static_cast<uint16_t>( rgbaImage.width() ),
158 static_cast<uint16_t>( rgbaImage.height() ),
159 0, // offset: 0 = current frame
160 true // flip Y coord: true for OpenGL
161 );
162#endif
163
164 // Request next frame capture
165 Qt3DRender::QRenderCaptureReply *nextReply = mThumbnailCapture->requestCapture();
166 connect( nextReply, &Qt3DRender::QRenderCaptureReply::completed, this, [this, nextReply]() { onThumbnailCaptureCompleted( nextReply ); } );
167}
168
169void QgsFrameGraph::constructAmbientOcclusionRenderPass()
170{
171 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
172
173 QgsAmbientOcclusionRenderView *aorv = new QgsAmbientOcclusionRenderView( sAmbientOcclusionRenderView, mMainCamera, mSize, forwardDepthTexture, mRootEntity );
174 registerRenderView( std::unique_ptr<QgsAmbientOcclusionRenderView>( aorv ), sAmbientOcclusionRenderView );
175}
176
177void QgsFrameGraph::constructBloomRenderPass()
178{
179 Qt3DRender::QTexture2D *forwardColorTexture = forwardRenderView().colorTexture();
180
181 QgsBloomRenderView *rv = new QgsBloomRenderView( sBloomRenderView, forwardColorTexture, mSize, mRootEntity );
182 registerRenderView( std::unique_ptr<QgsBloomRenderView>( rv ), sBloomRenderView );
183}
184
185void QgsFrameGraph::constructRubberBandsPass( Qt3DRender::QFrameGraphNode *topNode )
186{
187 // rubber band render view writes to the same output textures than the forward render view:
188 QgsRubberBandRenderView *rv = new QgsRubberBandRenderView( sRubberRenderView, mMainCamera, mRootEntity, forwardRenderView().renderTargetSelector()->target() );
189 registerRenderView( std::unique_ptr<QgsRubberBandRenderView>( rv ), sRubberRenderView, topNode );
190}
191
192void QgsFrameGraph::constructDepthRenderPass()
193{
194 // entity used to draw the depth texture and convert it to rgb image
195 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
196 QgsDepthRenderView *rv = new QgsDepthRenderView( sDepthRenderView, mSize, forwardDepthTexture, mRootEntity );
197 registerRenderView( std::unique_ptr<QgsDepthRenderView>( rv ), sDepthRenderView );
198}
199
200Qt3DRender::QRenderCapture *QgsFrameGraph::depthRenderCapture()
201{
203}
204
205void QgsFrameGraph::addGlobalParameters( const QList<Qt3DRender::QParameter *> &parameters )
206{
207 for ( Qt3DRender::QParameter *param : parameters )
208 {
209 mGlobalParamsStorage->addParameter( param );
210 }
211}
212
213QgsFrameGraph::QgsFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root )
214 : Qt3DCore::QEntity( root )
215 , mSize( s )
216{
217 // general overview of how the frame graph looks:
218 //
219 // +------------------------+ using window or
220 // | QRenderSurfaceSelector | offscreen surface
221 // +------------------------+
222 // |
223 // +-----------+
224 // | QViewport | (0,0,1,1)
225 // +-----------+
226 // |
227 // +---------------------+---------------+------------------------+-------------------+
228 // | | | | |
229 // | | | (optional) | |
230 // +--------------+ +------------------+ +-----------------+ +-----------------+ +-----------------+
231 // | shadows pass | | forward passes | | MSAA blit | | depth buffer | | post-processing |
232 // | | | (solid objects, | | (color + depth) | | processing pass | | passes |
233 // +--------------+ | transparent, | +-----------------+ +-----------------+ +-----------------+
234 // | highlights, |
235 // | rubber bands) |
236 // +------------------+
237 //
238 // Notes:
239 // - (optional) MSAA blits multisampled (4 samples) color and depth textures
240 // so that other passes can sample them
241 // - shadows pass MUST come before other forward passes, as we use the shadow
242 // information in the material shaders
243 // - depth buffer processing pass is used whenever we need depth map information
244 // (for camera navigation) and it converts depth texture to a color texture
245 // so that we can capture it with QRenderCapture - currently it is unable
246 // to capture depth buffer, only colors (see QTBUG-65155)
247 // - there are multiple post-processing passes that take rendered output
248 // of the scene, optionally apply effects (add shadows, ambient occlusion,
249 // eye dome lighting) and finally output to the given surface
250 // - there may be also two more passes when 3D axis is shown - see Qgs3DAxis
251
252 mRootEntity = root;
253 mMainCamera = mainCamera;
254
255 mRenderSurfaceSelector = new Qt3DRender::QRenderSurfaceSelector;
256
257 QObject *surfaceObj = dynamic_cast<QObject *>( surface );
258 Q_ASSERT( surfaceObj );
259
260 mRenderSurfaceSelector->setSurface( surfaceObj );
261 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
262
263 mMainViewPort = new Qt3DRender::QViewport( mRenderSurfaceSelector );
264 mMainViewPort->setNormalizedRect( QRectF( 0.0f, 0.0f, 1.0f, 1.0f ) );
265
266 mGlobalParamsStorage = new Qt3DRender::QRenderPassFilter( mMainViewPort );
267 mGlobalParamsStorage->setObjectName( "GlobalParametersStore" );
268
269 // shadow rendering pass -- must be constructed BEFORE the forward render pass,
270 // to ensure it always has the correct depth available.
271 constructShadowRenderPass();
272
273 // Forward render
274 constructForwardRenderPass();
275
276 // Highlighted items pass
277 constructHighlightsPass();
278
279 // rubber bands (they should be always on top)
280 constructRubberBandsPass( mGlobalParamsStorage );
281
282 mMsaaBlitNode = new Qt3DRender::QBlitFramebuffer( mGlobalParamsStorage );
283 mMsaaBlitNode->setObjectName( "MsaaBlitFramebuffer" );
284 mMsaaBlitNode->setEnabled( false );
285 new Qt3DRender::QNoDraw( mMsaaBlitNode );
286
287 mMsaaDepthBlitNode = new Qt3DRender::QBlitFramebuffer( mGlobalParamsStorage );
288 mMsaaDepthBlitNode->setObjectName( "MsaaDepthBlitFramebuffer" );
289 mMsaaDepthBlitNode->setEnabled( false );
290 new Qt3DRender::QNoDraw( mMsaaDepthBlitNode );
291
292 // depth buffer processing
293 constructDepthRenderPass();
294
295 // Ambient occlusion factor render pass
296 constructAmbientOcclusionRenderPass();
297
298 constructBloomRenderPass();
299
300 // post process
301 constructPostprocessingPass( mGlobalParamsStorage );
302
303#ifdef HAVE_TRACY
304 constructThumbnailCapturePass();
305#endif
306
307 // fix FBO incomplete issue when using globe and 3D animations export with MSAA enabled
308 // (with globe, canvas simply stays empty with FBO incomplete msg appearing on window resize)
309 Qt3DRender::QRenderTargetSelector *targetSelector = new Qt3DRender::QRenderTargetSelector( mGlobalParamsStorage );
310 targetSelector->setTarget( forwardRenderView().regularRenderTarget() );
311 mMsaaClearBuffers = new Qt3DRender::QClearBuffers( targetSelector );
312 mMsaaClearBuffers->setEnabled( false );
313 mMsaaClearBuffers->setBuffers( Qt3DRender::QClearBuffers::ColorDepthBuffer );
314 new Qt3DRender::QNoDraw( mMsaaClearBuffers );
315}
316
317void QgsFrameGraph::unregisterRenderView( const QString &name )
318{
319 if ( mRenderViewMap.find( name ) != mRenderViewMap.end() )
320 {
321 mRenderViewMap[name]->topGraphNode()->setParent( ( QNode * ) nullptr );
322 mRenderViewMap.erase( name );
323 }
324}
325
326bool QgsFrameGraph::registerRenderView( std::unique_ptr<QgsAbstractRenderView> renderView, const QString &name, Qt3DRender::QFrameGraphNode *topNode )
327{
328 bool out;
329 if ( mRenderViewMap.find( name ) == mRenderViewMap.end() )
330 {
331 mRenderViewMap[name] = std::move( renderView );
332 mRenderViewMap[name]->topGraphNode()->setParent( topNode ? topNode : mGlobalParamsStorage );
333 mRenderViewMap[name]->updateWindowResize( mSize.width(), mSize.height() );
334 out = true;
335 }
336 else
337 out = false;
338
339 return out;
340}
341
342void QgsFrameGraph::setRenderViewEnabled( const QString &name, bool enable )
343{
344 if ( mRenderViewMap[name] )
345 {
346 mRenderViewMap[name]->setEnabled( enable );
347 }
348}
349
351{
352 if ( mRenderViewMap.find( name ) != mRenderViewMap.end() )
353 {
354 return mRenderViewMap[name].get();
355 }
356 return nullptr;
357}
358
359bool QgsFrameGraph::isRenderViewEnabled( const QString &name )
360{
361 return mRenderViewMap[name] != nullptr && mRenderViewMap[name]->isEnabled();
362}
363
365{
367
368 aoRenderView.setRadius( settings.radius() );
369 aoRenderView.setIntensity( settings.intensity() );
370 aoRenderView.setThreshold( settings.threshold() );
371 aoRenderView.setEnabled( settings.isEnabled() );
372
374}
375
381
383{
385
386 renderView.setEnabled( settings.isEnabled() );
387 renderView.setFilterRadius( static_cast< float >( settings.radius() ) );
388
391}
392
397
399{
400 const QgsShadowSettings shadowSettings = mapSettings.shadowSettings();
401 const QList<QgsLightSource *> lightSources = mapSettings.lightSources();
402 if ( shadowSettings.renderShadows() )
403 {
404 const QString lightSourceId = shadowSettings.lightSource();
405 QgsLightSource *light = nullptr;
406 int globalLightIndex = 0;
407
408 QgsLightSource *backupLightSource = nullptr;
409 int backupLightSourceIndex = 0;
410 for ( int i = 0; !light && i < lightSources.size(); i++ )
411 {
412 if ( !backupLightSource )
413 {
414 if ( auto directionalLight = dynamic_cast< QgsDirectionalLightSettings * >( lightSources[i] ) )
415 {
416 backupLightSource = directionalLight;
417 backupLightSourceIndex = i;
418 }
419 else if ( auto sunLight = dynamic_cast< QgsSunLightSettings * >( lightSources[i] ) )
420 {
421 backupLightSource = sunLight;
422 backupLightSourceIndex = i;
423 }
424 }
425
426 if ( lightSources[i]->id() == lightSourceId )
427 {
428 light = lightSources[i];
429 globalLightIndex = i;
430 }
431 }
432
433 if ( !light )
434 {
435 // if we didn't find an light matching the exact ID requested, then
436 // fallback to just the first compatible light found in the scene
437 light = backupLightSource;
438 globalLightIndex = backupLightSourceIndex;
439 }
440
441 if ( light )
442 {
443 QgsVector3D lightDirection;
444 if ( auto directionalLight = dynamic_cast< QgsDirectionalLightSettings * >( light ) )
445 {
446 lightDirection = directionalLight->direction();
447 }
448 else if ( auto sunLight = dynamic_cast< QgsSunLightSettings * >( light ) )
449 {
450 lightDirection = sunLight->direction( mapSettings );
451 }
452
453 const int size = shadowSettings.qualityToMapResolution( shadowSettings.shadowQuality() );
454 shadowRenderView().setMapSize( size, size );
456
458 postprocessingRenderView().entity()->updateShadowSettings( shadowSettings, lightDirection, size, globalLightIndex );
459 }
460 }
461 else
462 {
463 shadowRenderView().setEnabled( false );
465 }
466}
467
469{
471
472 if ( !mDepthTextureDebugging && settings.debugDepthMapEnabled() )
473 {
474 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
475 mDepthTextureDebugging = new QgsOverlayTextureEntity( forwardDepthTexture, overlayRenderView.overlayLayer(), this );
476 }
477
478 overlayRenderView.setEnabled( settings.debugDepthMapEnabled() || settings.is2DMapOverlayEnabled() );
479
480 if ( mDepthTextureDebugging )
481 {
482 mDepthTextureDebugging->setEnabled( settings.debugDepthMapEnabled() );
483 if ( settings.debugDepthMapEnabled() )
484 mDepthTextureDebugging->setPosition( settings.debugDepthMapCorner(), settings.debugDepthMapSize() );
485 else
486 {
487 delete mDepthTextureDebugging;
488 mDepthTextureDebugging = nullptr;
489 }
490 }
491}
492
494{
495 QObject *top = mRenderSurfaceSelector;
496 while ( top->parent() && dynamic_cast<Qt3DRender::QFrameGraphNode *>( top->parent() ) )
497 top = top->parent();
498
500 context.lowestId = mMainCamera->id().id();
501 QStringList strList = QgsFrameGraphUtils::dumpFrameGraph( dynamic_cast<Qt3DRender::QFrameGraphNode *>( top ), context );
502
503 return strList.join( "\n" ) + QString( "\n" );
504}
505
507{
508 QStringList strList = QgsFrameGraphUtils::dumpSceneGraph( mRootEntity, QgsFrameGraphUtils::FgDumpContext() );
509 return strList.join( "\n" ) + QString( "\n" );
510}
511
512void QgsFrameGraph::setClearColor( const QColor &clearColor )
513{
514 forwardRenderView().setClearColor( clearColor );
515}
516
521
523{
524 mSize = s;
525 for ( auto it = mRenderViewMap.begin(); it != mRenderViewMap.end(); ++it )
526 {
527 QgsAbstractRenderView *rv = it->second.get();
528 rv->updateWindowResize( mSize.width(), mSize.height() );
529 }
530
531 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
532
533 mMsaaBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
534 mMsaaBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
535 mMsaaDepthBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
536 mMsaaDepthBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
537
538 if ( mThumbnailTexture )
539 updateThumbnailTextureSize();
540}
541
542Qt3DRender::QRenderCapture *QgsFrameGraph::renderCapture()
543{
545}
546
551
556
558{
559 mMsaaEnabled = enabled;
560
561 if ( !enabled && mMsaaBlitConfigured )
562 {
563 mMsaaBlitNode->setSource( nullptr );
564 mMsaaBlitNode->setDestination( nullptr );
565 mMsaaDepthBlitNode->setSource( nullptr );
566 mMsaaDepthBlitNode->setDestination( nullptr );
567 mMsaaBlitConfigured = false;
568 mMsaaClearBuffers->setEnabled( false );
569 }
570
572
573 if ( enabled && !mMsaaBlitConfigured )
574 {
575 mMsaaBlitConfigured = true;
576 mMsaaBlitNode->setSource( forwardRenderView().msaaRenderTarget() );
577 mMsaaBlitNode->setDestination( forwardRenderView().regularRenderTarget() );
578 mMsaaBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
579 mMsaaBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
580 mMsaaBlitNode->setSourceAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
581 mMsaaBlitNode->setDestinationAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
582 mMsaaBlitNode->setInterpolationMethod( Qt3DRender::QBlitFramebuffer::Nearest );
583
584 mMsaaDepthBlitNode->setSource( forwardRenderView().msaaRenderTarget() );
585 mMsaaDepthBlitNode->setDestination( forwardRenderView().regularRenderTarget() );
586 mMsaaDepthBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
587 mMsaaDepthBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
588 mMsaaDepthBlitNode->setSourceAttachmentPoint( Qt3DRender::QRenderTargetOutput::DepthStencil );
589 mMsaaDepthBlitNode->setDestinationAttachmentPoint( Qt3DRender::QRenderTargetOutput::DepthStencil );
590 mMsaaDepthBlitNode->setInterpolationMethod( Qt3DRender::QBlitFramebuffer::Nearest );
591
592 mMsaaClearBuffers->setEnabled( true );
593 }
594
595 Qt3DRender::QRenderTarget *target = enabled ? forwardRenderView().msaaRenderTarget() : forwardRenderView().regularRenderTarget();
597 rubberBandRenderView().renderTargetSelector()->setTarget( target );
598 mMsaaBlitNode->setEnabled( enabled );
599 mMsaaDepthBlitNode->setEnabled( enabled );
600}
601
606
607void QgsFrameGraph::addClipPlanes( int nrClipPlanes )
608{
609 forwardRenderView().addClipPlanes( nrClipPlanes );
610}
611
613{
615 return *( dynamic_cast<QgsForwardRenderView *>( rv ) );
616}
617
619{
621 return *( dynamic_cast<QgsShadowRenderView *>( rv ) );
622}
623
625{
626 QgsAbstractRenderView *rv = mRenderViewMap[QgsFrameGraph::sDepthRenderView].get();
627 return *( dynamic_cast<QgsDepthRenderView *>( rv ) );
628}
629
635
637{
638 QgsAbstractRenderView *rv = mRenderViewMap[QgsFrameGraph::sBloomRenderView].get();
639 return *( dynamic_cast<QgsBloomRenderView *>( rv ) );
640}
641
647
653
658
Definition of the world.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
QgsShadowSettings shadowSettings() const
Returns the current configuration of shadows.
QList< QgsLightSource * > lightSources() const
Returns list of directional light sources defined in the scene.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
bool is2DMapOverlayEnabled() const
Returns whether 2D map overlay is enabled.
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
Base class for 3D render view.
virtual void setEnabled(bool enable)
Enable or disable via enable the render view sub tree.
virtual bool isEnabled() const
Returns true if render view is enabled.
virtual void updateWindowResize(int width, int height)
Called when 3D window is resized.
Container class that holds different objects related to ambient occlusion rendering.
void setRadius(float radius)
Delegates to QgsAmbientOcclusionRenderEntity::setRadius.
void setEnabled(bool enable) override
Enable or disable via enable the render view sub tree.
void setIntensity(float intensity)
Delegates to QgsAmbientOcclusionRenderEntity::setIntensity.
void setThreshold(float threshold)
Delegates to QgsAmbientOcclusionRenderEntity::setThreshold.
Contains the configuration of ambient occlusion rendering.
float radius() const
Returns the radius parameter of the ambient occlusion effect.
bool isEnabled() const
Returns whether ambient occlusion effect is enabled.
float intensity() const
Returns the shading factor of the ambient occlusion effect.
float threshold() const
Returns at what amount of occlusion the effect will kick in.
Container class that holds different objects related to bloom rendering.
Contains the configuration of the lighting "bloom" effect.
double radius() const
Returns the filter radius for the bloom.
bool isEnabled() const
Returns whether the bloom effect is enabled.
Contains the configuration of the scene's color grading settings, such as exposure and tone mapping.
Container class that holds different objects related to depth rendering.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
Definition of a directional light in a 3D map scene.
Container class that holds different objects related to forward rendering.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color).
Qt3DRender::QTexture2D * colorTexture() const
Returns forward color texture.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setMsaaEnabled(bool enabled)
Sets whether multisample anti-aliasing (MSAA) is enabled.
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Qt3DRender::QTexture2D * depthTexture() const
Returns forward depth texture.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void removeClipPlanes()
Disables OpenGL clipping.
Qt3DRender::QRenderTarget * msaaRenderTarget() const
Returns the multisampled render target used as blit source when MSAA is enabled.
Qt3DRender::QRenderTarget * regularRenderTarget() const
Returns the regular (single-sample) render target used as blit destination and postprocessing input.
static QStringList dumpFrameGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the frame graph starting from node. The object ids will be given relatively to...
static QStringList dumpSceneGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the scene graph starting from node. The object ids will be given relatively to...
void addGlobalParameters(const QList< Qt3DRender::QParameter * > &parameters)
Adds additional global parameters to the graph.
void setMsaaEnabled(bool enabled)
Sets whether multisample anti-aliasing (MSAA) is enabled.
void updateAmbientOcclusionSettings(const QgsAmbientOcclusionSettings &settings)
Updates settings for ambient occlusion.
void updateEyeDomeSettings(const Qgs3DMapSettings &settings)
Updates settings for eye dome lighting.
void updateBloomSettings(const QgsBloomSettings &settings)
Updates settings for the bloom lighting effect.
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 addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void updateColorGradingSettings(const QgsColorGradingSettings &settings)
Updates settings for color grading.
static const QString sPostprocRenderView
Postprocessing render view name.
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.
QgsPostprocessingRenderView & postprocessingRenderView()
Returns post processing renderview.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
QgsAmbientOcclusionRenderView & ambientOcclusionRenderView()
Returns ambient occlusion renderview.
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.
QgsRubberBandRenderView & rubberBandRenderView()
Returns rubber band renderview.
static const QString sOverlayRenderView
QgsDepthRenderView & depthRenderView()
Returns depth renderview.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color).
static const QString sDepthRenderView
static const QString sForwardRenderView
static const QString sBloomRenderView
static const QString sShadowRenderView
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
void updateShadowSettings(const Qgs3DMapSettings &mapSettings)
Updates shadow bias, light and texture size according to shadowSettings and lightSources.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
QgsHighlightsRenderView & highlightsRenderView()
Returns the highlights renderview, used for rendering highlight overlays of identified features.
static const QString sAxiS3DRenderView
void updateDebugDepthMapSettings(const Qgs3DMapSettings &settings)
Updates settings for depth debug map.
QgsForwardRenderView & forwardRenderView()
Returns forward renderview.
static const QString sAmbientOcclusionRenderView
Ambient occlusion render view name.
QgsOverlayTextureRenderView & overlayTextureRenderView()
Returns overlay texture renderview.
QString dumpSceneGraph() const
Dumps scene graph as string.
QgsShadowRenderView & shadowRenderView()
Returns shadow renderview.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
QgsBloomRenderView & bloomRenderView()
Returns the bloom render view.
static const QString sHighlightsRenderView
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
QgsFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
static const QString sRubberRenderView
Container class that holds different objects related to highlighting identified features.
void setRenderTarget(Qt3DRender::QRenderTarget *target)
Switches the render target (called when toggling MSAA on/off).
Base class for light sources in 3d scenes.
An entity responsible for rendering an overlay texture in 3D view.
Simple render view to preview overlay textures in 3D view.
Qt3DRender::QLayer * overlayLayer() const
Returns layer in which entities must be added in the in order to be processed by this renderview.
void updateShadowSettings(const QgsShadowSettings &shadowSettings, const QgsVector3D &lightDir, int size, int globalLightIndex)
Sets shadow rendering to use a directional light.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether screen space ambient occlusion is enabled.
void setShadowRenderingEnabled(bool enabled)
Sets whether shadow rendering is enabled.
void setBloomEnabled(bool enabled)
Sets whether physically based bloom is enabled.
void updateEyeDomeSettings(const Qgs3DMapSettings &settings)
Updates eye dome lighting settings from settings.
void updateBloomSettings(const QgsBloomSettings &settings)
Sets bloom rendering to use a directional light.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting is enabled.
void updateColorGradingSettings(const QgsColorGradingSettings &settings)
Updates settings for color grading.
Container class that holds different objects related to postprocessing rendering.
Qt3DRender::QRenderCapture * renderCapture() const
Returns the render capture object used to take an image of the postprocessing buffer of the scene.
QgsPostprocessingEntity * entity() const
Returns the QT3D entity used to do the rendering.
void setOffScreenRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
QgsOverlayTextureRenderView * overlayTextureRenderView() const
Returns overlay texture render view.
Container class that holds different objects related to rubberband rendering.
Qt3DRender::QRenderTargetSelector * renderTargetSelector() const
Returns rubberband tard selector.
Container class that holds different objects related to shadow rendering.
void setMapSize(int width, int height)
Update shadow depth texture size.
void setEnabled(bool enable) override
Enable or disable via enable the renderview sub tree.
Contains configuration for rendering shadows.
bool renderShadows() const
Returns whether shadow rendering is enabled.
static int qualityToMapResolution(Qgis::ShadowQuality quality)
Returns the shadow map resolution corresponding to the specified shadow quality.
QString lightSource() const
Returns the ID of the light source casting shadows.
Qgis::ShadowQuality shadowQuality() const
Returns the quality of the shadow map texture used to generate the shadows.
Definition of a sun light in a 3D map scene.
A 3D vector (similar to QVector3D) with the difference that it uses double precision instead of singl...
Definition qgsvector3d.h:33