@@ -339,6 +339,9 @@ define([
339
339
340
340
this . _transitioner = new SceneTransitioner ( this ) ;
341
341
342
+ this . _preUpdate = new Event ( ) ;
343
+ this . _postUpdate = new Event ( ) ;
344
+
342
345
this . _renderError = new Event ( ) ;
343
346
this . _preRender = new Event ( ) ;
344
347
this . _postRender = new Event ( ) ;
@@ -1024,6 +1027,45 @@ define([
1024
1027
}
1025
1028
} ,
1026
1029
1030
+ /**
1031
+ * Gets the event that will be raised before the scene is updated or rendered. Subscribers to the event
1032
+ * receive the Scene instance as the first parameter and the current time as the second parameter.
1033
+ * @memberof Scene.prototype
1034
+ *
1035
+ * @see scene#postUpdate
1036
+ * @see scene#preRender
1037
+ * @see scene#postRender
1038
+ * @see scene#render
1039
+ *
1040
+ * @type {Event }
1041
+ * @readonly
1042
+ */
1043
+ preUpdate : {
1044
+ get : function ( ) {
1045
+ return this . _preUpdate ;
1046
+ }
1047
+ } ,
1048
+
1049
+ /**
1050
+ * Gets the event that will be raised immediately after the scene is updated and before the scene is rendered.
1051
+ * Subscribers to the event receive the Scene instance as the first parameter and the current time as the second
1052
+ * parameter.
1053
+ * @memberof Scene.prototype
1054
+ *
1055
+ * @see scene#preUpdate
1056
+ * @see scene#preRender
1057
+ * @see scene#postRender
1058
+ * @see scene#render
1059
+ *
1060
+ * @type {Event }
1061
+ * @readonly
1062
+ */
1063
+ postUpdate : {
1064
+ get : function ( ) {
1065
+ return this . _postUpdate ;
1066
+ }
1067
+ } ,
1068
+
1027
1069
/**
1028
1070
* Gets the event that will be raised when an error is thrown inside the <code>render</code> function.
1029
1071
* The Scene instance and the thrown error are the only two parameters passed to the event handler.
@@ -1041,10 +1083,16 @@ define([
1041
1083
} ,
1042
1084
1043
1085
/**
1044
- * Gets the event that will be raised at the start of each call to <code>render</code>. Subscribers to the event
1045
- * receive the Scene instance as the first parameter and the current time as the second parameter.
1086
+ * Gets the event that will be raised after the scene is updated and immediately before the scene is rendered.
1087
+ * Subscribers to the event receive the Scene instance as the first parameter and the current time as the second
1088
+ * parameter.
1046
1089
* @memberof Scene.prototype
1047
1090
*
1091
+ * @see scene#preUpdate
1092
+ * @see scene#postUpdate
1093
+ * @see scene#postRender
1094
+ * @see scene#render
1095
+ *
1048
1096
* @type {Event }
1049
1097
* @readonly
1050
1098
*/
@@ -1055,10 +1103,15 @@ define([
1055
1103
} ,
1056
1104
1057
1105
/**
1058
- * Gets the event that will be raised at the end of each call to <code>render</code> . Subscribers to the event
1106
+ * Gets the event that will be raised immediately after the scene is rendered . Subscribers to the event
1059
1107
* receive the Scene instance as the first parameter and the current time as the second parameter.
1060
1108
* @memberof Scene.prototype
1061
1109
*
1110
+ * @see scene#preUpdate
1111
+ * @see scene#postUpdate
1112
+ * @see scene#postRender
1113
+ * @see scene#render
1114
+ *
1062
1115
* @type {Event }
1063
1116
* @readonly
1064
1117
*/
@@ -2787,7 +2840,7 @@ define([
2787
2840
}
2788
2841
}
2789
2842
2790
- function callAfterRenderFunctions ( frameState ) {
2843
+ function callAfterRenderCycleFunctions ( frameState ) {
2791
2844
// Functions are queued up during primitive update and executed here in case
2792
2845
// the function modifies scene state that should remain constant over the frame.
2793
2846
var functions = frameState . afterRender ;
@@ -2860,14 +2913,7 @@ define([
2860
2913
}
2861
2914
2862
2915
function update ( scene , time ) {
2863
- var frameState = scene . _frameState ;
2864
-
2865
- scene . _groundPrimitives . update ( frameState ) ;
2866
- scene . _primitives . update ( frameState ) ;
2867
-
2868
- if ( defined ( scene . globe ) ) {
2869
- scene . globe . update ( frameState ) ;
2870
- }
2916
+ // TODO: Update primitives, including globe
2871
2917
}
2872
2918
2873
2919
function render ( scene , time ) {
@@ -2922,6 +2968,18 @@ define([
2922
2968
context . endFrame ( ) ;
2923
2969
}
2924
2970
2971
+ function tryAndCatchError ( scene , time , functionToExecute ) {
2972
+ try {
2973
+ functionToExecute ( scene , time ) ;
2974
+ } catch ( error ) {
2975
+ scene . _renderError . raiseEvent ( scene , error ) ;
2976
+
2977
+ if ( scene . rethrowRenderErrors ) {
2978
+ throw error ;
2979
+ }
2980
+ }
2981
+ }
2982
+
2925
2983
/**
2926
2984
* @private
2927
2985
*/
@@ -2930,39 +2988,33 @@ define([
2930
2988
time = JulianDate . now ( ) ;
2931
2989
}
2932
2990
2933
- this . _preRender . raiseEvent ( this , time ) ;
2934
2991
this . _jobScheduler . resetBudgets ( ) ;
2935
2992
2936
- var cameraChanged = checkForCameraUpdates ( this ) ;
2993
+ // Update
2994
+ this . _preUpdate . raiseEvent ( this , time ) ;
2995
+ tryAndCatchError ( this , time , update ) ;
2996
+ this . _postUpdate . raiseEvent ( this , time ) ;
2937
2997
2998
+ var cameraChanged = checkForCameraUpdates ( this ) ;
2938
2999
var shouldRender = ! this . requestRenderMode || this . _renderRequested || cameraChanged || ( this . mode === SceneMode . MORPHING ) ;
2939
-
2940
3000
if ( ! shouldRender && defined ( this . maximumRenderTimeChange ) && defined ( this . _lastRenderTime ) ) {
2941
3001
var difference = Math . abs ( JulianDate . secondsDifference ( this . _lastRenderTime , time ) ) ;
2942
3002
shouldRender = shouldRender || difference >= this . maximumRenderTimeChange ;
2943
3003
}
2944
3004
2945
- try {
2946
- if ( shouldRender ) {
2947
- this . _lastRenderTime = JulianDate . clone ( time , this . _lastRenderTime ) ;
2948
- this . _renderRequested = false ;
3005
+ if ( shouldRender ) {
3006
+ this . _lastRenderTime = JulianDate . clone ( time , this . _lastRenderTime ) ;
3007
+ this . _renderRequested = false ;
2949
3008
2950
- render ( this , time ) ;
2951
- } else {
2952
- update ( this , time ) ;
2953
- }
2954
- } catch ( error ) {
2955
- this . _renderError . raiseEvent ( this , error ) ;
2956
-
2957
- if ( this . rethrowRenderErrors ) {
2958
- throw error ;
2959
- }
3009
+ // Render
3010
+ this . _preRender . raiseEvent ( this , time ) ;
3011
+ tryAndCatchError ( this , time , render ) ;
3012
+ this . _postRender . raiseEvent ( this , time ) ;
2960
3013
}
2961
3014
2962
3015
updateDebugShowFramesPerSecond ( this , shouldRender ) ;
2963
3016
RequestScheduler . update ( ) ;
2964
- callAfterRenderFunctions ( this . _frameState ) ;
2965
- this . _postRender . raiseEvent ( this , time ) ;
3017
+ callAfterRenderCycleFunctions ( this . _frameState ) ;
2966
3018
} ;
2967
3019
2968
3020
/**
@@ -3143,7 +3195,7 @@ define([
3143
3195
3144
3196
var object = this . _pickFramebuffer . end ( scratchRectangle ) ;
3145
3197
context . endFrame ( ) ;
3146
- callAfterRenderFunctions ( frameState ) ;
3198
+ callAfterRenderCycleFunctions ( frameState ) ;
3147
3199
return object ;
3148
3200
} ;
3149
3201
0 commit comments