Skip to content

Commit

Permalink
fix point rendering issue
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 a84f2a2 commit 0c4c3a6
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 12 deletions.
25 changes: 16 additions & 9 deletions src/3d/qgsshadowrenderingframegraph.cpp
Expand Up @@ -44,13 +44,9 @@ Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRende

mRenderCapture = new Qt3DRender::QRenderCapture( mForwardRenderLayerFilter );

// TODO: make the width and height change dynamically as the 3D viewer is resized
int width = 1024;
int height = 768;

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

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

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

mRootEntity = root;
mMainCamera = mainCamera;
mLightCamera = new Qt3DRender::QCamera;
Expand Down Expand Up @@ -404,3 +403,11 @@ void QgsShadowRenderingFrameGraph::setupDepthMapDebugging( bool enabled, Qt::Cor
}
}
}

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

//! Returns the root of the frame graph object
Qt3DRender::QFrameGraphNode *getFrameGraphRoot() { return mRenderSurfaceSelector; }
Expand Down Expand Up @@ -122,7 +122,8 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
//! 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 );
private:
Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
Qt3DRender::QViewport *mMainViewPort = nullptr;
Expand Down Expand Up @@ -160,6 +161,9 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
float mShadowBias = 0.00001f;
int mShadowMapResolution = 2048;

int mWidth = 1024;
int mHeight = 768;

bool mEyeDomeLightingEnabled = false;
double mEyeDomeLightingStrength = 1000.0;
int mEyeDomeLightingDistance = 1;
Expand Down
9 changes: 8 additions & 1 deletion 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, mWindow3D->camera(), mRoot );
mShadowRenderingFrameGraph = new QgsShadowRenderingFrameGraph( mWindow3D, 1024, 768, mWindow3D->camera(), mRoot );

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

Expand Down Expand Up @@ -98,3 +98,10 @@ QSurface *QgsWindow3DEngine::surface() const
{
return mWindow3D;
}

void QgsWindow3DEngine::setSize( int width, int height )
{
mWindow3D->setWidth( width );
mWindow3D->setHeight( height );
mShadowRenderingFrameGraph->setSize( width, height );
}
2 changes: 2 additions & 0 deletions src/3d/qgswindow3dengine.h
Expand Up @@ -78,6 +78,8 @@ 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 );
private:
//! 3D window with all the 3D magic inside
Qt3DExtras::Qt3DWindow *mWindow3D = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions src/app/3d/qgs3dmapcanvas.cpp
Expand Up @@ -61,6 +61,9 @@ 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() );
}

Qgs3DMapCanvas::~Qgs3DMapCanvas()
Expand All @@ -83,6 +86,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() );
}

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

0 comments on commit 0c4c3a6

Please sign in to comment.