@@ -15,6 +15,7 @@ var GameEvents = require('../../core/events');
1515var IsSizePowerOfTwo = require ( '../../math/pow2/IsSizePowerOfTwo' ) ;
1616var NOOP = require ( '../../utils/NOOP' ) ;
1717var PipelineManager = require ( './PipelineManager' ) ;
18+ var RenderTarget = require ( './RenderTarget' ) ;
1819var ScaleEvents = require ( '../../scale/events' ) ;
1920var TextureEvents = require ( '../../textures/events' ) ;
2021var Utils = require ( './Utils' ) ;
@@ -598,6 +599,17 @@ var WebGLRenderer = new Class({
598599 */
599600 this . isBooted = false ;
600601
602+ /**
603+ * A Render Target you can use to capture the current state of the Renderer.
604+ *
605+ * A Render Target encapsulates a framebuffer and texture for the WebGL Renderer.
606+ *
607+ * @name Phaser.Renderer.WebGL.WebGLRenderer#renderTarget
608+ * @type {Phaser.Renderer.WebGL.RenderTarget }
609+ * @since 3.50.0
610+ */
611+ this . renderTarget = null ;
612+
601613 this . init ( this . config ) ;
602614 } ,
603615
@@ -827,6 +839,8 @@ var WebGLRenderer = new Class({
827839
828840 this . isBooted = true ;
829841
842+ this . renderTarget = new RenderTarget ( this , this . width , this . height , 1 , 0 , false , true ) ;
843+
830844 // Set-up pipelines
831845
832846 pipelineManager . boot ( game . config . pipeline ) ;
@@ -865,6 +879,36 @@ var WebGLRenderer = new Class({
865879 }
866880 } ,
867881
882+ /**
883+ * Binds the WebGL Renderers Render Target, so all drawn content is now redirected to it.
884+ *
885+ * Make sure to call `endCapture`.
886+ *
887+ * @method Phaser.Renderer.WebGL.WebGLRenderer#beginCapture
888+ * @since 3.50.0
889+ */
890+ beginCapture : function ( )
891+ {
892+ this . renderTarget . bind ( true ) ;
893+
894+ this . resetTextures ( true ) ;
895+ } ,
896+
897+ /**
898+ * Unbinds the WebGL Renderers Render Target and returns it, stopping any further content being drawn to it.
899+ *
900+ * @method Phaser.Renderer.WebGL.WebGLRenderer#endCapture
901+ * @since 3.50.0
902+ *
903+ * @return {Phaser.Renderer.WebGL.RenderTarget } A reference to the WebGL Renderer Render Target.
904+ */
905+ endCapture : function ( )
906+ {
907+ this . renderTarget . unbind ( true ) ;
908+
909+ return this . renderTarget ;
910+ } ,
911+
868912 /**
869913 * Resizes the drawing buffer to match that required by the Scale Manager.
870914 *
@@ -1018,6 +1062,34 @@ var WebGLRenderer = new Class({
10181062 }
10191063 } ,
10201064
1065+ /**
1066+ * Resets the gl scissor state to be whatever the current scissor is, if there is one, without
1067+ * modifying the scissor stack.
1068+ *
1069+ * @method Phaser.Renderer.WebGL.WebGLRenderer#resetScissor
1070+ * @since 3.50.0
1071+ */
1072+ resetScissor : function ( )
1073+ {
1074+ var gl = this . gl ;
1075+
1076+ var current = this . currentScissor ;
1077+
1078+ if ( current )
1079+ {
1080+ var x = current [ 0 ] ;
1081+ var y = current [ 1 ] ;
1082+ var width = current [ 2 ] ;
1083+ var height = current [ 3 ] ;
1084+
1085+ if ( width > 0 && height > 0 )
1086+ {
1087+ gl . enable ( gl . SCISSOR_TEST ) ;
1088+ gl . scissor ( x , ( this . drawingBufferHeight - y - height ) , width , height ) ;
1089+ }
1090+ }
1091+ } ,
1092+
10211093 /**
10221094 * Pops the last scissor state and sets it.
10231095 *
@@ -1058,6 +1130,19 @@ var WebGLRenderer = new Class({
10581130 return ( ( mask && mask . isStencil ) || ( camMask && camMask . isStencil ) ) ;
10591131 } ,
10601132
1133+ /**
1134+ * Resets the gl viewport to the current renderer dimensions.
1135+ *
1136+ * @method Phaser.Renderer.WebGL.WebGLRenderer#resetViewport
1137+ * @since 3.50.0
1138+ */
1139+ resetViewport : function ( )
1140+ {
1141+ var gl = this . gl ;
1142+
1143+ gl . viewport ( 0 , 0 , this . width , this . height ) ;
1144+ } ,
1145+
10611146 /**
10621147 * Sets the blend mode to the value given.
10631148 *
0 commit comments