QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgswindow3dengine.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswindow3dengine.cpp
3  --------------------------------------
4  Date : July 2018
5  Copyright : (C) 2018 by Martin Dobias
6  Email : wonder dot sk at gmail dot com
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 "qgswindow3dengine.h"
17 
18 #include <Qt3DRender/QRenderCapture>
19 #include <Qt3DExtras/Qt3DWindow>
20 #include <Qt3DExtras/QForwardRenderer>
21 #include <Qt3DRender/QRenderSettings>
22 
23 #include "qgspreviewquad.h"
24 
26  : QgsAbstract3DEngine( parent )
27 {
28  mWindow3D = new Qt3DExtras::Qt3DWindow;
29 
30  mRoot = new Qt3DCore::QEntity;
31  mWindow3D->setRootEntity( mRoot );
32 
33  mShadowRenderingFrameGraph = new QgsShadowRenderingFrameGraph( mWindow3D, mWindow3D->camera(), mRoot );
34 
35  mWindow3D->setActiveFrameGraph( mShadowRenderingFrameGraph->getFrameGraphRoot() );
36 
37  // force switching to no shadow rendering
39 }
40 
42 {
43  return mWindow3D;
44 }
45 
47 {
48  Qt3DRender::QRenderCaptureReply *captureReply;
49  captureReply = mShadowRenderingFrameGraph->renderCapture()->requestCapture();
50  connect( captureReply, &Qt3DRender::QRenderCaptureReply::completed, this, [ = ]
51  {
52  emit imageCaptured( captureReply->image() );
53  captureReply->deleteLater();
54  } );
55 }
56 
58 {
59  mShadowRenderingEnabled = enabled;
60  mShadowRenderingFrameGraph->setShadowRenderingEnabled( mShadowRenderingEnabled );
61 }
62 
63 void QgsWindow3DEngine::setClearColor( const QColor &color )
64 {
65  mShadowRenderingFrameGraph->setClearColor( color );
66 }
67 
69 {
70  // Not sure if this works properly
71  mShadowRenderingFrameGraph->setFrustumCullingEnabled( enabled );
72 }
73 
74 void QgsWindow3DEngine::setRootEntity( Qt3DCore::QEntity *root )
75 {
76  mSceneRoot = root;
77  mSceneRoot->setParent( mRoot );
78  mSceneRoot->addComponent( mShadowRenderingFrameGraph->forwardRenderLayer() );
79  mSceneRoot->addComponent( mShadowRenderingFrameGraph->castShadowsLayer() );
80 }
81 
82 Qt3DRender::QRenderSettings *QgsWindow3DEngine::renderSettings()
83 {
84  return mWindow3D->renderSettings();
85 }
86 
87 Qt3DRender::QCamera *QgsWindow3DEngine::camera()
88 {
89  return mWindow3D->camera();
90 }
91 
93 {
94  return mWindow3D->size();
95 }
96 
97 QSurface *QgsWindow3DEngine::surface() const
98 {
99  return mWindow3D;
100 }
QgsWindow3DEngine::QgsWindow3DEngine
QgsWindow3DEngine(QObject *parent=nullptr)
Constructor for QgsWindow3DEngine with the specified parent object.
Definition: qgswindow3dengine.cpp:25
qgspreviewquad.h
QgsShadowRenderingFrameGraph::castShadowsLayer
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
Definition: qgsshadowrenderingframegraph.h:77
QgsWindow3DEngine::setFrustumCullingEnabled
void setFrustumCullingEnabled(bool enabled) override
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...
Definition: qgswindow3dengine.cpp:68
QgsWindow3DEngine::requestCaptureImage
void requestCaptureImage() override
Starts a request for an image rendered by the engine.
Definition: qgswindow3dengine.cpp:46
QgsWindow3DEngine::window
QWindow * window()
Returns the internal 3D window where all the rendered output is displayed.
Definition: qgswindow3dengine.cpp:41
QgsAbstract3DEngine::imageCaptured
void imageCaptured(const QImage &image)
Emitted after a call to requestCaptureImage() to return the captured image.
QgsWindow3DEngine::renderSettings
Qt3DRender::QRenderSettings * renderSettings() override
Returns access to the engine's render settings (the frame graph can be accessed from here)
Definition: qgswindow3dengine.cpp:82
QgsShadowRenderingFrameGraph
3 Container class that holds different objects related to shadow rendering
Definition: qgsshadowrenderingframegraph.h:57
QgsWindow3DEngine::setRootEntity
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
Definition: qgswindow3dengine.cpp:74
QgsShadowRenderingFrameGraph::forwardRenderLayer
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
Definition: qgsshadowrenderingframegraph.h:79
qgswindow3dengine.h
QgsShadowRenderingFrameGraph::renderCapture
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
Definition: qgsshadowrenderingframegraph.h:91
QgsAbstract3DEngine
3 Base class for 3D engine implementation.
Definition: qgsabstract3dengine.h:58
QgsWindow3DEngine::surface
QSurface * surface() const override
Returns the surface of the engine.
Definition: qgswindow3dengine.cpp:97
QgsWindow3DEngine::size
QSize size() const override
Returns size of the engine's rendering area in pixels.
Definition: qgswindow3dengine.cpp:92
QgsShadowRenderingFrameGraph::setFrustumCullingEnabled
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.cpp:334
QgsWindow3DEngine::camera
Qt3DRender::QCamera * camera() override
Returns pointer to the engine's camera entity.
Definition: qgswindow3dengine.cpp:87
QgsShadowRenderingFrameGraph::getFrameGraphRoot
Qt3DRender::QFrameGraphNode * getFrameGraphRoot()
Returns the root of the frame graph object.
Definition: qgsshadowrenderingframegraph.h:63
QgsWindow3DEngine::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether shadow rendering is enabled.
Definition: qgswindow3dengine.cpp:57
QgsShadowRenderingFrameGraph::setClearColor
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Definition: qgsshadowrenderingframegraph.cpp:306
QgsShadowRenderingFrameGraph::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.cpp:311
QgsWindow3DEngine::setClearColor
void setClearColor(const QColor &color) override
Sets background color of the scene.
Definition: qgswindow3dengine.cpp:63