@@ -10,6 +10,8 @@ var BaseCamera = require('../../cameras/2d/BaseCamera');
1010var CameraEvents = require ( '../../cameras/2d/events' ) ;
1111var Class = require ( '../../utils/Class' ) ;
1212var CONST = require ( '../../const' ) ;
13+ var EventEmitter = require ( 'eventemitter3' ) ;
14+ var Events = require ( './events' ) ;
1315var GameEvents = require ( '../../core/events' ) ;
1416var IsSizePowerOfTwo = require ( '../../math/pow2/IsSizePowerOfTwo' ) ;
1517var NOOP = require ( '../../utils/NOOP' ) ;
@@ -37,17 +39,22 @@ var WebGLSnapshot = require('../snapshot/WebGLSnapshot');
3739 *
3840 * @class WebGLRenderer
3941 * @memberof Phaser.Renderer.WebGL
42+ * @extends Phaser.Events.EventEmitter
4043 * @constructor
4144 * @since 3.0.0
4245 *
4346 * @param {Phaser.Game } game - The Game instance which owns this WebGL Renderer.
4447 */
4548var WebGLRenderer = new Class ( {
4649
50+ Extends : EventEmitter ,
51+
4752 initialize :
4853
4954 function WebGLRenderer ( game )
5055 {
56+ EventEmitter . call ( this ) ;
57+
5158 var gameConfig = game . config ;
5259
5360 var contextCreationConfig = {
@@ -612,6 +619,15 @@ var WebGLRenderer = new Class({
612619 */
613620 this . defaultScissor = [ 0 , 0 , 0 , 0 ] ;
614621
622+ /**
623+ * Has this renderer fully booted yet?
624+ *
625+ * @name Phaser.Renderer.WebGL.WebGLRenderer#isBooted
626+ * @type {boolean }
627+ * @since 3.50.0
628+ */
629+ this . isBooted = false ;
630+
615631 this . init ( this . config ) ;
616632 } ,
617633
@@ -839,23 +855,11 @@ var WebGLRenderer = new Class({
839855 this . width = baseSize . width ;
840856 this . height = baseSize . height ;
841857
842- // Set-up pipelines
843-
844- // First, default ones
845- pipelineManager . boot ( ) ;
858+ this . isBooted = true ;
846859
847- var pipelines = game . config . pipeline ;
848-
849- // Then, custom ones
850- if ( pipelines )
851- {
852- for ( var pipelineName in pipelines )
853- {
854- var pipelineInstance = pipelines [ pipelineName ] ;
860+ // Set-up pipelines
855861
856- pipelineManager . add ( pipelineName , new pipelineInstance ( game ) ) ;
857- }
858- }
862+ pipelineManager . boot ( game . config . pipeline ) ;
859863
860864 // Set-up default textures, fbo and scissor
861865
@@ -895,6 +899,7 @@ var WebGLRenderer = new Class({
895899 * Resizes the drawing buffer to match that required by the Scale Manager.
896900 *
897901 * @method Phaser.Renderer.WebGL.WebGLRenderer#resize
902+ * @fires Phaser.Renderer.WebGL.Events#RESIZE
898903 * @since 3.0.0
899904 *
900905 * @param {number } [width] - The new width of the renderer.
@@ -911,8 +916,6 @@ var WebGLRenderer = new Class({
911916
912917 gl . viewport ( 0 , 0 , width , height ) ;
913918
914- this . pipelines . resize ( width , height ) ;
915-
916919 this . drawingBufferHeight = gl . drawingBufferHeight ;
917920
918921 gl . scissor ( 0 , ( gl . drawingBufferHeight - height ) , width , height ) ;
@@ -922,6 +925,8 @@ var WebGLRenderer = new Class({
922925 this . defaultScissor [ 2 ] = width ;
923926 this . defaultScissor [ 3 ] = height ;
924927
928+ this . emit ( Events . RESIZE , width , height ) ;
929+
925930 return this ;
926931 } ,
927932
@@ -2142,6 +2147,8 @@ var WebGLRenderer = new Class({
21422147
21432148 var color = camera . backgroundColor ;
21442149
2150+ camera . emit ( CameraEvents . PRE_RENDER , camera ) ;
2151+
21452152 this . pipelines . preBatchCamera ( camera ) ;
21462153
21472154 this . pushScissor ( cx , cy , cw , ch ) ;
@@ -2164,11 +2171,6 @@ var WebGLRenderer = new Class({
21642171 color . alphaGL
21652172 ) ;
21662173 }
2167-
2168- if ( camera . postPipeline )
2169- {
2170- camera . emit ( CameraEvents . PRE_RENDER , camera ) ;
2171- }
21722174 } ,
21732175
21742176 /**
@@ -2227,18 +2229,16 @@ var WebGLRenderer = new Class({
22272229 camera . mask . postRenderWebGL ( this , camera . _maskCamera ) ;
22282230 }
22292231
2230- if ( camera . postPipeline )
2231- {
2232- camera . emit ( CameraEvents . POST_RENDER , camera ) ;
2232+ this . pipelines . postBatchCamera ( camera ) ;
22332233
2234- this . pipelines . postBatchCamera ( camera ) ;
2235- }
2234+ camera . emit ( CameraEvents . POST_RENDER , camera ) ;
22362235 } ,
22372236
22382237 /**
22392238 * Clears the current vertex buffer and updates pipelines.
22402239 *
22412240 * @method Phaser.Renderer.WebGL.WebGLRenderer#preRender
2241+ * @fires Phaser.Renderer.WebGL.Events#PRE_RENDER
22422242 * @since 3.0.0
22432243 */
22442244 preRender : function ( )
@@ -2277,7 +2277,7 @@ var WebGLRenderer = new Class({
22772277
22782278 this . textureFlush = 0 ;
22792279
2280- this . pipelines . preRender ( ) ;
2280+ this . emit ( Events . PRE_RENDER ) ;
22812281 } ,
22822282
22832283 /**
@@ -2291,6 +2291,7 @@ var WebGLRenderer = new Class({
22912291 * This method is not called if `Camera.visible` is `false`, or `Camera.alpha` is zero.
22922292 *
22932293 * @method Phaser.Renderer.WebGL.WebGLRenderer#render
2294+ * @fires Phaser.Renderer.WebGL.Events#RENDER
22942295 * @since 3.0.0
22952296 *
22962297 * @param {Phaser.Scene } scene - The Scene to render.
@@ -2303,7 +2304,7 @@ var WebGLRenderer = new Class({
23032304
23042305 var childCount = children . length ;
23052306
2306- this . pipelines . render ( scene , camera ) ;
2307+ this . emit ( Events . RENDER , scene , camera ) ;
23072308
23082309 // Apply scissor for cam region + render background color, if not transparent
23092310 this . preRenderCamera ( camera ) ;
@@ -2390,13 +2391,14 @@ var WebGLRenderer = new Class({
23902391 * The post-render step happens after all Cameras in all Scenes have been rendered.
23912392 *
23922393 * @method Phaser.Renderer.WebGL.WebGLRenderer#postRender
2394+ * @fires Phaser.Renderer.WebGL.Events#POST_RENDER
23932395 * @since 3.0.0
23942396 */
23952397 postRender : function ( )
23962398 {
23972399 if ( this . contextLost ) { return ; }
23982400
2399- this . pipelines . postRender ( ) ;
2401+ this . emit ( Events . POST_RENDER ) ;
24002402
24012403 var state = this . snapshotState ;
24022404
@@ -2844,6 +2846,8 @@ var WebGLRenderer = new Class({
28442846 this . pipelines . destroy ( ) ;
28452847 this . defaultCamera . destroy ( ) ;
28462848
2849+ this . removeAllListeners ( ) ;
2850+
28472851 this . fboStack = [ ] ;
28482852 this . maskStack = [ ] ;
28492853 this . extensions = { } ;
0 commit comments