Skip to content

Commit 3d4f5bb

Browse files
committedJul 19, 2018
Fix after review / Travis fixes
1 parent 89d3fda commit 3d4f5bb

8 files changed

+88
-11
lines changed
 

‎src/3d/qgs3dmapscene.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ QgsChunkedEntity::SceneState _sceneState( QgsCameraController *cameraController
192192

193193
void Qgs3DMapScene::onCameraChanged()
194194
{
195-
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
195+
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
196196
{
197197
if ( entity->isEnabled() )
198198
entity->update( _sceneState( mCameraController ) );
@@ -273,7 +273,7 @@ void Qgs3DMapScene::onFrameTriggered( float dt )
273273
{
274274
mCameraController->frameTriggered( dt );
275275

276-
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
276+
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
277277
{
278278
if ( entity->isEnabled() && entity->needsUpdate() )
279279
{
@@ -475,7 +475,7 @@ void Qgs3DMapScene::updateSceneState()
475475
return;
476476
}
477477

478-
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
478+
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
479479
{
480480
if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
481481
{

‎src/3d/qgs3dmapscene.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
6666
//! Returns number of pending jobs of the terrain entity
6767
int terrainPendingJobsCount() const;
6868

69+
//! Enumeration of possible states of the 3D scene
6970
enum SceneState
7071
{
7172
Ready, //!< The scene is fully loaded/updated

‎src/3d/qgs3dutils.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ QImage Qgs3DUtils::captureSceneImage( QgsAbstract3DEngine &engine, Qgs3DMapScene
3737
{
3838
if ( scene->sceneState() == Qgs3DMapScene::Ready )
3939
{
40-
qDebug() << "loaded - requesting image";
4140
engine.requestCaptureImage();
4241
}
4342
};
4443

45-
auto saveImageFcn = [&engine, &evLoop, &resImage]( const QImage & img )
44+
auto saveImageFcn = [&evLoop, &resImage]( const QImage & img )
4645
{
4746
resImage = img;
4847
evLoop.quit();

‎src/3d/qgsabstract3dengine.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/***************************************************************************
2+
qgsabstract3dengine.h
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+
116
#ifndef QGSABSTRACT3DENGINE_H
217
#define QGSABSTRACT3DENGINE_H
318

@@ -20,6 +35,7 @@ namespace Qt3DRender
2035
}
2136

2237
/**
38+
* \ingroup 3d
2339
* Base class for 3D engine implementation. A 3D engine is responsible for setting up
2440
* rendering with Qt3D. This means mainly:
2541
* - creating Qt3D aspect engine and registering rendering aspect
@@ -36,17 +52,29 @@ class _3D_EXPORT QgsAbstract3DEngine : public QObject
3652
Q_OBJECT
3753
public:
3854

55+
//! Sets background color of the scene
3956
virtual void setClearColor( const QColor &color ) = 0;
57+
//! Sets whether frustum culling is enabled (this should make rendering faster by not rendering entities outside of camera's view)
4058
virtual void setFrustumCullingEnabled( bool enabled ) = 0;
59+
//! Sets root entity of the 3D scene
4160
virtual void setRootEntity( Qt3DCore::QEntity *root ) = 0;
4261

62+
//! Returns access to the engine's render settings (the frame graph can be accessed from here)
4363
virtual Qt3DRender::QRenderSettings *renderSettings() = 0;
64+
//! Returns pointer to the engine's camera entity
4465
virtual Qt3DRender::QCamera *camera() = 0;
66+
//! Returns size of the engine's rendering area in pixels
4567
virtual QSize size() const = 0;
4668

69+
/**
70+
* Starts a request for an image rendered by the engine.
71+
* The function does not block - when the rendered image is captured, it is returned in imageCaptured() signal.
72+
* Only one image reqeust can be active at a time.
73+
*/
4774
virtual void requestCaptureImage() = 0;
4875

4976
signals:
77+
//! Emitted after a call to requestCaptureImage() to return the captured image.
5078
void imageCaptured( const QImage &image );
5179
};
5280

‎src/3d/qgsoffscreen3dengine.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636

3737
QgsOffscreen3DEngine::QgsOffscreen3DEngine()
3838
{
39-
mSize = QSize( 640, 480 );
40-
4139
// Set up the default OpenGL surface format.
4240
QSurfaceFormat format;
4341
format.setDepthBufferSize( 32 ); // TODO: or 24? (used by QWindow3D)
@@ -75,6 +73,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
7573
createFrameGraph();
7674

7775
// Set this frame graph to be in use.
76+
// the render settings also sets itself as the parent of mSurfaceSelector
7877
mRenderSettings->setActiveFrameGraph( mSurfaceSelector );
7978

8079
// Set the root entity of the engine. This causes the engine to begin running.
@@ -85,6 +84,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
8584
QgsOffscreen3DEngine::~QgsOffscreen3DEngine()
8685
{
8786
delete mAspectEngine;
87+
delete mOffscreenSurface;
8888
}
8989

9090
void QgsOffscreen3DEngine::setSize( const QSize &s )
@@ -116,7 +116,7 @@ void QgsOffscreen3DEngine::createRenderTarget()
116116
// The lifetime of the objects created here is managed
117117
// automatically, as they become children of this object.
118118

119-
// Create a render target output for rendering colour.
119+
// Create a render target output for rendering color.
120120
mTextureOutput = new Qt3DRender::QRenderTargetOutput( mTextureTarget );
121121
mTextureOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
122122

@@ -161,7 +161,8 @@ void QgsOffscreen3DEngine::createFrameGraph()
161161
// Create a texture to render into. This acts as the buffer that
162162
// holds the rendered image.
163163
mRenderTargetSelector = new Qt3DRender::QRenderTargetSelector( mSurfaceSelector );
164-
createRenderTarget(); // new TextureRenderTarget(renderTargetSelector, size);
164+
createRenderTarget();
165+
// the target selector also sets itself as the parent of mTextureTarget
165166
mRenderTargetSelector->setTarget( mTextureTarget );
166167

167168
// Create a node used for clearing the required buffers.

‎src/3d/qgsoffscreen3dengine.h

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/***************************************************************************
2+
qgsoffscreen3dengine.h
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+
116
#ifndef QGSOFFSCREEN3DENGINE_H
217
#define QGSOFFSCREEN3DENGINE_H
318

@@ -34,13 +49,23 @@ namespace Qt3DLogic
3449
}
3550

3651

52+
/**
53+
* \ingroup 3d
54+
* Off-screen 3D engine implementation. It is useful for recording rendered 3D scenes of arbitrary size.
55+
*
56+
* \note While the on-screen 3D engine also allows capturing of images, its limitation is that
57+
* the captured images are of the size of the on-screen window.
58+
*
59+
* \since QGIS 3.4
60+
*/
3761
class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
3862
{
3963
Q_OBJECT
4064
public:
4165
QgsOffscreen3DEngine();
4266
~QgsOffscreen3DEngine();
4367

68+
//! Sets the size of the rendering area (in pixels)
4469
void setSize( const QSize &s );
4570

4671
void setClearColor( const QColor &color ) override;
@@ -59,7 +84,7 @@ class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
5984

6085
private:
6186

62-
QSize mSize;
87+
QSize mSize = QSize( 640, 480 );
6388
Qt3DRender::QCamera *mCamera = nullptr;
6489
QOffscreenSurface *mOffscreenSurface = nullptr;
6590
Qt3DRender::QRenderCaptureReply *mReply = nullptr;
@@ -68,7 +93,7 @@ class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
6893
Qt3DCore::QAspectEngine *mAspectEngine = nullptr; // The aspect engine, which holds the scene and related aspects.
6994
Qt3DRender::QRenderAspect *mRenderAspect = nullptr; // The render aspect, which deals with rendering the scene.
7095
Qt3DLogic::QLogicAspect *mLogicAspect = nullptr; // The logic aspect, which runs jobs to do with synchronising frames.
71-
Qt3DRender::QRenderSettings *mRenderSettings = nullptr; // The render settings, which control the general rendering behaviour.
96+
Qt3DRender::QRenderSettings *mRenderSettings = nullptr; // The render settings, which control the general rendering behavior.
7297
Qt3DCore::QNode *mSceneRoot = nullptr; // The scene root, which becomes a child of the engine's root entity.
7398
Qt3DCore::QEntity *mRoot = nullptr;
7499

‎src/3d/qgswindow3dengine.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
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+
116
#include "qgswindow3dengine.h"
217

318
#include <Qt3DRender/QRenderCapture>

‎src/3d/qgswindow3dengine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ namespace Qt3DExtras
3232
class QWindow;
3333

3434

35+
/**
36+
* \ingroup 3d
37+
* On-screen 3D engine: it creates OpenGL window (QWindow) and displays rendered 3D scene there.
38+
* The window can be embedded into a QWidget-based application with QWidget::createWindowContainer().
39+
*
40+
* \since QGIS 3.4
41+
*/
3542
class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine
3643
{
3744
Q_OBJECT
3845
public:
3946
QgsWindow3DEngine();
4047

48+
//! Returns the internal 3D window where all the rendered output is displayed
4149
QWindow *window();
4250

4351
void requestCaptureImage() override;

0 commit comments

Comments
 (0)