@@ -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 ;
@@ -458,30 +443,6 @@ class GlobeSurfaceTileProvider {
458443 ) ;
459444 vectorProvider . makeClean ( ) ;
460445
461- // Similarly, for clipping polygons, re-request data as needed
462- if ( defined ( clippingPolygons ) ) {
463- this . _quadtree . forEachRenderedTile (
464- /** @param {QuadtreeTile } tile */
465- ( tile ) => {
466- if ( ! tile . isClipped ) {
467- return ;
468- }
469-
470- const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
471- // The surface tile's clipping polygon data is cleared above whenever the clipping polygon collection changes.
472- if ( defined ( surfaceTile . clippingPolygonData ) ) {
473- return ;
474- }
475-
476- surfaceTile . clippingPolygonData =
477- clippingPolygons . requestRectangleData (
478- tile . rectangle ,
479- frameState . context ,
480- ) ;
481- } ,
482- ) ;
483- }
484-
485446 // Add credits for terrain and imagery providers.
486447 updateCredits ( this , frameState ) ;
487448
@@ -627,6 +588,10 @@ class GlobeSurfaceTileProvider {
627588 ) ;
628589 }
629590
591+ if ( this . _clippingPolygonsDirty ) {
592+ releaseClippingPolygonData ( this ) ;
593+ }
594+
630595 // Add the tile render commands to the command list, sorted by texture count.
631596 const tilesToRenderByTextureCount = this . _tilesToRenderByTextureCount ;
632597 for (
@@ -647,6 +612,7 @@ class GlobeSurfaceTileProvider {
647612 ) {
648613 const tile = tilesToRender [ tileIndex ] ;
649614 const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
615+ updateTileClippingPolygonData ( this , tile , surfaceTile , frameState ) ;
650616 const tileBoundingRegion = surfaceTile . tileBoundingRegion ;
651617 addDrawCommandsForTile ( this , tile , frameState ) ;
652618 frameState . minimumTerrainHeight = Math . min (
@@ -1450,6 +1416,60 @@ function sortTileImageryByLayerIndex(a, b) {
14501416 return aImagery . imageryLayer . _layerIndex - bImagery . imageryLayer . _layerIndex ;
14511417}
14521418
1419+ /**
1420+ * Releases cached clipping polygon data on all loaded tiles so it is rebuilt
1421+ * against the current collection, and clears the dirty flag.
1422+ * @param {GlobeSurfaceTileProvider } tileProvider
1423+ * @ignore
1424+ */
1425+ function releaseClippingPolygonData ( tileProvider ) {
1426+ tileProvider . _quadtree . forEachLoadedTile (
1427+ /** @param {QuadtreeTile } tile */
1428+ function ( tile ) {
1429+ const surfaceTile = /** @type {GlobeSurfaceTile } */ ( tile . data ) ;
1430+ if ( ! defined ( surfaceTile ?. clippingPolygonData ) ) {
1431+ return ;
1432+ }
1433+
1434+ ClippingPolygonCollection . releaseRectangleData (
1435+ surfaceTile . clippingPolygonData ,
1436+ ) ;
1437+ surfaceTile . clippingPolygonData = undefined ;
1438+ } ,
1439+ ) ;
1440+ tileProvider . _clippingPolygonsDirty = false ;
1441+ }
1442+
1443+ /**
1444+ * Builds clipping polygon data for a tile about to be rendered, unless it is
1445+ * unclipped or its data was already built this frame.
1446+ * @param {GlobeSurfaceTileProvider } tileProvider
1447+ * @param {QuadtreeTile } tile
1448+ * @param {GlobeSurfaceTile } surfaceTile
1449+ * @param {FrameState } frameState
1450+ * @ignore
1451+ */
1452+ function updateTileClippingPolygonData (
1453+ tileProvider ,
1454+ tile ,
1455+ surfaceTile ,
1456+ frameState ,
1457+ ) {
1458+ const clippingPolygons = tileProvider . _clippingPolygons ;
1459+ if (
1460+ ! defined ( clippingPolygons ) ||
1461+ ! tile . isClipped ||
1462+ defined ( surfaceTile . clippingPolygonData )
1463+ ) {
1464+ return ;
1465+ }
1466+
1467+ surfaceTile . clippingPolygonData = clippingPolygons . requestRectangleData (
1468+ tile . rectangle ,
1469+ frameState . context ,
1470+ ) ;
1471+ }
1472+
14531473/**
14541474 * @param {GlobeSurfaceTileProvider } surface
14551475 * @param {FrameState } frameState
0 commit comments