Skip to content
Permalink
Browse files

Fix after review / Travis fixes

  • Loading branch information
wonder-sk committed Jul 19, 2018
1 parent 89d3fda commit 3d4f5bb2571a2bfa48ca0b70b3d49610cd4ff1fb
@@ -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 ) );
@@ -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() )
{
@@ -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 )
{
@@ -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
@@ -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();
@@ -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

@@ -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
@@ -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 );
};

@@ -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)
@@ -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.
@@ -85,6 +84,7 @@ QgsOffscreen3DEngine::QgsOffscreen3DEngine()
QgsOffscreen3DEngine::~QgsOffscreen3DEngine()
{
delete mAspectEngine;
delete mOffscreenSurface;
}

void QgsOffscreen3DEngine::setSize( const QSize &s )
@@ -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 );

@@ -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.
@@ -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

@@ -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;
@@ -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;
@@ -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;

@@ -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>
@@ -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;

0 comments on commit 3d4f5bb

Please sign in to comment.
You can’t perform that action at this time.