Skip to content

Commit ca4168e

Browse files
committed
New Camera Pipeline, better boot handling, tidied up docs
1 parent 52d8140 commit ca4168e

7 files changed

Lines changed: 102 additions & 30 deletions

File tree

src/renderer/webgl/pipelines/BitmapMaskPipeline.js

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ var BitmapMaskPipeline = new Class({
5151
{
5252
config.fragShader = GetFastValue(config, 'fragShader', ShaderSourceFS),
5353
config.vertShader = GetFastValue(config, 'vertShader', ShaderSourceVS),
54-
config.vertexSize = GetFastValue(config, 'vertexSize', 8),
5554
config.vertexCapacity = GetFastValue(config, 'vertexCapacity', 3),
5655
config.vertices = GetFastValue(config, 'vertices', new Float32Array([ -1, 1, -1, -7, 7, 1 ]).buffer),
5756
config.attributes = GetFastValue(config, 'attributes', [
@@ -71,29 +70,17 @@ var BitmapMaskPipeline = new Class({
7170
WebGLPipeline.call(this, config);
7271
},
7372

74-
/**
75-
* Called every time the pipeline is bound by the renderer.
76-
* Sets the shader program, vertex buffer and other resources.
77-
* Should only be called when changing pipeline.
78-
*
79-
* @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#bind
80-
* @since 3.50.0
81-
*
82-
* @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear?
83-
*
84-
* @return {this} This WebGLPipeline instance.
85-
*/
86-
bind: function (reset)
73+
boot: function ()
8774
{
88-
if (reset === undefined) { reset = false; }
89-
90-
WebGLPipeline.prototype.bind.call(this, reset);
75+
WebGLPipeline.prototype.boot.call(this);
9176

92-
this.set2f('uResolution', this.width, this.height);
9377
this.set1i('uMainSampler', 0);
9478
this.set1i('uMaskSampler', 1);
79+
},
9580

96-
return this;
81+
onResize: function (width, height)
82+
{
83+
this.set2f('uResolution', width, height);
9784
},
9885

9986
/**
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
var Class = require('../../../utils/Class');
8+
var GetFastValue = require('../../../utils/object/GetFastValue');
9+
var MultiPipeline = require('./MultiPipeline');
10+
var ShaderSourceFS = require('../shaders/Single-frag.js');
11+
var ShaderSourceVS = require('../shaders/Single-vert.js');
12+
var WebGLPipeline = require('../WebGLPipeline');
13+
14+
/**
15+
* @classdesc
16+
* The Camera Pipeline is a special version of the Multi Pipeline that only ever
17+
* uses one texture, bound to texture unit zero and with a vertex capacity of 1.
18+
*
19+
* The fragment shader it uses can be found in `shaders/src/Single.frag`.
20+
* The vertex shader it uses can be found in `shaders/src/Single.vert`.
21+
*
22+
* The default shader attributes for this pipeline are:
23+
*
24+
* `inPosition` (vec2, offset 0)
25+
* `inTexCoord` (vec2, offset 8)
26+
* `inTexId` (float, offset 16) - this value is always zero in the Camera Pipeline
27+
* `inTintEffect` (float, offset 20)
28+
* `inTint` (vec4, offset 24, normalized)
29+
*
30+
* The default shader uniforms for this pipeline are:
31+
*
32+
* `uProjectionMatrix` (mat4)
33+
* `uMainSampler` (sampler2D)
34+
*
35+
* @class CameraPipeline
36+
* @extends Phaser.Renderer.WebGL.Pipelines.MultiPipeline
37+
* @memberof Phaser.Renderer.WebGL.Pipelines
38+
* @constructor
39+
* @since 3.50.0
40+
*
41+
* @param {Phaser.Types.Renderer.WebGL.WebGLPipelineConfig} config - The configuration options for this pipeline.
42+
*/
43+
var CameraPipeline = new Class({
44+
45+
Extends: MultiPipeline,
46+
47+
initialize:
48+
49+
function CameraPipeline (config)
50+
{
51+
config.fragShader = GetFastValue(config, 'fragShader', ShaderSourceFS),
52+
config.vertShader = GetFastValue(config, 'vertShader', ShaderSourceVS),
53+
config.vertexCapacity = 1;
54+
config.forceZero = true;
55+
56+
MultiPipeline.call(this, config);
57+
},
58+
59+
boot: function ()
60+
{
61+
WebGLPipeline.prototype.boot.call(this);
62+
63+
this.set1i('uMainSampler', 0);
64+
}
65+
66+
});
67+
68+
module.exports = CameraPipeline;

src/renderer/webgl/pipelines/GraphicsPipeline.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ var GraphicsPipeline = new Class({
9595
'uProjectionMatrix',
9696
'uMainSampler'
9797
]);
98+
config.forceZero = true;
9899

99100
WebGLPipeline.call(this, config);
100101

@@ -227,8 +228,13 @@ var GraphicsPipeline = new Class({
227228
* @since 3.12.0
228229
*/
229230
this.polygonCache = [];
231+
},
232+
233+
boot: function ()
234+
{
235+
WebGLPipeline.prototype.boot.call(this);
230236

231-
this.forceZero = true;
237+
this.set1i('uMainSampler', 0);
232238
},
233239

234240
/**

src/renderer/webgl/pipelines/MultiPipeline.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ var WebGLPipeline = require('../WebGLPipeline');
4242
* The default shader uniforms for this pipeline are:
4343
*
4444
* `uProjectionMatrix` (mat4)
45-
* `uViewMatrix` (mat4)
46-
* `uModelMatrix` (mat4)
4745
* `uMainSampler` (sampler2D array)
4846
*
4947
* If you wish to create a custom pipeline extending from this one, you can use two string
@@ -156,13 +154,11 @@ var MultiPipeline = new Class({
156154
*
157155
* @return {this} This WebGLPipeline instance.
158156
*/
159-
bind: function ()
157+
boot: function ()
160158
{
161-
WebGLPipeline.prototype.bind.call(this);
159+
WebGLPipeline.prototype.boot.call(this);
162160

163161
this.currentShader.set1iv('uMainSampler', this.renderer.textureIndexes);
164-
165-
return this;
166162
},
167163

168164
/**

src/renderer/webgl/pipelines/SinglePipeline.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var GetFastValue = require('../../../utils/object/GetFastValue');
99
var MultiPipeline = require('./MultiPipeline');
1010
var ShaderSourceFS = require('../shaders/Single-frag.js');
1111
var ShaderSourceVS = require('../shaders/Single-vert.js');
12+
var WebGLPipeline = require('../WebGLPipeline');
1213

1314
/**
1415
* @classdesc
@@ -33,8 +34,6 @@ var ShaderSourceVS = require('../shaders/Single-vert.js');
3334
* The default shader uniforms for this pipeline are:
3435
*
3536
* `uProjectionMatrix` (mat4)
36-
* `uViewMatrix` (mat4)
37-
* `uModelMatrix` (mat4)
3837
* `uMainSampler` (sampler2D)
3938
*
4039
* @class SinglePipeline
@@ -55,10 +54,16 @@ var SinglePipeline = new Class({
5554
{
5655
config.fragShader = GetFastValue(config, 'fragShader', ShaderSourceFS),
5756
config.vertShader = GetFastValue(config, 'vertShader', ShaderSourceVS),
57+
config.forceZero = true;
5858

5959
MultiPipeline.call(this, config);
60+
},
6061

61-
this.forceZero = true;
62+
boot: function ()
63+
{
64+
WebGLPipeline.prototype.boot.call(this);
65+
66+
this.set1i('uMainSampler', 0);
6267
}
6368

6469
});

src/renderer/webgl/pipelines/const.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,17 @@ var PIPELINE_CONST = {
6464
* @const
6565
* @since 3.50.0
6666
*/
67-
GRAPHICS_PIPELINE: 'GraphicsPipeline'
67+
GRAPHICS_PIPELINE: 'GraphicsPipeline',
6868

69+
/**
70+
* The Camera Pipeline.
71+
*
72+
* @name Phaser.Renderer.WebGL.Pipelines.CAMERA_PIPELINE
73+
* @type {string}
74+
* @const
75+
* @since 3.50.0
76+
*/
77+
CAMERA_PIPELINE: 'CameraPipeline'
6978
};
7079

7180
module.exports = PIPELINE_CONST;

src/renderer/webgl/pipelines/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Extend = require('../../../utils/object/Extend');
1414
var Pipelines = {
1515

1616
BitmapMaskPipeline: require('./BitmapMaskPipeline'),
17+
CameraPipeline: require('./CameraPipeline'),
1718
GraphicsPipeline: require('./GraphicsPipeline'),
1819
LightPipeline: require('./LightPipeline'),
1920
MultiPipeline: require('./MultiPipeline'),

0 commit comments

Comments
 (0)