Skip to content

Commit d07b2fc

Browse files
committed
Lots more documentation added
1 parent 11aabfc commit d07b2fc

2 files changed

Lines changed: 105 additions & 15 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,10 @@ var WebGLPipeline = new Class({
778778
},
779779

780780
/**
781-
* TODO
781+
* This method is called as a result of the `WebGLPipeline.batchQuad` method, right before a quad
782+
* belonging to a Game Object is about to be added to the batch. When this is called, the
783+
* renderer has just performed a flush. It will bind the current render target, if any are set
784+
* and finally call the `onPreBatch` hook.
782785
*
783786
* @method Phaser.Renderer.WebGL.WebGLPipeline#preBatch
784787
* @since 3.50.0
@@ -800,7 +803,12 @@ var WebGLPipeline = new Class({
800803
},
801804

802805
/**
803-
* TODO
806+
* This method is called as a result of the `WebGLPipeline.batchQuad` method, right after a quad
807+
* belonging to a Game Object has been added to the batch. When this is called, the
808+
* renderer has just performed a flush.
809+
*
810+
* It calls the `onDraw` hook followed by the `onPostBatch` hook, which can be used to perform
811+
* additional Post FX Pipeline processing.
804812
*
805813
* @method Phaser.Renderer.WebGL.WebGLPipeline#postBatch
806814
* @since 3.50.0
@@ -818,6 +826,21 @@ var WebGLPipeline = new Class({
818826
return this;
819827
},
820828

829+
/**
830+
* This method is only used by Post FX Pipelines and those that extend from them.
831+
*
832+
* This method is called every time the `postBatch` method is called and is passed a
833+
* reference to the current render target.
834+
*
835+
* At the very least a Post FX Pipeline should call `this.bindAndDraw(renderTarget)`,
836+
* however, you can do as much additional processing as you like in this method if
837+
* you override it from within your own pipelines.
838+
*
839+
* @method Phaser.Renderer.WebGL.WebGLPipeline#onDraw
840+
* @since 3.50.0
841+
*
842+
* @param {Phaser.Renderer.WebGL.RenderTarget} renderTarget - The Render Target.
843+
*/
821844
onDraw: function ()
822845
{
823846
},
@@ -932,12 +955,7 @@ var WebGLPipeline = new Class({
932955
/**
933956
* By default this is an empty method hook that you can override and use in your own custom pipelines.
934957
*
935-
* This method is called every time a **Game Object** asks the Pipeline Manager to use this pipeline
936-
* as the post-render pipeline.
937-
*
938-
* Unlike the `bind` method, which is only called once per frame, this is called for every object
939-
* that requests use of this pipeline, allowing you to perform per-object set-up, such as loading
940-
* shader uniform data.
958+
* This method is called immediately before a **Game Object** is about to add itself to the batch.
941959
*
942960
* @method Phaser.Renderer.WebGL.WebGLPipeline#onPreBatch
943961
* @since 3.50.0
@@ -951,7 +969,7 @@ var WebGLPipeline = new Class({
951969
/**
952970
* By default this is an empty method hook that you can override and use in your own custom pipelines.
953971
*
954-
* TODO
972+
* This method is called immediately after a **Game Object** has been added to the batch.
955973
*
956974
* @method Phaser.Renderer.WebGL.WebGLPipeline#onPostBatch
957975
* @since 3.50.0

src/renderer/webgl/pipelines/PostFXPipeline.js

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ var WebGLPipeline = require('../WebGLPipeline');
2626
*
2727
* The default shader uniforms for this pipeline are:
2828
*
29-
* `uProjectionMatrix` (mat4)
30-
* `uMainSampler` (sampler2D)
29+
* `uMainSampler` (sampler2D)
3130
*
3231
* @class PostFXPipeline
3332
* @extends Phaser.Renderer.WebGL.WebGLPipeline
@@ -170,32 +169,107 @@ var PostFXPipeline = new Class({
170169
this.bindAndDraw(renderTarget);
171170
},
172171

172+
/**
173+
* Copy the `source` Render Target to the `target` Render Target.
174+
*
175+
* You can optionally set the brightness factor of the copy.
176+
*
177+
* The difference between this method and `drawFrame` is that this method
178+
* uses a faster copy shader, where only the brightness can be modified.
179+
* If you need color level manipulation, see `drawFrame` instead.
180+
*
181+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#copyFrame
182+
* @since 3.50.0
183+
*
184+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The source Render Target.
185+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
186+
* @param {number} [brightness=1] - The brightness value applied to the frame copy.
187+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
188+
*/
173189
copyFrame: function (source, target, brightness, clearAlpha)
174190
{
175191
this.manager.copyFrame(source, target, brightness, clearAlpha);
176192
},
177193

194+
/**
195+
* Copy the `source` Render Target to the `target` Render Target, using the
196+
* given Color Matrix.
197+
*
198+
* The difference between this method and `copyFrame` is that this method
199+
* uses a color matrix shader, where you have full control over the luminance
200+
* values used during the copy. If you don't need this, you can use the faster
201+
* `copyFrame` method instead.
202+
*
203+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#drawFrame
204+
* @since 3.50.0
205+
*
206+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The source Render Target.
207+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
208+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
209+
*/
178210
drawFrame: function (source, target, clearAlpha)
179211
{
180212
this.manager.drawFrame(source, target, clearAlpha, this.colorMatrix);
181213
},
182214

215+
/**
216+
* Draws the `source1` and `source2` Render Targets to the `target` Render Target
217+
* using a linear blend effect, which is controlled by the `strength` parameter.
218+
*
219+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#blendFrames
220+
* @since 3.50.0
221+
*
222+
* @param {Phaser.Renderer.WebGL.RenderTarget} source1 - The first source Render Target.
223+
* @param {Phaser.Renderer.WebGL.RenderTarget} source2 - The second source Render Target.
224+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
225+
* @param {number} [strength=1] - The strength of the blend.
226+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
227+
*/
183228
blendFrames: function (source1, source2, target, strength, clearAlpha)
184229
{
185230
this.manager.blendFrames(source1, source2, target, strength, clearAlpha);
186231
},
187232

233+
/**
234+
* Draws the `source1` and `source2` Render Targets to the `target` Render Target
235+
* using an additive blend effect, which is controlled by the `strength` parameter.
236+
*
237+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#blendFramesAdditive
238+
* @since 3.50.0
239+
*
240+
* @param {Phaser.Renderer.WebGL.RenderTarget} source1 - The first source Render Target.
241+
* @param {Phaser.Renderer.WebGL.RenderTarget} source2 - The second source Render Target.
242+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
243+
* @param {number} [strength=1] - The strength of the blend.
244+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
245+
*/
188246
blendFramesAdditive: function (source1, source2, target, strength, clearAlpha)
189247
{
190248
this.manager.blendFramesAdditive(source1, source2, target, strength, clearAlpha);
191249
},
192250

251+
/**
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).
254+
*
255+
* You can optionally set the shader to be used for the draw here, if this is a multi-shader
256+
* pipeline.
257+
*
258+
* @method Phaser.Renderer.WebGL.Pipelines.PostFXPipeline#bindAndDraw
259+
* @since 3.50.0
260+
*
261+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The Render Target to draw from.
262+
* @param {Phaser.Renderer.WebGL.WebGLShader} [currentShader] - The shader to use during the draw.
263+
*/
193264
bindAndDraw: function (source, currentShader)
194265
{
195266
this.bind(currentShader);
196267

197-
// Pop out this pipelines renderTarget
198-
this.renderer.popFramebuffer();
268+
if (this.currentTarget)
269+
{
270+
// Pop out this pipelines renderTarget
271+
this.renderer.popFramebuffer();
272+
}
199273

200274
var gl = this.gl;
201275

@@ -206,8 +280,6 @@ var PostFXPipeline = new Class({
206280
gl.drawArrays(gl.TRIANGLES, 0, 6);
207281

208282
gl.bindTexture(gl.TEXTURE_2D, null);
209-
210-
// this.renderer.resetTextures();
211283
}
212284

213285
});

0 commit comments

Comments
 (0)