55 */
66
77var Class = require ( '../../utils/Class' ) ;
8- var CustomMap = require ( '../../structs/Map' ) ;
98var CONST = require ( './pipelines/const' ) ;
9+ var CustomMap = require ( '../../structs/Map' ) ;
1010
1111// Default Phaser 3 Pipelines
1212var BitmapMaskPipeline = require ( './pipelines/BitmapMaskPipeline' ) ;
@@ -16,6 +16,7 @@ var MultiPipeline = require('./pipelines/MultiPipeline');
1616var PostFXPipeline = require ( './pipelines/PostFXPipeline' ) ;
1717var RopePipeline = require ( './pipelines/RopePipeline' ) ;
1818var SinglePipeline = require ( './pipelines/SinglePipeline' ) ;
19+ var UtilityPipeline = require ( './pipelines/UtilityPipeline' ) ;
1920
2021/**
2122 * @classdesc
@@ -159,6 +160,16 @@ var PipelineManager = new Class({
159160 * @since 3.50.0
160161 */
161162 this . POSTFX_PIPELINE = null ;
163+
164+ /**
165+ * A constant-style reference to the Utility Pipeline Instance.
166+ *
167+ * @name Phaser.Renderer.WebGL.PipelineManager#UTILITY_PIPELINE
168+ * @type {Phaser.Renderer.WebGL.Pipelines.UtilityPipeline }
169+ * @default null
170+ * @since 3.50.0
171+ */
172+ this . UTILITY_PIPELINE = null ;
162173 } ,
163174
164175 /**
@@ -179,6 +190,7 @@ var PipelineManager = new Class({
179190 this . MULTI_PIPELINE = this . add ( CONST . MULTI_PIPELINE , new MultiPipeline ( { game : game } ) ) ;
180191 this . BITMAPMASK_PIPELINE = this . add ( CONST . BITMAPMASK_PIPELINE , new BitmapMaskPipeline ( { game : game } ) ) ;
181192 this . POSTFX_PIPELINE = this . add ( CONST . POSTFX_PIPELINE , new PostFXPipeline ( { game : game } ) ) ;
193+ this . UTILITY_PIPELINE = this . add ( CONST . UTILITY_PIPELINE , new UtilityPipeline ( { game : game } ) ) ;
182194
183195 this . add ( CONST . SINGLE_PIPELINE , new SinglePipeline ( { game : game } ) ) ;
184196 this . add ( CONST . ROPE_PIPELINE , new RopePipeline ( { game : game } ) ) ;
@@ -419,12 +431,13 @@ var PipelineManager = new Class({
419431 *
420432 * @param {Phaser.Renderer.WebGL.WebGLPipeline } pipeline - The pipeline instance to be set as current.
421433 * @param {Phaser.GameObjects.GameObject } [gameObject] - The Game Object that invoked this pipeline, if any.
434+ * @param {Phaser.Renderer.WebGL.WebGLShader } [currentShader] - The shader to set as being current.
422435 *
423436 * @return {Phaser.Renderer.WebGL.WebGLPipeline } The pipeline that was set.
424437 */
425- set : function ( pipeline , gameObject )
438+ set : function ( pipeline , gameObject , currentShader )
426439 {
427- if ( ! this . isCurrent ( pipeline ) )
440+ if ( ! this . isCurrent ( pipeline , currentShader ) )
428441 {
429442 this . flush ( ) ;
430443
@@ -435,7 +448,7 @@ var PipelineManager = new Class({
435448
436449 this . current = pipeline ;
437450
438- pipeline . bind ( ) ;
451+ pipeline . bind ( currentShader ) ;
439452 }
440453
441454 pipeline . onBind ( gameObject ) ;
@@ -475,21 +488,38 @@ var PipelineManager = new Class({
475488 * @since 3.50.0
476489 *
477490 * @param {Phaser.Renderer.WebGL.WebGLPipeline } pipeline - The pipeline instance to be checked.
491+ * @param {Phaser.Renderer.WebGL.WebGLShader } [currentShader] - The shader to set as being current.
478492 *
479493 * @return {boolean } `true` if the given pipeline is already the current pipeline, otherwise `false`.
480494 */
481- isCurrent : function ( pipeline )
495+ isCurrent : function ( pipeline , currentShader )
482496 {
483497 var renderer = this . renderer ;
484498 var current = this . current ;
485499
500+ if ( current && ! currentShader )
501+ {
502+ currentShader = current . currentShader ;
503+ }
504+
486505 return ! (
487506 current !== pipeline ||
488507 current . vertexBuffer !== renderer . currentVertexBuffer ||
489- current . currentShader . program !== renderer . currentProgram
508+ currentShader . program !== renderer . currentProgram
490509 ) ;
491510 } ,
492511
512+ copyFrame : function ( source , target , brightness )
513+ {
514+ if ( brightness === undefined ) { brightness = 1 ; }
515+
516+ var pipeline = this . setUtility ( this . UTILITY_PIPELINE . copyShader ) ;
517+
518+ pipeline . copyFrame ( source , target , brightness ) ;
519+
520+ return this ;
521+ } ,
522+
493523 forceZero : function ( )
494524 {
495525 return ( this . current && this . current . forceZero ) ;
@@ -525,6 +555,23 @@ var PipelineManager = new Class({
525555 return this . set ( this . CAMERA_PIPELINE ) ;
526556 } ,
527557
558+ /**
559+ * Sets the Utility Pipeline to be the currently bound pipeline.
560+ *
561+ * This is the default Phaser 3 rendering pipeline.
562+ *
563+ * @method Phaser.Renderer.WebGL.PipelineManager#setUtility
564+ * @since 3.50.0
565+ *
566+ * @param {Phaser.Renderer.WebGL.WebGLShader } [currentShader] - The shader to set as being current.
567+ *
568+ * @return {Phaser.Renderer.WebGL.Pipelines.UtilityPipeline } The Utility Pipeline instance.
569+ */
570+ setUtility : function ( currentShader )
571+ {
572+ return this . set ( this . UTILITY_PIPELINE , null , currentShader ) ;
573+ } ,
574+
528575 /**
529576 * Use this to reset the gl context to the state that Phaser requires to continue rendering.
530577 *
0 commit comments