Skip to content

Commit 5062c97

Browse files
committed
Added copyToGame method to finalise fbo to renderer
1 parent ce0b9d9 commit 5062c97

3 files changed

Lines changed: 58 additions & 34 deletions

File tree

src/renderer/webgl/PipelineManager.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,30 @@ var PipelineManager = new Class({
667667
return this;
668668
},
669669

670+
/**
671+
* Pops the framebuffer from the renderers FBO stack and sets that as the active target,
672+
* then draws the `source` Render Target to it. It then resets the renderer textures.
673+
*
674+
* This should be done when you need to draw the _final_ results of a pipeline to the game
675+
* canvas, or the next framebuffer in line on the FBO stack. You should only call this once
676+
* in the `onDraw` handler and it should be the final thing called. Be careful not to call
677+
* this if you need to actually use the pipeline shader, instead of the copy shader. In
678+
* those cases, use the `bindAndDraw` method.
679+
*
680+
* @method Phaser.Renderer.WebGL.PipelineManager#copyToGame
681+
* @since 3.50.0
682+
*
683+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The Render Target to draw from.
684+
*/
685+
copyToGame: function (source)
686+
{
687+
var pipeline = this.setUtility(this.UTILITY_PIPELINE.copyShader);
688+
689+
pipeline.copyToGame(source);
690+
691+
return this;
692+
},
693+
670694
/**
671695
* Copy the `source` Render Target to the `target` Render Target, using the
672696
* given Color Matrix.

src/renderer/webgl/pipelines/PostFXPipeline.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,26 @@ var PostFXPipeline = new Class({
192192
this.manager.copyFrame(source, target, brightness, clear, clearAlpha);
193193
},
194194

195+
/**
196+
* Pops the framebuffer from the renderers FBO stack and sets that as the active target,
197+
* then draws the `source` Render Target to it. It then resets the renderer textures.
198+
*
199+
* This should be done when you need to draw the _final_ results of a pipeline to the game
200+
* canvas, or the next framebuffer in line on the FBO stack. You should only call this once
201+
* in the `onDraw` handler and it should be the final thing called. Be careful not to call
202+
* this if you need to actually use the pipeline shader, instead of the copy shader. In
203+
* those cases, use the `bindAndDraw` method.
204+
*
205+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#copyToGame
206+
* @since 3.50.0
207+
*
208+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The Render Target to draw from.
209+
*/
210+
copyToGame: function (source)
211+
{
212+
this.manager.copyToGame(source);
213+
},
214+
195215
/**
196216
* Copy the `source` Render Target to the `target` Render Target, using the
197217
* given Color Matrix.

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -342,57 +342,37 @@ var UtilityPipeline = new Class({
342342
},
343343

344344
/**
345-
* Binds this pipeline and draws the `source` Render Target to the `target` Render Target.
345+
* Pops the framebuffer from the renderers FBO stack and sets that as the active target,
346+
* then draws the `source` Render Target to it. It then resets the renderer textures.
346347
*
347-
* If no `target` is specified, it will pop the framebuffer from the Renderers FBO stack
348-
* and use that instead, which should be done when you need to draw the final results of
349-
* this pipeline to the game canvas.
348+
* This should be done when you need to draw the _final_ results of a pipeline to the game
349+
* canvas, or the next framebuffer in line on the FBO stack. You should only call this once
350+
* in the `onDraw` handler and it should be the final thing called. Be careful not to call
351+
* this if you need to actually use the pipeline shader, instead of the copy shader. In
352+
* those cases, use the `bindAndDraw` method.
350353
*
351-
* You can optionally set the shader to be used for the draw here, if this is a multi-shader
352-
* pipeline. By default `currentShader` will be used. If you need to set a shader but not
353-
* a target, just pass `null` as the `target` parameter.
354-
*
355-
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#bindAndDraw
354+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#copyToGame
356355
* @since 3.50.0
357356
*
358357
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The Render Target to draw from.
359-
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The Render Target to draw to. If not set, it will pop the fbo from the stack.
360-
* @param {Phaser.Renderer.WebGL.WebGLShader} [currentShader] - The shader to use during the draw.
361-
bindAndDraw: function (source, target)
358+
*/
359+
copyToGame: function (source)
362360
{
363361
var gl = this.gl;
364362

365-
this.bind(currentShader);
363+
this.set1i('uMainSampler', 0, this.copyShader);
364+
this.set1f('uBrightness', 1, this.copyShader);
366365

367-
this.set1i('uMainSampler', 0);
368-
369-
if (target)
370-
{
371-
gl.viewport(0, 0, target.width, target.height);
372-
gl.bindFramebuffer(gl.FRAMEBUFFER, target.framebuffer);
373-
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, target.texture, 0);
374-
}
375-
else
376-
{
377-
this.renderer.popFramebuffer();
378-
}
366+
this.renderer.popFramebuffer();
379367

380368
gl.activeTexture(gl.TEXTURE0);
381369
gl.bindTexture(gl.TEXTURE_2D, source.texture);
382370

383371
gl.bufferData(gl.ARRAY_BUFFER, this.vertexData, gl.STATIC_DRAW);
384372
gl.drawArrays(gl.TRIANGLES, 0, 6);
385373

386-
if (!target)
387-
{
388-
this.renderer.resetTextures();
389-
}
390-
else
391-
{
392-
gl.bindTexture(gl.TEXTURE_2D, null);
393-
}
374+
this.renderer.resetTextures();
394375
},
395-
*/
396376

397377
/**
398378
* Copy the `source` Render Target to the `target` Render Target, using the

0 commit comments

Comments
 (0)