Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix after review / Travis fixes
  • Loading branch information
wonder-sk committed Jul 19, 2018
1 parent 89d3fda commit 3d4f5bb
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/3d/qgs3dmapscene.cpp
Expand Up @@ -192,7 +192,7 @@ QgsChunkedEntity::SceneState _sceneState( QgsCameraController *cameraController

void Qgs3DMapScene::onCameraChanged()
{
Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
{
if ( entity->isEnabled() )
entity->update( _sceneState( mCameraController ) );
Expand Down Expand Up @@ -273,7 +273,7 @@ void Qgs3DMapScene::onFrameTriggered( float dt )
{
mCameraController->frameTriggered( dt );

Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
{
if ( entity->isEnabled() && entity->needsUpdate() )
{
Expand Down Expand Up @@ -475,7 +475,7 @@ void Qgs3DMapScene::updateSceneState()
return;
}

Q_FOREACH ( QgsChunkedEntity *entity, mChunkEntities )
for ( QgsChunkedEntity *entity : qgis::as_const( mChunkEntities ) )
{
if ( entity->isEnabled() && entity->pendingJobsCount() > 0 )
{
Expand Down
1 change: 1 addition & 0 deletions src/3d/qgs3dmapscene.h
Expand Up @@ -66,6 +66,7 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
//! Returns number of pending jobs of the terrain entity
int terrainPendingJobsCount() const;

//! Enumeration of possible states of the 3D scene
enum SceneState
{
Ready, //!< The scene is fully loaded/updated
Expand Down
3 changes: 1 addition & 2 deletions src/3d/qgs3dutils.cpp
Expand Up @@ -37,12 +37,11 @@ QImage Qgs3DUtils::captureSceneImage( QgsAbstract3DEngine &engine, Qgs3DMapScene
{
if ( scene->sceneState() == Qgs3DMapScene::Ready )
{
qDebug() << "loaded - requesting image";
engine.requestCaptureImage();
}
};

auto saveImageFcn = [&engine, &evLoop, &resImage]( const QImage & img )
auto saveImageFcn = [&evLoop, &resImage]( const QImage & img )
{
resImage = img;
evLoop.quit();
Expand Down
28 changes: 28 additions & 0 deletions src/3d/qgsabstract3dengine.h
@@ -1,3 +1,18 @@
/***************************************************************************
qgsabstract3dengine.h
--------------------------------------
Date : July 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSABSTRACT3DENGINE_H
#define QGSABSTRACT3DENGINE_H

Expand All @@ -20,6 +35,7 @@ namespace Qt3DRender
}

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

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

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

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

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

Expand Down
9 changes: 5 additions & 4 deletions src/3d/qgsoffscreen3dengine.cpp
Expand Up @@ -36,8 +36,6 @@

QgsOffscreen3DEngine::QgsOffscreen3DEngine()
{
mSize = QSize( 640, 480 );

// Set up the default OpenGL surface format.
QSurfaceFormat format;
format.setDepthBufferSize( 32 ); // TODO: or 24? (used by QWindow3D)
Expand Down Expand Up @@ -75,6 +73,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
createFrameGraph();

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

// Set the root entity of the engine. This causes the engine to begin running.
Expand All @@ -85,6 +84,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
QgsOffscreen3DEngine::~QgsOffscreen3DEngine()
{
delete mAspectEngine;
delete mOffscreenSurface;
}

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

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

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

// Create a node used for clearing the required buffers.
Expand Down
29 changes: 27 additions & 2 deletions src/3d/qgsoffscreen3dengine.h
@@ -1,3 +1,18 @@
/***************************************************************************
qgsoffscreen3dengine.h
--------------------------------------
Date : July 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSOFFSCREEN3DENGINE_H
#define QGSOFFSCREEN3DENGINE_H

Expand Down Expand Up @@ -34,13 +49,23 @@ namespace Qt3DLogic
}


/**
* \ingroup 3d
* Off-screen 3D engine implementation. It is useful for recording rendered 3D scenes of arbitrary size.
*
* \note While the on-screen 3D engine also allows capturing of images, its limitation is that
* the captured images are of the size of the on-screen window.
*
* \since QGIS 3.4
*/
class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
{
Q_OBJECT
public:
QgsOffscreen3DEngine();
~QgsOffscreen3DEngine();

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

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

private:

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

Expand Down
15 changes: 15 additions & 0 deletions src/3d/qgswindow3dengine.cpp
@@ -1,3 +1,18 @@
/***************************************************************************
qgswindow3dengine.cpp
--------------------------------------
Date : July 2018
Copyright : (C) 2018 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgswindow3dengine.h"

#include <Qt3DRender/QRenderCapture>
Expand Down
8 changes: 8 additions & 0 deletions src/3d/qgswindow3dengine.h
Expand Up @@ -32,12 +32,20 @@ namespace Qt3DExtras
class QWindow;


/**
* \ingroup 3d
* On-screen 3D engine: it creates OpenGL window (QWindow) and displays rendered 3D scene there.
* The window can be embedded into a QWidget-based application with QWidget::createWindowContainer().
*
* \since QGIS 3.4
*/
class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine
{
Q_OBJECT
public:
QgsWindow3DEngine();

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

void requestCaptureImage() override;
Expand Down

0 comments on commit 3d4f5bb

Please sign in to comment.