Skip to content

Commit

Permalink
qgs3dutils: Factor out culling mode enum conversion
Browse files Browse the repository at this point in the history
This will be used by `QgsMesh3DMaterial` in the next commmit.
  • Loading branch information
ptitjano authored and nyalldawson committed Oct 6, 2023
1 parent af3bab4 commit 66a8120
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
12 changes: 12 additions & 0 deletions src/3d/qgs3dutils.cpp
Expand Up @@ -890,3 +890,15 @@ void Qgs3DUtils::computeBoundingBoxNearFarPlanes( const QgsAABB &bbox, const QMa
ffar = std::max( ffar, dst );
}
}

Qt3DRender::QCullFace::CullingMode Qgs3DUtils::qt3DcullingMode( Qgs3DTypes::CullingMode mode )
{
switch ( mode )
{
case Qgs3DTypes::NoCulling: return Qt3DRender::QCullFace::NoCulling;
case Qgs3DTypes::Front: return Qt3DRender::QCullFace::Front;
case Qgs3DTypes::Back: return Qt3DRender::QCullFace::Back;
case Qgs3DTypes::FrontAndBack: return Qt3DRender::QCullFace::FrontAndBack;
}
return Qt3DRender::QCullFace::NoCulling;
}
10 changes: 10 additions & 0 deletions src/3d/qgs3dutils.h
Expand Up @@ -40,6 +40,7 @@ namespace Qt3DExtras

#include <QSize>
#include <Qt3DRender/QCamera>
#include <Qt3DRender/QCullFace>

#include <memory>

Expand Down Expand Up @@ -295,6 +296,15 @@ class _3D_EXPORT Qgs3DUtils
* \since QGIS 3.34
*/
static void computeBoundingBoxNearFarPlanes( const QgsAABB &bbox, const QMatrix4x4 &viewMatrix, float &fnear, float &ffar );

/**
* Converts Qgs3DTypes::CullingMode \a mode into its Qt3D equivalent.
*
* \param mode culling mode
*
* \since QGIS 3.34
*/
static Qt3DRender::QCullFace::CullingMode qt3DcullingMode( Qgs3DTypes::CullingMode mode );
};

#endif // QGS3DUTILS_H
15 changes: 1 addition & 14 deletions src/3d/symbols/qgspolygon3dsymbol_p.cpp
Expand Up @@ -286,19 +286,6 @@ void QgsPolygon3DSymbolHandler::makeEntity( Qt3DCore::QEntity *parent, const Qgs
// cppcheck-suppress memleak
}


static Qt3DRender::QCullFace::CullingMode _qt3DcullingMode( Qgs3DTypes::CullingMode mode )
{
switch ( mode )
{
case Qgs3DTypes::NoCulling: return Qt3DRender::QCullFace::NoCulling;
case Qgs3DTypes::Front: return Qt3DRender::QCullFace::Front;
case Qgs3DTypes::Back: return Qt3DRender::QCullFace::Back;
case Qgs3DTypes::FrontAndBack: return Qt3DRender::QCullFace::FrontAndBack;
}
return Qt3DRender::QCullFace::NoCulling;
}

// front/back side culling
static void applyCullingMode( Qgs3DTypes::CullingMode cullingMode, Qt3DRender::QMaterial *material )
{
Expand All @@ -309,7 +296,7 @@ static void applyCullingMode( Qgs3DTypes::CullingMode cullingMode, Qt3DRender::Q
for ( auto rpit = renderPasses.begin(); rpit != renderPasses.end(); ++rpit )
{
Qt3DRender::QCullFace *cullFace = new Qt3DRender::QCullFace;
cullFace->setMode( _qt3DcullingMode( cullingMode ) );
cullFace->setMode( Qgs3DUtils::qt3DcullingMode( cullingMode ) );
( *rpit )->addRenderState( cullFace );
}
}
Expand Down

0 comments on commit 66a8120

Please sign in to comment.