QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  mFrameGraph = new QgsShadowRenderingFrameGraph( mWindow3D, QSize( 1024, 768 ), mWindow3D->camera(), mRoot );
35  mWindow3D->setActiveFrameGraph( mFrameGraph->frameGraphRoot() );
36 
37  // force switching to no shadow rendering
39 }
40 
42 {
43  return mWindow3D;
44 }
45 
46 Qt3DCore::QEntity *QgsWindow3DEngine::root() const
47 {
48  return mRoot;
49 }
50 
52 {
53  mShadowRenderingEnabled = enabled;
54  mFrameGraph->setShadowRenderingEnabled( mShadowRenderingEnabled );
55 }
56 
57 void QgsWindow3DEngine::setClearColor( const QColor &color )
58 {
59  mFrameGraph->setClearColor( color );
60 }
61 
63 {
64  // Not sure if this works properly
66 }
67 
68 void QgsWindow3DEngine::setRootEntity( Qt3DCore::QEntity *root )
69 {
70  mSceneRoot = root;
71  mSceneRoot->setParent( mRoot );
72  mSceneRoot->addComponent( mFrameGraph->forwardRenderLayer() );
73  mSceneRoot->addComponent( mFrameGraph->castShadowsLayer() );
74 }
75 
76 Qt3DRender::QRenderSettings *QgsWindow3DEngine::renderSettings()
77 {
78  return mWindow3D->renderSettings();
79 }
80 
81 Qt3DRender::QCamera *QgsWindow3DEngine::camera()
82 {
83  return mWindow3D->camera();
84 }
85 
87 {
88  return mWindow3D->size();
89 }
90 
91 QSurface *QgsWindow3DEngine::surface() const
92 {
93  return mWindow3D;
94 }
95 
97 {
98  mSize = s;
99 
100  mWindow3D->setWidth( mSize.width() );
101  mWindow3D->setHeight( mSize.height() );
102  mFrameGraph->setSize( mSize );
103  camera()->setAspectRatio( float( mSize.width() ) / float( mSize.height() ) );
104 }
QgsWindow3DEngine::QgsWindow3DEngine
QgsWindow3DEngine(QObject *parent=nullptr)
Constructor for QgsWindow3DEngine with the specified parent object.
Definition: qgswindow3dengine.cpp:25
QgsShadowRenderingFrameGraph::frameGraphRoot
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
Definition: qgsshadowrenderingframegraph.h:68
qgspreviewquad.h
QgsShadowRenderingFrameGraph::setSize
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Definition: qgsshadowrenderingframegraph.cpp:661
QgsShadowRenderingFrameGraph::castShadowsLayer
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
Definition: qgsshadowrenderingframegraph.h:82
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:62
QgsAbstract3DEngine::mFrameGraph
QgsShadowRenderingFrameGraph * mFrameGraph
Definition: qgsabstract3dengine.h:139
QgsWindow3DEngine::window
QWindow * window()
Returns the internal 3D window where all the rendered output is displayed.
Definition: qgswindow3dengine.cpp:41
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:76
QgsShadowRenderingFrameGraph
Container class that holds different objects related to shadow rendering.
Definition: qgsshadowrenderingframegraph.h:59
QgsWindow3DEngine::setRootEntity
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
Definition: qgswindow3dengine.cpp:68
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:84
qgswindow3dengine.h
QgsAbstract3DEngine
Base class for 3D engine implementation. A 3D engine is responsible for setting up rendering with Qt3...
Definition: qgsabstract3dengine.h:60
QgsWindow3DEngine::surface
QSurface * surface() const override
Returns the surface of the engine.
Definition: qgswindow3dengine.cpp:91
QgsWindow3DEngine::root
Qt3DCore::QEntity * root() const
Returns the root entity.
Definition: qgswindow3dengine.cpp:46
QgsWindow3DEngine::size
QSize size() const override
Returns size of the engine's rendering area in pixels.
Definition: qgswindow3dengine.cpp:86
QgsShadowRenderingFrameGraph::setFrustumCullingEnabled
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.cpp:593
QgsWindow3DEngine::camera
Qt3DRender::QCamera * camera() override
Returns pointer to the engine's camera entity.
Definition: qgswindow3dengine.cpp:81
QgsShadowRenderingFrameGraph::setRenderCaptureEnabled
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
Definition: qgsshadowrenderingframegraph.cpp:673
QgsWindow3DEngine::setSize
void setSize(QSize s) override
Sets the size of the rendering area (in pixels)
Definition: qgswindow3dengine.cpp:96
QgsWindow3DEngine::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether shadow rendering is enabled.
Definition: qgswindow3dengine.cpp:51
QgsShadowRenderingFrameGraph::setClearColor
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Definition: qgsshadowrenderingframegraph.cpp:565
QgsShadowRenderingFrameGraph::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.cpp:570
QgsWindow3DEngine::setClearColor
void setClearColor(const QColor &color) override
Sets background color of the scene.
Definition: qgswindow3dengine.cpp:57