@@ -413,21 +413,6 @@ class GlobeSurfaceTileProvider {
413413 ) ;
414414 }
415415
416- const clippingPolygons = this . _clippingPolygons ;
417- if ( defined ( clippingPolygons ) && this . _clippingPolygonsDirty ) {
418- this . _quadtree . forEachLoadedTile ( ( tile ) => {
419- const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
420- if ( defined ( surfaceTile ?. clippingPolygonData ) ) {
421- ClippingPolygonCollection . releaseRectangleData (
422- surfaceTile . clippingPolygonData ,
423- ) ;
424- surfaceTile . clippingPolygonData = undefined ;
425- }
426- } ) ;
427-
428- this . _clippingPolygonsDirty = false ;
429- }
430-
431416 // Record regions dirtied by changed collections, re-bake overlapping
432417 // tiles, and build vector data for new surface tiles.
433418 const vectorProvider = this . _vectorProvider ;
@@ -457,30 +442,6 @@ class GlobeSurfaceTileProvider {
457442 ) ;
458443 vectorProvider . makeClean ( ) ;
459444
460- // Similarly, for clipping polygons, re-request data as needed
461- if ( defined ( clippingPolygons ) ) {
462- this . _quadtree . forEachRenderedTile (
463- /** @param {QuadtreeTile } tile */
464- ( tile ) => {
465- if ( ! tile . isClipped ) {
466- return ;
467- }
468-
469- const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
470- // The surface tile's clipping polygon data is cleared above whenever the clipping polygon collection changes.
471- if ( defined ( surfaceTile . clippingPolygonData ) ) {
472- return ;
473- }
474-
475- surfaceTile . clippingPolygonData =
476- clippingPolygons . requestRectangleData (
477- tile . rectangle ,
478- frameState . context ,
479- ) ;
480- } ,
481- ) ;
482- }
483-
484445 // Add credits for terrain and imagery providers.
485446 updateCredits ( this , frameState ) ;
486447
@@ -626,6 +587,10 @@ class GlobeSurfaceTileProvider {
626587 ) ;
627588 }
628589
590+ if ( this . _clippingPolygonsDirty ) {
591+ releaseClippingPolygonData ( this ) ;
592+ }
593+
629594 // Add the tile render commands to the command list, sorted by texture count.
630595 const tilesToRenderByTextureCount = this . _tilesToRenderByTextureCount ;
631596 for (
@@ -646,6 +611,7 @@ class GlobeSurfaceTileProvider {
646611 ) {
647612 const tile = tilesToRender [ tileIndex ] ;
648613 const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
614+ updateTileClippingPolygonData ( this , tile , surfaceTile , frameState ) ;
649615 const tileBoundingRegion = surfaceTile . tileBoundingRegion ;
650616 addDrawCommandsForTile ( this , tile , frameState ) ;
651617 frameState . minimumTerrainHeight = Math . min (
@@ -1415,6 +1381,60 @@ function sortTileImageryByLayerIndex(a, b) {
14151381 return aImagery . imageryLayer . _layerIndex - bImagery . imageryLayer . _layerIndex ;
14161382}
14171383
1384+ /**
1385+ * Releases cached clipping polygon data on all loaded tiles so it is rebuilt
1386+ * against the current collection, and clears the dirty flag.
1387+ * @param {GlobeSurfaceTileProvider } tileProvider
1388+ * @ignore
1389+ */
1390+ function releaseClippingPolygonData ( tileProvider ) {
1391+ tileProvider . _quadtree . forEachLoadedTile (
1392+ /** @param {QuadtreeTile } tile */
1393+ function ( tile ) {
1394+ const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
1395+ if ( ! defined ( surfaceTile ?. clippingPolygonData ) ) {
1396+ return ;
1397+ }
1398+
1399+ ClippingPolygonCollection . releaseRectangleData (
1400+ surfaceTile . clippingPolygonData ,
1401+ ) ;
1402+ surfaceTile . clippingPolygonData = undefined ;
1403+ } ,
1404+ ) ;
1405+ tileProvider . _clippingPolygonsDirty = false ;
1406+ }
1407+
1408+ /**
1409+ * Builds clipping polygon data for a tile about to be rendered, unless it is
1410+ * unclipped or its data was already built this frame.
1411+ * @param {GlobeSurfaceTileProvider } tileProvider
1412+ * @param {QuadtreeTile } tile
1413+ * @param {GlobeSurfaceTile } surfaceTile
1414+ * @param {FrameState } frameState
1415+ * @ignore
1416+ */
1417+ function updateTileClippingPolygonData (
1418+ tileProvider ,
1419+ tile ,
1420+ surfaceTile ,
1421+ frameState ,
1422+ ) {
1423+ const clippingPolygons = tileProvider . _clippingPolygons ;
1424+ if (
1425+ ! defined ( clippingPolygons ) ||
1426+ ! tile . isClipped ||
1427+ defined ( surfaceTile . clippingPolygonData )
1428+ ) {
1429+ return ;
1430+ }
1431+
1432+ surfaceTile . clippingPolygonData = clippingPolygons . requestRectangleData (
1433+ tile . rectangle ,
1434+ frameState . context ,
1435+ ) ;
1436+ }
1437+
14181438/**
14191439 * @param {GlobeSurfaceTileProvider } surface
14201440 * @param {FrameState } frameState
0 commit comments