30 QgsTerrainTextureGenerator::QgsTerrainTextureGenerator(
const Qgs3DMapSettings &map )
33 , mTextureSize( QSize( mMap.mapTileResolution(), mMap.mapTileResolution() ) )
37 int QgsTerrainTextureGenerator::render(
const QgsRectangle &extent, QgsChunkNodeId tileId,
const QString &debugText )
40 mapSettings.setExtent( extent );
42 QList<QgsMapLayer *> layers = mMap.layers();
43 QList<QgsMapLayer *> toBeRenderedLayers;
46 if ( l->renderer3D() ==
nullptr )
47 toBeRenderedLayers.push_back( l );
49 mapSettings.setLayers( toBeRenderedLayers );
51 QgsEventTracing::addEvent( QgsEventTracing::AsyncBegin, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), tileId.text() );
57 jobData.jobId = ++mLastJobId;
58 jobData.tileId = tileId;
60 jobData.extent = extent;
61 jobData.debugText = debugText;
63 mJobs.insert( job, jobData );
70 void QgsTerrainTextureGenerator::cancelJob(
int jobId )
72 for (
const JobData &jd : std::as_const( mJobs ) )
74 if ( jd.jobId == jobId )
77 jd.job->cancelWithoutBlocking();
79 jd.job->deleteLater();
80 mJobs.remove( jd.job );
84 Q_ASSERT(
false &&
"requested job ID does not exist!" );
87 void QgsTerrainTextureGenerator::waitForFinished()
91 QVector<QgsMapRendererSequentialJob *> toBeDeleted;
94 mapJob->waitForFinished();
95 JobData jobData = mJobs.value( mapJob );
96 toBeDeleted.push_back( mapJob );
98 QImage img = mapJob->renderedImage();
100 if ( mMap.showTerrainTilesInfo() )
104 p.setPen( Qt::white );
105 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
106 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
111 emit tileReady( jobData.jobId, img );
116 mJobs.remove( mapJob );
117 mapJob->deleteLater();
121 void QgsTerrainTextureGenerator::onRenderingFinished()
125 Q_ASSERT( mJobs.contains( mapJob ) );
126 JobData jobData = mJobs.value( mapJob );
130 if ( mMap.showTerrainTilesInfo() )
134 p.setPen( Qt::white );
135 p.drawRect( 0, 0, img.width() - 1, img.height() - 1 );
136 p.drawText( img.rect(), jobData.debugText, QTextOption( Qt::AlignCenter ) );
140 mapJob->deleteLater();
141 mJobs.remove( mapJob );
145 QgsEventTracing::addEvent( QgsEventTracing::AsyncEnd, QStringLiteral(
"3D" ), QStringLiteral(
"Texture" ), jobData.tileId.text() );
148 emit tileReady( jobData.jobId, img );
165 QString mapThemeName = mMap.terrainMapTheme();
166 if ( mapThemeName.isEmpty() || !mapThemes || !mapThemes->
hasMapTheme( mapThemeName ) )