Skip to content

Commit

Permalink
change to using QSize
Browse files Browse the repository at this point in the history
  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Jan 23, 2021
1 parent 0c4c3a6 commit a4c180a
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/3d/qgsabstract3dengine.h
Expand Up @@ -77,6 +77,8 @@ class _3D_EXPORT QgsAbstract3DEngine : public QObject
virtual Qt3DRender::QCamera *camera() = 0;
//! Returns size of the engine's rendering area in pixels
virtual QSize size() const = 0;
//! Sets the size of the rendering area (in pixels)
virtual void setSize( QSize s ) = 0;

/**
* Starts a request for an image rendered by the engine.
Expand Down
3 changes: 1 addition & 2 deletions src/3d/qgsoffscreen3dengine.h
Expand Up @@ -68,8 +68,7 @@ class _3D_EXPORT QgsOffscreen3DEngine : public QgsAbstract3DEngine
QgsOffscreen3DEngine();
~QgsOffscreen3DEngine() override;

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

void setClearColor( const QColor &color ) override;
void setFrustumCullingEnabled( bool enabled ) override;
Expand Down
22 changes: 10 additions & 12 deletions src/3d/qgsshadowrenderingframegraph.cpp
Expand Up @@ -45,8 +45,8 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRende
mRenderCapture = new Qt3DRender::QRenderCapture( mForwardRenderLayerFilter );

mForwardColorTexture = new Qt3DRender::QTexture2D;
mForwardColorTexture->setWidth( mWidth );
mForwardColorTexture->setHeight( mWidth );
mForwardColorTexture->setWidth( mSize.width() );
mForwardColorTexture->setHeight( mSize.height() );
mForwardColorTexture->setFormat( Qt3DRender::QTexture2D::TextureFormat::RGBA16F );
mForwardColorTexture->setGenerateMipMaps( false );
mForwardColorTexture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
Expand All @@ -55,8 +55,8 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRende
mForwardColorTexture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::ClampToEdge );

mForwardDepthTexture = new Qt3DRender::QTexture2D;
mForwardDepthTexture->setWidth( mWidth );
mForwardDepthTexture->setHeight( mHeight );
mForwardDepthTexture->setWidth( mSize.width() );
mForwardDepthTexture->setHeight( mSize.height() );
mForwardDepthTexture->setFormat( Qt3DRender::QTexture2D::TextureFormat::DepthFormat );
mForwardDepthTexture->setGenerateMipMaps( false );
mForwardDepthTexture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
Expand Down Expand Up @@ -137,11 +137,10 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructPostprocessi
return mPostprocessPassLayerFilter;
}

QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph( QWindow *window, int width, int height, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root )
QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph( QWindow *window, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root )
: Qt3DCore::QEntity( root )
{
mWidth = width;
mHeight = height;
mSize = s;

mRootEntity = root;
mMainCamera = mainCamera;
Expand Down Expand Up @@ -404,10 +403,9 @@ void QgsShadowRenderingFrameGraph::setupDepthMapDebugging( bool enabled, Qt::Cor
}
}

void QgsShadowRenderingFrameGraph::setSize( int width, int height )
void QgsShadowRenderingFrameGraph::setSize( QSize s )
{
mWidth = width;
mHeight = height;
mForwardColorTexture->setSize( mWidth, mHeight );
mForwardDepthTexture->setSize( mWidth, mHeight );
mSize = s;
mForwardColorTexture->setSize( mSize.width(), mSize.height() );
mForwardDepthTexture->setSize( mSize.width(), mSize.height() );
}
7 changes: 3 additions & 4 deletions src/3d/qgsshadowrenderingframegraph.h
Expand Up @@ -57,7 +57,7 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
{
public:
//! Constructor
QgsShadowRenderingFrameGraph( QWindow *window, int width, int height, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
QgsShadowRenderingFrameGraph( QWindow *window, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );

//! Returns the root of the frame graph object
Qt3DRender::QFrameGraphNode *getFrameGraphRoot() { return mRenderSurfaceSelector; }
Expand Down Expand Up @@ -123,7 +123,7 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
//! Sets the depth map debugging view port
void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
//! Sets the size of the buffers used for rendering
void setSize( int width, int height );
void setSize( QSize s );
private:
Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
Qt3DRender::QViewport *mMainViewPort = nullptr;
Expand Down Expand Up @@ -161,8 +161,7 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
float mShadowBias = 0.00001f;
int mShadowMapResolution = 2048;

int mWidth = 1024;
int mHeight = 768;
QSize mSize = QSize( 1024, 768 );

bool mEyeDomeLightingEnabled = false;
double mEyeDomeLightingStrength = 1000.0;
Expand Down
17 changes: 12 additions & 5 deletions src/3d/qgswindow3dengine.cpp
Expand Up @@ -30,7 +30,7 @@ QgsWindow3DEngine::QgsWindow3DEngine( QObject *parent )
mRoot = new Qt3DCore::QEntity;
mWindow3D->setRootEntity( mRoot );

mShadowRenderingFrameGraph = new QgsShadowRenderingFrameGraph( mWindow3D, 1024, 768, mWindow3D->camera(), mRoot );
mShadowRenderingFrameGraph = new QgsShadowRenderingFrameGraph( mWindow3D, QSize( 1024, 768 ), mWindow3D->camera(), mRoot );

mWindow3D->setActiveFrameGraph( mShadowRenderingFrameGraph->getFrameGraphRoot() );

Expand Down Expand Up @@ -99,9 +99,16 @@ QSurface *QgsWindow3DEngine::surface() const
return mWindow3D;
}

void QgsWindow3DEngine::setSize( int width, int height )
void QgsWindow3DEngine::setSize( QSize s )
{
mWindow3D->setWidth( width );
mWindow3D->setHeight( height );
mShadowRenderingFrameGraph->setSize( width, height );
mSize = s;

// mTexture->setSize( mSize.width(), mSize.height() );
// mDepthTexture->setSize( mSize.width(), mSize.height() );
// mSurfaceSelector->setExternalRenderTargetSize( mSize );

mWindow3D->setWidth( mSize.width() );
mWindow3D->setHeight( mSize.height() );
mShadowRenderingFrameGraph->setSize( mSize );
camera()->setAspectRatio( float( mSize.width() ) / float( mSize.height() ) );
}
4 changes: 2 additions & 2 deletions src/3d/qgswindow3dengine.h
Expand Up @@ -78,8 +78,7 @@ class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine
QSize size() const override;
QSurface *surface() const override;

//! Sets the size of the window (useful to fix frame graph parameters)
void setSize( int width, int height );
void setSize( QSize s ) override;
private:
//! 3D window with all the 3D magic inside
Qt3DExtras::Qt3DWindow *mWindow3D = nullptr;
Expand All @@ -91,6 +90,7 @@ class _3D_EXPORT QgsWindow3DEngine : public QgsAbstract3DEngine
Qt3DCore::QEntity *mSceneRoot = nullptr;

QgsPreviewQuad *mPreviewQuad = nullptr;
QSize mSize = QSize( 1024, 768 );
};

#endif // QGSWINDOW3DENGINE_H
7 changes: 3 additions & 4 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -62,8 +62,7 @@ Qgs3DMapCanvas::Qgs3DMapCanvas( QWidget *parent )
mEngine->window()->setCursor( Qt::OpenHandCursor );
mEngine->window()->installEventFilter( this );

if (QgsWindow3DEngine *window = dynamic_cast< QgsWindow3DEngine * >( mEngine ))
window->setSize( mContainer->width(), mContainer->height() );
mEngine->setSize( mContainer->size() );
}

Qgs3DMapCanvas::~Qgs3DMapCanvas()
Expand All @@ -86,8 +85,8 @@ void Qgs3DMapCanvas::resizeEvent( QResizeEvent *ev )

QRect viewportRect( QPoint( 0, 0 ), size() );
mScene->cameraController()->setViewport( viewportRect );
if (QgsWindow3DEngine *window = dynamic_cast< QgsWindow3DEngine * >( mEngine ))
window->setSize( viewportRect.width(), viewportRect.height() );

mEngine->setSize( viewportRect.size() );
}

void Qgs3DMapCanvas::setMap( Qgs3DMapSettings *map )
Expand Down

0 comments on commit a4c180a

Please sign in to comment.