19 #include <QOffscreenSurface>
20 #include <QSurfaceFormat>
21 #include <QOpenGLFunctions>
23 #include <Qt3DCore/QAspectEngine>
24 #include <Qt3DLogic/QLogicAspect>
25 #include <Qt3DRender/QCamera>
26 #include <Qt3DRender/QCameraSelector>
27 #include <Qt3DRender/QClearBuffers>
28 #include <Qt3DRender/QRenderAspect>
29 #include <Qt3DRender/QRenderCapture>
30 #include <Qt3DRender/QRenderSettings>
31 #include <Qt3DRender/QRenderTarget>
32 #include <Qt3DRender/QRenderTargetOutput>
33 #include <Qt3DRender/QRenderTargetSelector>
34 #include <Qt3DRender/QRenderSurfaceSelector>
35 #include <Qt3DRender/QTexture>
36 #include <Qt3DRender/QViewport>
37 #include <QtGui/QOpenGLContext>
42 QSurfaceFormat format;
48 format.setRenderableType( QSurfaceFormat::OpenGLES );
50 if ( QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL )
52 format.setVersion( 4, 3 );
53 format.setProfile( QSurfaceFormat::CoreProfile );
57 format.setMajorVersion( 3 );
58 format.setDepthBufferSize( 32 );
59 format.setSamples( 8 );
60 QSurfaceFormat::setDefaultFormat( format );
63 mCamera =
new Qt3DRender::QCamera;
64 mCamera->lens()->setPerspectiveProjection( 45.0f,
float( mSize.width() ) /
float( mSize.height() ), 0.1f, 1000.0f );
65 mCamera->setPosition( QVector3D( 0, 0, 20.0f ) );
66 mCamera->setUpVector( QVector3D( 0, 1, 0 ) );
67 mCamera->setViewCenter( QVector3D( 0, 0, 0 ) );
70 mAspectEngine =
new Qt3DCore::QAspectEngine();
71 mRenderAspect =
new Qt3DRender::QRenderAspect( Qt3DRender::QRenderAspect::Threaded );
72 mLogicAspect =
new Qt3DLogic::QLogicAspect();
74 mAspectEngine->registerAspect( mRenderAspect );
75 mAspectEngine->registerAspect( mLogicAspect );
82 mRoot =
new Qt3DCore::QEntity;
83 mRenderSettings =
new Qt3DRender::QRenderSettings( mRoot );
84 mRoot->addComponent( mRenderSettings );
86 mCamera->setParent( mRoot );
90 mOffscreenSurface =
new QOffscreenSurface();
91 mOffscreenSurface->setFormat( QSurfaceFormat::defaultFormat() );
92 mOffscreenSurface->create();
102 mAspectEngine->setRootEntity( Qt3DCore::QEntityPtr( mRoot ) );
108 delete mAspectEngine;
109 delete mOffscreenSurface;
117 mCamera->setAspectRatio(
float( mSize.width() ) /
float( mSize.height() ) );
135 mSceneRoot->setParent(
static_cast<Qt3DCore::QNode *
>(
nullptr ) );
140 mSceneRoot->setParent( mRoot );
147 return mRenderSettings;
162 return mOffscreenSurface;
QgsShadowRenderingFrameGraph * mFrameGraph
void setSize(QSize s) override
Sets the size of the rendering area (in pixels)
void setClearColor(const QColor &color) override
Sets background color of the scene.
QSize size() const override
Returns size of the engine's rendering area in pixels.
void setRootEntity(Qt3DCore::QEntity *root) override
Sets root entity of the 3D scene.
~QgsOffscreen3DEngine() override
void setFrustumCullingEnabled(bool enabled) override
Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities ...
Qt3DRender::QCamera * camera() override
Returns pointer to the engine's camera entity.
Qt3DRender::QRenderSettings * renderSettings() override
Returns access to the engine's render settings (the frame graph can be accessed from here)
QSurface * surface() const override
Returns the surface of the engine.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.