@@ -77,6 +77,7 @@ function DynamicEnvironmentMapManager(options) {
77
77
this . _sphericalHarmonicCoefficientsDirty = false ;
78
78
79
79
this . _shouldRegenerateShaders = false ;
80
+ this . _shouldReset = false ;
80
81
81
82
options = defaultValue ( options , defaultValue . EMPTY_OBJECT ) ;
82
83
@@ -251,7 +252,7 @@ Object.defineProperties(DynamicEnvironmentMapManager.prototype, {
251
252
}
252
253
253
254
this . _position = Cartesian3 . clone ( value , this . _position ) ;
254
- this . reset ( ) ;
255
+ this . _shouldReset = true ;
255
256
} ,
256
257
} ,
257
258
@@ -345,7 +346,7 @@ DynamicEnvironmentMapManager._updateCommandQueue = (frameState) => {
345
346
DynamicEnvironmentMapManager . _activeComputeCommandCount <
346
347
DynamicEnvironmentMapManager . _maximumComputeCommandCount
347
348
) {
348
- if ( command . canceled ) {
349
+ if ( command . owner . isDestroyed ( ) || command . canceled ) {
349
350
command = DynamicEnvironmentMapManager . _nextFrameCommandQueue . shift ( ) ;
350
351
continue ;
351
352
}
@@ -402,7 +403,6 @@ DynamicEnvironmentMapManager.prototype.reset = function () {
402
403
for ( let i = 0 ; i < length ; ++ i ) {
403
404
if ( defined ( this . _radianceMapComputeCommands [ i ] ) ) {
404
405
this . _radianceMapComputeCommands [ i ] . canceled = true ;
405
- DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
406
406
}
407
407
this . _radianceMapComputeCommands [ i ] = undefined ;
408
408
}
@@ -411,19 +411,19 @@ DynamicEnvironmentMapManager.prototype.reset = function () {
411
411
for ( let i = 0 ; i < length ; ++ i ) {
412
412
if ( defined ( this . _convolutionComputeCommands [ i ] ) ) {
413
413
this . _convolutionComputeCommands [ i ] . canceled = true ;
414
- DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
415
414
}
416
415
this . _convolutionComputeCommands [ i ] = undefined ;
417
416
}
418
417
419
418
if ( defined ( this . _irradianceComputeCommand ) ) {
420
419
this . _irradianceComputeCommand . canceled = true ;
421
- DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
422
420
this . _irradianceComputeCommand = undefined ;
423
421
}
424
422
425
423
this . _radianceMapDirty = true ;
426
424
this . _radianceCommandsDirty = true ;
425
+ this . _convolutionsCommandsDirty = false ;
426
+ this . _irradianceCommandDirty = false ;
427
427
} ;
428
428
429
429
const scratchPackedAtmosphere = new Cartesian3 ( ) ;
@@ -576,33 +576,34 @@ function updateRadianceMap(manager, frameState) {
576
576
} ,
577
577
} ,
578
578
owner : manager ,
579
- postExecute : ( ) => {
580
- const commands = manager . _radianceMapComputeCommands ;
581
- if ( ! defined ( commands [ index ] ) ) {
582
- // This command was cancelled
583
- return ;
584
- }
585
- commands [ index ] = undefined ;
586
-
587
- const framebuffer = new Framebuffer ( {
588
- context : context ,
589
- colorTextures : [ manager . _radianceMapTextures [ index ] ] ,
590
- } ) ;
591
-
592
- // Copy the output texture into the corresponding cubemap face
593
- framebuffer . _bind ( ) ;
594
- manager . _radianceCubeMap [ face ] . copyFromFramebuffer ( ) ;
595
- framebuffer . _unBind ( ) ;
596
- framebuffer . destroy ( ) ;
597
-
579
+ } ) ;
580
+ command . postExecute = ( ) => {
581
+ if ( manager . isDestroyed ( ) || command . canceled ) {
598
582
DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
583
+ return ;
584
+ }
599
585
600
- if ( ! commands . some ( defined ) ) {
601
- manager . _convolutionsCommandsDirty = true ;
602
- manager . _shouldRegenerateShaders = true ;
603
- }
604
- } ,
605
- } ) ;
586
+ const commands = manager . _radianceMapComputeCommands ;
587
+ commands [ index ] = undefined ;
588
+
589
+ const framebuffer = new Framebuffer ( {
590
+ context : context ,
591
+ colorTextures : [ manager . _radianceMapTextures [ index ] ] ,
592
+ } ) ;
593
+
594
+ // Copy the output texture into the corresponding cubemap face
595
+ framebuffer . _bind ( ) ;
596
+ manager . _radianceCubeMap [ face ] . copyFromFramebuffer ( ) ;
597
+ framebuffer . _unBind ( ) ;
598
+ framebuffer . destroy ( ) ;
599
+
600
+ DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
601
+
602
+ if ( ! commands . some ( defined ) ) {
603
+ manager . _convolutionsCommandsDirty = true ;
604
+ manager . _shouldRegenerateShaders = true ;
605
+ }
606
+ } ;
606
607
607
608
manager . _radianceMapComputeCommands [ i ] = command ;
608
609
DynamicEnvironmentMapManager . _queueCommand ( command , frameState ) ;
@@ -629,13 +630,14 @@ function updateSpecularMaps(manager, frameState) {
629
630
const context = frameState . context ;
630
631
631
632
let facesCopied = 0 ;
632
- const getPostExecute = ( index , texture , face , level ) => ( ) => {
633
- // Copy output texture to corresponding face and mipmap level
634
- const commands = manager . _convolutionComputeCommands ;
635
- if ( ! defined ( commands [ index ] ) || commands [ index ] . canceled ) {
636
- // This command was cancelled
633
+ const getPostExecute = ( command , index , texture , face , level ) => ( ) => {
634
+ if ( manager . isDestroyed ( ) || command . canceled ) {
635
+ DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
637
636
return ;
638
637
}
638
+
639
+ // Copy output texture to corresponding face and mipmap level
640
+ const commands = manager . _convolutionComputeCommands ;
639
641
commands [ index ] = undefined ;
640
642
641
643
radianceCubeMap . copyFace ( frameState , texture , face , level ) ;
@@ -712,8 +714,14 @@ function updateSpecularMaps(manager, frameState) {
712
714
return CubeMap . getDirection ( face , scratchCartesian ) ;
713
715
} ,
714
716
} ,
715
- postExecute : getPostExecute ( index , texture , face , level ) ,
716
717
} ) ;
718
+ command . postExecute = getPostExecute (
719
+ command ,
720
+ index ,
721
+ texture ,
722
+ face ,
723
+ level ,
724
+ ) ;
717
725
manager . _convolutionComputeCommands [ index ] = command ;
718
726
DynamicEnvironmentMapManager . _queueCommand ( command , frameState ) ;
719
727
++ index ;
@@ -737,7 +745,7 @@ function updateIrradianceResources(manager, frameState) {
737
745
const dimensions = irradianceTextureDimensions ;
738
746
739
747
let texture = manager . _irradianceMapTexture ;
740
- if ( defined ( texture ) ) {
748
+ if ( defined ( texture ) && ! texture . isDestroyed ( ) ) {
741
749
texture . destroy ( ) ;
742
750
}
743
751
@@ -761,22 +769,25 @@ function updateIrradianceResources(manager, frameState) {
761
769
const command = new ComputeCommand ( {
762
770
fragmentShaderSource : fs ,
763
771
outputTexture : texture ,
772
+ owner : manager ,
764
773
uniformMap : {
765
774
u_radianceMap : ( ) => manager . _radianceCubeMap ?? context . defaultTexture ,
766
775
} ,
767
- postExecute : ( ) => {
768
- if ( ! defined ( manager . _irradianceComputeCommand ) ) {
769
- // This command was cancelled
770
- return ;
771
- }
772
- manager . _irradianceTextureDirty = false ;
773
- manager . _irradianceComputeCommand = undefined ;
774
- manager . _sphericalHarmonicCoefficientsDirty = true ;
775
- manager . _irradianceMapFS = undefined ;
776
+ } ) ;
776
777
778
+ command . postExecute = ( ) => {
779
+ if ( manager . isDestroyed ( ) || command . canceled ) {
777
780
DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
778
- } ,
779
- } ) ;
781
+ return ;
782
+ }
783
+ manager . _irradianceTextureDirty = false ;
784
+ manager . _irradianceComputeCommand = undefined ;
785
+ manager . _sphericalHarmonicCoefficientsDirty = true ;
786
+ manager . _irradianceMapFS = undefined ;
787
+
788
+ DynamicEnvironmentMapManager . _activeComputeCommandCount -- ;
789
+ } ;
790
+
780
791
manager . _irradianceComputeCommand = command ;
781
792
DynamicEnvironmentMapManager . _queueCommand ( command , frameState ) ;
782
793
manager . _irradianceTextureDirty = true ;
@@ -792,7 +803,7 @@ function updateSphericalHarmonicCoefficients(manager, frameState) {
792
803
const context = frameState . context ;
793
804
794
805
if ( ! defined ( manager . _irradianceMapTexture ) ) {
795
- // Operation was cancelled
806
+ // Operation was canceled
796
807
return ;
797
808
}
798
809
@@ -864,9 +875,11 @@ DynamicEnvironmentMapManager.prototype.update = function (frameState) {
864
875
this . maximumSecondsDifference ,
865
876
) ) ;
866
877
867
- if ( regenerateEnvironmentMap ) {
878
+ if ( this . _shouldReset || regenerateEnvironmentMap ) {
868
879
this . reset ( ) ;
880
+ this . _shouldReset = false ;
869
881
this . _lastTime = JulianDate . clone ( frameState . time , this . _lastTime ) ;
882
+ return ;
870
883
}
871
884
872
885
if ( this . _radianceMapDirty ) {
0 commit comments