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;