@@ -249,36 +249,52 @@ var PostFXPipeline = new Class({
249249 } ,
250250
251251 /**
252- * Binds this pipeline, pops the framebuffer then draws the `source`
253- * Render Target to the framebuffer currently set in the renderer (after the fbo stack pop).
252+ * Binds this pipeline and draws the `source` Render Target to the `target` Render Target.
253+ *
254+ * If no `target` is specified, it will pop the framebuffer from the Renderers FBO stack
255+ * and use that instead, which should be done when you need to draw the final results of
256+ * this pipeline to the game canvas.
254257 *
255258 * You can optionally set the shader to be used for the draw here, if this is a multi-shader
256- * pipeline.
259+ * pipeline. By default `currentShader` will be used. If you need to set a shader but not
260+ * a target, just pass `null` as the `target` parameter.
257261 *
258262 * @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#bindAndDraw
259263 * @since 3.50.0
260264 *
261265 * @param {Phaser.Renderer.WebGL.RenderTarget } source - The Render Target to draw from.
266+ * @param {Phaser.Renderer.WebGL.RenderTarget } [target] - The Render Target to draw to. If not set, it will pop the fbo from the stack.
262267 * @param {Phaser.Renderer.WebGL.WebGLShader } [currentShader] - The shader to use during the draw.
263268 */
264- bindAndDraw : function ( source , currentShader )
269+ bindAndDraw : function ( source , target , currentShader )
265270 {
271+ var gl = this . gl ;
272+
266273 this . bind ( currentShader ) ;
267274
268275 this . set1i ( 'uMainSampler' , 0 ) ;
269276
270- // Pop out this pipelines renderTarget
271- this . renderer . popFramebuffer ( ) ;
272-
273- var gl = this . gl ;
277+ if ( target )
278+ {
279+ gl . viewport ( 0 , 0 , target . width , target . height ) ;
280+ gl . bindFramebuffer ( gl . FRAMEBUFFER , target . framebuffer ) ;
281+ gl . framebufferTexture2D ( gl . FRAMEBUFFER , gl . COLOR_ATTACHMENT0 , gl . TEXTURE_2D , target . texture , 0 ) ;
282+ }
283+ else
284+ {
285+ this . renderer . popFramebuffer ( ) ;
286+ }
274287
275288 gl . activeTexture ( gl . TEXTURE0 ) ;
276289 gl . bindTexture ( gl . TEXTURE_2D , source . texture ) ;
277290
278291 gl . bufferData ( gl . ARRAY_BUFFER , this . vertexData , gl . STATIC_DRAW ) ;
279292 gl . drawArrays ( gl . TRIANGLES , 0 , 6 ) ;
280293
281- this . renderer . resetTextures ( ) ;
294+ if ( ! target )
295+ {
296+ this . renderer . resetTextures ( ) ;
297+ }
282298 }
283299
284300} ) ;
0 commit comments