Skip to content

Commit cf275b4

Browse files
committed
Added all JSDocs
1 parent 6a97fe6 commit cf275b4

1 file changed

Lines changed: 197 additions & 16 deletions

File tree

src/renderer/webgl/pipelines/UtilityPipeline.js

Lines changed: 197 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,29 @@ var WebGLPipeline = require('../WebGLPipeline');
1717

1818
/**
1919
* @classdesc
20-
* TODO
20+
* The Utility Pipeline is a special-use pipeline that belongs to the Pipeline Manager.
2121
*
22-
* The fragment shader it uses can be found in `shaders/src/PostFX.frag`.
23-
* The vertex shader it uses can be found in `shaders/src/PostFX.vert`.
22+
* It provides 4 shaders and handy associated methods:
23+
*
24+
* 1) Copy Shader. A fast texture to texture copy shader with optional brightness setting.
25+
* 2) Additive Blend Mode Shader. Blends two textures using an additive blend mode.
26+
* 3) Linear Blend Mode Shader. Blends two textures using a linear blend mode.
27+
* 4) Color Matrix Copy Shader. Draws a texture to a target using a Color Matrix.
28+
*
29+
* You typically do not extend or access this pipeline directly, but instead go
30+
* via the following methods in the Pipeline Manager:
31+
*
32+
* `copyFrame`
33+
* `drawFrame`
34+
* `blendFrames`
35+
* `blendFramesAdditive`
2436
*
2537
* The default shader attributes for this pipeline are:
2638
*
2739
* `inPosition` (vec2, offset 0)
2840
* `inTexCoord` (vec2, offset 8)
2941
*
30-
* The default shader uniforms for this pipeline are:
31-
*
32-
* `uProjectionMatrix` (mat4)
33-
* `uMainSampler` (sampler2D)
42+
* This pipeline has a hard-coded batch size of 1 and a hard coded set of vertices.
3443
*
3544
* @class UtilityPipeline
3645
* @extends Phaser.Renderer.WebGL.WebGLPipeline
@@ -48,7 +57,7 @@ var UtilityPipeline = new Class({
4857

4958
function UtilityPipeline (config)
5059
{
51-
config.renderTarget = [
60+
config.renderTarget = GetFastValue(config, 'renderTarget', [
5261
{
5362
scale: 1
5463
},
@@ -61,9 +70,11 @@ var UtilityPipeline = new Class({
6170
{
6271
scale: 0.5
6372
}
64-
];
65-
config.vertShader = QuadVS;
66-
config.shaders = [
73+
]);
74+
75+
config.vertShader = GetFastValue(config, 'vertShader', QuadVS);
76+
77+
config.shaders = GetFastValue(config, 'shaders', [
6778
{
6879
name: 'Copy',
6980
fragShader: CopyFS,
@@ -98,7 +109,8 @@ var UtilityPipeline = new Class({
98109
'uColorMatrix'
99110
]
100111
}
101-
];
112+
]);
113+
102114
config.attributes = GetFastValue(config, 'attributes', [
103115
{
104116
name: 'inPosition',
@@ -113,7 +125,6 @@ var UtilityPipeline = new Class({
113125
]);
114126

115127
// x, y, u, v (x/y in NDC)
116-
117128
config.vertices = new Float32Array([
118129
-1, -1, 0, 0,
119130
-1, 1, 0, 1,
@@ -127,16 +138,123 @@ var UtilityPipeline = new Class({
127138

128139
WebGLPipeline.call(this, config);
129140

141+
/**
142+
* A default Color Matrix, used by the Color Matrix Shader when one
143+
* isn't provided.
144+
*
145+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#colorMatrix
146+
* @type {Phaser.Display.ColorMatrix}
147+
* @since 3.50.0
148+
*/
130149
this.colorMatrix = new ColorMatrix();
131150

