18#include <QOffscreenSurface>
19#include <QSurfaceFormat>
20#include <QOpenGLFunctions>
22#include <Qt3DCore/QAspectEngine>
23#include <Qt3DLogic/QLogicAspect>
24#include <Qt3DRender/QCamera>
25#include <Qt3DRender/QCameraSelector>
26#include <Qt3DRender/QClearBuffers>
27#include <Qt3DRender/QRenderAspect>
28#include <Qt3DRender/QRenderCapture>
29#include <Qt3DRender/QRenderSettings>
30#include <Qt3DRender/QRenderTarget>
31#include <Qt3DRender/QRenderTargetOutput>
32#include <Qt3DRender/QRenderTargetSelector>
33#include <Qt3DRender/QRenderSurfaceSelector>
34#include <Qt3DRender/QTexture>
35#include <Qt3DRender/QViewport>
36#include <QtGui/QOpenGLContext>
41 QSurfaceFormat format;
47 format.setRenderableType( QSurfaceFormat::OpenGLES );
49 if ( QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL )
51 format.setVersion( 4, 3 );
52 format.setProfile( QSurfaceFormat::CoreProfile );
56 format.setMajorVersion( 3 );
57 format.setDepthBufferSize( 32 );
58 format.setSamples( 8 );
59 QSurfaceFormat::setDefaultFormat( format );
62 mCamera =
new Qt3DRender::QCamera;
63 mCamera->lens()->setPerspectiveProjection( 45.0f,
float( mSize.width() ) /
float( mSize.height() ), 0.1f, 1000.0f );
64 mCamera->setPosition( QVector3D( 0, 0, 20.0f ) );
65 mCamera->setUpVector( QVector3D( 0, 1, 0 ) );
66 mCamera->setViewCenter( QVector3D( 0, 0, 0 ) );
69 mAspectEngine =
new Qt3DCore::QAspectEngine();
71#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
72 mRenderAspect =
new Qt3DRender::QRenderAspect( Qt3DRender::QRenderAspect::Threaded );
74 mRenderAspect =
new Qt3DRender::QRenderAspect();
77 mLogicAspect =
new Qt3DLogic::QLogicAspect();
79 mAspectEngine->registerAspect( mRenderAspect );
80 mAspectEngine->registerAspect( mLogicAspect );
87 mRoot =
new Qt3DCore::QEntity;
88 mRenderSettings =
new Qt3DRender::QRenderSettings( mRoot );
89 mRoot->addComponent( mRenderSettings );
91 mCamera->setParent( mRoot );
95 mOffscreenSurface =
new QOffscreenSurface();
96 mOffscreenSurface->setFormat( QSurfaceFormat::defaultFormat() );
97 mOffscreenSurface->create();
107 mAspectEngine->setRootEntity( Qt3DCore::QEntityPtr( mRoot ) );
113 delete mAspectEngine;
114 delete mOffscreenSurface;
122 mCamera->setAspectRatio(
float( mSize.width() ) /
float( mSize.height() ) );
141 mSceneRoot->setParent(
static_cast<Qt3DCore::QNode *
>(
nullptr ) );
146 mSceneRoot->setParent( mRoot );
153 return mRenderSettings;
168 return mOffscreenSurface;
void sizeChanged()
Emitted after a call to setSize()
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.
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
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::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
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.