Skip to content

Commit 89d3fda

Browse files
committedJul 19, 2018
Allow offscreen image size configuration
1 parent 6884053 commit 89d3fda

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed
 

‎src/3d/qgsoffscreen3dengine.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
#include <Qt3DRender/QTexture>
3434
#include <Qt3DRender/QViewport>
3535

36-
// TODO: set size
37-
// TODO: destructor
3836

3937
QgsOffscreen3DEngine::QgsOffscreen3DEngine()
4038
{
@@ -48,7 +46,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
4846

4947
// Set up a camera to point at the shapes.
5048
mCamera = new Qt3DRender::QCamera;
51-
mCamera->lens()->setPerspectiveProjection( 45.0f, 1200.0f / 800.0f, 0.1f, 1000.0f );
49+
mCamera->lens()->setPerspectiveProjection( 45.0f, float( mSize.width() ) / float( mSize.height() ), 0.1f, 1000.0f );
5250
mCamera->setPosition( QVector3D( 0, 0, 20.0f ) );
5351
mCamera->setUpVector( QVector3D( 0, 1, 0 ) );
5452
mCamera->setViewCenter( QVector3D( 0, 0, 0 ) );
@@ -84,6 +82,22 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
8482

8583
}
8684

85+
QgsOffscreen3DEngine::~QgsOffscreen3DEngine()
86+
{
87+
delete mAspectEngine;
88+
}
89+
90+
void QgsOffscreen3DEngine::setSize( const QSize &s )
91+
{
92+
mSize = s;
93+
94+
mTexture->setSize( mSize.width(), mSize.height() );
95+
mDepthTexture->setSize( mSize.width(), mSize.height() );
96+
mSurfaceSelector->setExternalRenderTargetSize( mSize );
97+
98+
mCamera->setAspectRatio( float( mSize.width() ) / float( mSize.height() ) );
99+
}
100+
87101
void QgsOffscreen3DEngine::setClearColor( const QColor &color )
88102
{
89103
mClearBuffers->setClearColor( color );

‎src/3d/qgsoffscreen3dengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
3939
Q_OBJECT
4040
public:
4141
QgsOffscreen3DEngine();
42+
~QgsOffscreen3DEngine();
43+
44+
void setSize( const QSize &s );
4245

4346
void setClearColor( const QColor &color ) override;
4447
void setFrustumCullingEnabled( bool enabled ) override;

0 commit comments

Comments
 (0)
Please sign in to comment.