151+
/**
152+
* A reference to the Copy Shader belonging to this Utility Pipeline.
153+
*
154+
* This property is set during the `boot` method.
155+
*
156+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#copyShader
157+
* @type {Phaser.Renderer.WebGL.WebGLShader}
158+
* @default null
159+
* @since 3.50.0
160+
*/
132161
this.copyShader;
162+
163+
/**
164+
* A reference to the Additive Blend Shader belonging to this Utility Pipeline.
165+
*
166+
* This property is set during the `boot` method.
167+
*
168+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#addShader
169+
* @type {Phaser.Renderer.WebGL.WebGLShader}
170+
* @since 3.50.0
171+
*/
133172
this.addShader;
173+
174+
/**
175+
* A reference to the Linear Blend Shader belonging to this Utility Pipeline.
176+
*
177+
* This property is set during the `boot` method.
178+
*
179+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#linearShader
180+
* @type {Phaser.Renderer.WebGL.WebGLShader}
181+
* @since 3.50.0
182+
*/
134183
this.linearShader;
184+
185+
/**
186+
* A reference to the Color Matrix Shader belonging to this Utility Pipeline.
187+
*
188+
* This property is set during the `boot` method.
189+
*
190+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#colorMatrixShader
191+
* @type {Phaser.Renderer.WebGL.WebGLShader}
192+
* @since 3.50.0
193+
*/
135194
this.colorMatrixShader;
136195

196+
/**
197+
* A reference to the Full Frame 1 Render Target.
198+
*
199+
* This property is set during the `boot` method.
200+
*
201+
* This Render Target is the full size of the renderer.
202+
*
203+
* You can use this directly in Post FX Pipelines for multi-target effects.
204+
* However, be aware that these targets are shared between all post fx pipelines.
205+
*
206+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#fullFrame1
207+
* @type {Phaser.Renderer.WebGL.RenderTarget}
208+
* @since 3.50.0
209+
*/
137210
this.fullFrame1;
211+
212+
/**
213+
* A reference to the Full Frame 2 Render Target.
214+
*
215+
* This property is set during the `boot` method.
216+
*
217+
* This Render Target is the full size of the renderer.
218+
*
219+
* You can use this directly in Post FX Pipelines for multi-target effects.
220+
* However, be aware that these targets are shared between all post fx pipelines.
221+
*
222+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#fullFrame2
223+
* @type {Phaser.Renderer.WebGL.RenderTarget}
224+
* @since 3.50.0
225+
*/
138226
this.fullFrame2;
227+
228+
/**
229+
* A reference to the Half Frame 1 Render Target.
230+
*
231+
* This property is set during the `boot` method.
232+
*
233+
* This Render Target is half the size of the renderer.
234+
*
235+
* You can use this directly in Post FX Pipelines for multi-target effects.
236+
* However, be aware that these targets are shared between all post fx pipelines.
237+
*
238+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#halfFrame1
239+
* @type {Phaser.Renderer.WebGL.RenderTarget}
240+
* @since 3.50.0
241+
*/
139242
this.halfFrame1;
243+
244+
/**
245+
* A reference to the Half Frame 2 Render Target.
246+
*
247+
* This property is set during the `boot` method.
248+
*
249+
* This Render Target is half the size of the renderer.
250+
*
251+
* You can use this directly in Post FX Pipelines for multi-target effects.
252+
* However, be aware that these targets are shared between all post fx pipelines.
253+
*
254+
* @name Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#halfFrame2
255+
* @type {Phaser.Renderer.WebGL.RenderTarget}
256+
* @since 3.50.0
257+
*/
140258
this.halfFrame2;
141259
},
142260

@@ -156,11 +274,25 @@ var UtilityPipeline = new Class({
156274
this.fullFrame2 = targets[1];
157275
this.halfFrame1 = targets[2];
158276
this.halfFrame2 = targets[3];
159-
160-
console.log(this);
161277
},
162278

163-
// params = RenderTargets
279+
/**
280+
* Copy the `source` Render Target to the `target` Render Target.
281+
*
282+
* You can optionally set the brightness factor of the copy.
283+
*
284+
* The difference between this method and `drawFrame` is that this method
285+
* uses a faster copy shader, where only the brightness can be modified.
286+
* If you need color level manipulation, see `drawFrame` instead.
287+
*
288+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#copyFrame
289+
* @since 3.50.0
290+
*
291+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The source Render Target.
292+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
293+
* @param {number} [brightness=1] - The brightness value applied to the frame copy.
294+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
295+
*/
164296
copyFrame: function (source, target, brightness, clearAlpha)
165297
{
166298
if (brightness === undefined) { brightness = 1; }
@@ -207,6 +339,23 @@ var UtilityPipeline = new Class({
207339
gl.bindTexture(gl.TEXTURE_2D, null);
208340
},
209341

342+
/**
343+
* Copy the `source` Render Target to the `target` Render Target, using the
344+
* given Color Matrix.
345+
*
346+
* The difference between this method and `copyFrame` is that this method
347+
* uses a color matrix shader, where you have full control over the luminance
348+
* values used during the copy. If you don't need this, you can use the faster
349+
* `copyFrame` method instead.
350+
*
351+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#drawFrame
352+
* @since 3.50.0
353+
*
354+
* @param {Phaser.Renderer.WebGL.RenderTarget} source - The source Render Target.
355+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
356+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
357+
* @param {Phaser.Display.ColorMatrix} [colorMatrix] - The Color Matrix to use when performing the draw.
358+
*/
210359
drawFrame: function (source, target, clearAlpha, colorMatrix)
211360
{
212361
if (clearAlpha === undefined) { clearAlpha = true; }
@@ -243,6 +392,20 @@ var UtilityPipeline = new Class({
243392
gl.bindTexture(gl.TEXTURE_2D, null);
244393
},
245394

395+
/**
396+
* Draws the `source1` and `source2` Render Targets to the `target` Render Target
397+
* using a linear blend effect, which is controlled by the `strength` parameter.
398+
*
399+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#blendFrames
400+
* @since 3.50.0
401+
*
402+
* @param {Phaser.Renderer.WebGL.RenderTarget} source1 - The first source Render Target.
403+
* @param {Phaser.Renderer.WebGL.RenderTarget} source2 - The second source Render Target.
404+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
405+
* @param {number} [strength=1] - The strength of the blend.
406+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
407+
* @param {Phaser.Renderer.WebGL.WebGLShader} [blendShader] - The shader to use during the blend copy.
408+
*/
246409
blendFrames: function (source1, source2, target, strength, clearAlpha, blendShader)
247410
{
248411
if (strength === undefined) { strength = 1; }
@@ -287,6 +450,24 @@ var UtilityPipeline = new Class({
287450
gl.drawArrays(gl.TRIANGLES, 0, 6);
288451

289452
gl.bindTexture(gl.TEXTURE_2D, null);
453+
},
454+
455+
/**
456+
* Draws the `source1` and `source2` Render Targets to the `target` Render Target
457+
* using an additive blend effect, which is controlled by the `strength` parameter.
458+
*
459+
* @method Phaser.Renderer.WebGL.Pipelines.UtilityPipeline#blendFramesAdditive
460+
* @since 3.50.0
461+
*
462+
* @param {Phaser.Renderer.WebGL.RenderTarget} source1 - The first source Render Target.
463+
* @param {Phaser.Renderer.WebGL.RenderTarget} source2 - The second source Render Target.
464+
* @param {Phaser.Renderer.WebGL.RenderTarget} [target] - The target Render Target.
465+
* @param {number} [strength=1] - The strength of the blend.
466+
* @param {boolean} [clearAlpha=true] - Clear the alpha channel when running `gl.clear` on the target?
467+
*/
468+
blendFramesAdditive: function (source1, source2, target, strength, clearAlpha)
469+
{
470+
this.blendFrames(source1, source2, target, strength, clearAlpha, this.addShader);
290471
}
291472

292473
});

0 commit comments

Comments
 (0)