Skip to content

Commit a8d1bbc

Browse files
committed
PIXI.AbstractFilter has been merged into the Phaser.Filter class.All references to PIXI.AbstractFilter have been updated to use Phaser.Filter instead.
1 parent 879bcff commit a8d1bbc

8 files changed

Lines changed: 112 additions & 43 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
344344
* Math.isPowerOfTwo will return a boolean if the given width and height are a power of two.
345345
* Color.hexToRGBArray converts a hex color value to an [R, G, B] array.
346346
* Color.RGBArrayToHex converts an RGB color array, in the format: [R, G, B], to a hex color value.
347+
* PIXI.AbstractFilter has been merged into the Phaser.Filter class.All references to PIXI.AbstractFilter have been updated to use Phaser.Filter instead.
347348

348349
### Bug Fixes
349350

@@ -367,6 +368,8 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
367368
* PIXI.TileSprite has been removed as it's no longer used internally.
368369
* PIXI.EarCut has been removed as it's no longer used internally.
369370
* PIXI.Utils has been removed. All functionality is now available in Phaser.
371+
* PIXI.EventTarget has been removed as it's no longer used internally.
372+
* PIXI.AbstractFilter has been removed as it's no longer used internally. All functionality is now available via Phaser.Filter.
370373

371374
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
372375

build/config.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292
<script src="$path/src/pixi/textures/BaseTexture.js"></script>
9393
<script src="$path/src/pixi/textures/Texture.js"></script>
9494
95-
<script src="$path/src/pixi/filters/AbstractFilter.js"></script>
96-
9795
<script src="$path/src/Phaser.js"></script>
9896
<script src="$path/src/polyfills.js"></script>
9997
<script src="$path/src/utils/Utils.js"></script>

src/core/Filter.js

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
/**
22
* @author Richard Davey <rich@photonstorm.com>
3+
* @author Mat Groves (@Doormat23)
34
* @copyright 2016 Photon Storm Ltd.
45
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
56
*/
67

78
/**
89
* This is a base Filter class to use for any Phaser filter development.
10+
* If you want to make a custom filter, this should be your base class.
11+
*
12+
* The default uniforms, types and values for all Filters are:
13+
*
14+
* ```
15+
* resolution: { type: '2f', value: { x: 256, y: 256 }}
16+
* time: { type: '1f', value: 0 }
17+
* mouse: { type: '2f', value: { x: 0.0, y: 0.0 } }
18+
* date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] }
19+
* sampleRate: { type: '1f', value: 44100.0 }
20+
* iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } }
21+
* iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } }
22+
* iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } }
23+
* iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }
24+
* ```
925
*
1026
* The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and
1127
* therefore only work in WebGL and are not supported by Canvas at all.
1228
*
1329
* @class Phaser.Filter
1430
* @constructor
1531
* @param {Phaser.Game} game - A reference to the currently running game.
16-
* @param {object} uniforms - Uniform mappings object
17-
* @param {Array|string} fragmentSrc - The fragment shader code. Either an array, one element per line of code, or a string.
32+
* @param {object} [uniforms] - Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same.
33+
* @param {Array|string} [fragmentSrc] - The fragment shader code. Either an array, one element per line of code, or a string.
1834
*/
1935
Phaser.Filter = function (game, uniforms, fragmentSrc) {
2036

@@ -35,7 +51,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
3551
* @property {array} passes - An array of filter objects.
3652
* @private
3753
*/
38-
this.passes = [this];
54+
this.passes = [ this ];
3955

4056
/**
4157
* @property {array} shaders - Array an array of shaders.
@@ -83,7 +99,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
8399

84100
};
85101

86-
// Copy over/replace any passed in the constructor
102+
// Copy over / replace any passed in the constructor
87103
if (uniforms)
88104
{
89105
for (var key in uniforms)
@@ -92,25 +108,35 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
92108
}
93109
}
94110

111+
// If fragmentSrc is a string, split it based on new-lines into an array
112+
if (typeof fragmentSrc === 'string')
113+
{
114+
fragmentSrc = fragmentSrc.split('\n');
115+
}
116+
95117
/**
96118
* @property {array|string} fragmentSrc - The fragment shader code.
97119
*/
98-
this.fragmentSrc = fragmentSrc || '';
120+
this.fragmentSrc = fragmentSrc || [];
99121

100122
};
101123

102124
Phaser.Filter.prototype = {
103125

104126
/**
105-
* Should be over-ridden.
127+
* This should be over-ridden. Will receive a variable number of arguments.
128+
*
106129
* @method Phaser.Filter#init
107130
*/
108131
init: function () {
132+
109133
// This should be over-ridden. Will receive a variable number of arguments.
134+
110135
},
111136

112137
/**
113138
* Set the resolution uniforms on the filter.
139+
*
114140
* @method Phaser.Filter#setResolution
115141
* @param {number} width - The width of the display.
116142
* @param {number} height - The height of the display.
@@ -124,12 +150,13 @@ Phaser.Filter.prototype = {
124150

125151
/**
126152
* Updates the filter.
153+
*
127154
* @method Phaser.Filter#update
128155
* @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
129156
*/
130157
update: function (pointer) {
131158

132-
if (typeof pointer !== 'undefined')
159+
if (pointer)
133160
{
134161
var x = pointer.x / this.game.width;
135162
var y = 1 - pointer.y / this.game.height;
@@ -201,12 +228,33 @@ Phaser.Filter.prototype = {
201228
},
202229

203230
/**
204-
* Clear down this Filter and null out references
231+
* Syncs the uniforms between the class object and the shaders.
232+
*
233+
* @method Phaser.Filter#syncUniforms
234+
*/
235+
syncUniforms: function () {
236+
237+
for (var i = 0; i < this.shaders.length; i++)
238+
{
239+
this.shaders[i].dirty = true;
240+
}
241+
242+
},
243+
244+
/**
245+
* Clear down this Filter and null out references to game.
246+
*
205247
* @method Phaser.Filter#destroy
206248
*/
207249
destroy: function () {
208250

251+
this.passes.length = 0;
252+
this.shaders.length = 0;
253+
this.fragmentSrc.length = 0;
254+
209255
this.game = null;
256+
this.uniforms = null;
257+
this.prevPoint = null;
210258

211259
}
212260

@@ -220,12 +268,16 @@ Phaser.Filter.prototype.constructor = Phaser.Filter;
220268
*/
221269
Object.defineProperty(Phaser.Filter.prototype, 'width', {
222270

223-
get: function() {
271+
get: function () {
272+
224273
return this.uniforms.resolution.value.x;
274+
225275
},
226276

227-
set: function(value) {
277+
set: function (value) {
278+
228279
this.uniforms.resolution.value.x = value;
280+
229281
}
230282

231283
});
@@ -236,12 +288,16 @@ Object.defineProperty(Phaser.Filter.prototype, 'width', {
236288
*/
237289
Object.defineProperty(Phaser.Filter.prototype, 'height', {
238290

239-
get: function() {
291+
get: function () {
292+
240293
return this.uniforms.resolution.value.y;
294+
241295
},
242296

243-
set: function(value) {
297+
set: function (value) {
298+
244299
this.uniforms.resolution.value.y = value;
300+
245301
}
246302

247303
});

src/pixi/display/DisplayObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ Object.defineProperties(PIXI.DisplayObject.prototype, {
718718
* filter will reset this DisplayObjects blend mode to NORMAL.
719719
*
720720
* @name PIXI.DisplayObject#filters
721-
* @property {Array} filters - An Array of PIXI.AbstractFilter objects, or objects that extend them.
721+
* @property {Array} filters - An Array of Phaser.Filter objects, or objects that extend them.
722722
*/
723723
'filters': {
724724

src/pixi/display/Sprite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ PIXI.Sprite = function (texture) {
9595
* Set to null to remove a current shader.
9696
*
9797
* @property shader
98-
* @type AbstractFilter
98+
* @type Phaser.Filter
9999
* @default null
100100
*/
101101
this.shader = null;

src/pixi/renderers/webgl/WebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ PIXI.WebGLRenderer = function(game) {
144144
* @property spriteBatch
145145
* @type WebGLSpriteBatch
146146
*/
147-
this.spriteBatch = new PIXI.WebGLSpriteBatch();
147+
this.spriteBatch = new PIXI.WebGLSpriteBatch(game);
148148

149149
/**
150150
* Manages the masks using the stencil buffer

src/pixi/renderers/webgl/utils/WebGLFilterManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
337337
* Applies the filter to the specified area.
338338
*
339339
* @method applyFilterPass
340-
* @param filter {AbstractFilter} the filter that needs to be applied
340+
* @param filter {Phaser.Filter} the filter that needs to be applied
341341
* @param filterArea {Texture} TODO - might need an update
342342
* @param width {Number} the horizontal range of the filter
343343
* @param height {Number} the vertical range of the filter

src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
* @private
1616
* @constructor
1717
*/
18-
PIXI.WebGLSpriteBatch = function () {
18+
PIXI.WebGLSpriteBatch = function (game) {
19+
20+
/**
21+
* @property {Phaser.Game} game - A reference to the currently running game.
22+
*/
23+
this.game = game;
24+
1925
/**
2026
* @property vertSize
2127
* @type Number
@@ -136,7 +142,7 @@ PIXI.WebGLSpriteBatch = function () {
136142

137143
/**
138144
* @property defaultShader
139-
* @type AbstractFilter
145+
* @type Phaser.Filter
140146
*/
141147
this.defaultShader = null;
142148
};
@@ -155,32 +161,38 @@ PIXI.WebGLSpriteBatch.prototype.setContext = function (gl) {
155161
index + '.0) gl_FragColor = texture2D(uSamplerArray[' +
156162
index + '], vTextureCoord) * vColor;\n'
157163
}
158-
this.defaultShader = new PIXI.AbstractFilter([
159-
'//WebGLSpriteBatch Fragment Shader.',
160-
'precision lowp float;',
161-
'varying vec2 vTextureCoord;',
162-
'varying vec4 vColor;',
163-
'varying float vTextureIndex;',
164-
'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];',
165-
'void main(void) {',
166-
dynamicIfs,
167-
'\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
168-
'}'
169-
]);
164+
this.defaultShader = new Phaser.Filter(
165+
this.game,
166+
undefined,
167+
[
168+
'//WebGLSpriteBatch Fragment Shader.',
169+
'precision lowp float;',
170+
'varying vec2 vTextureCoord;',
171+
'varying vec4 vColor;',
172+
'varying float vTextureIndex;',
173+
'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];',
174+
'void main(void) {',
175+
dynamicIfs,
176+
'\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
177+
'}'
178+
]);
170179
}
171180
else
172181
{
173-
this.defaultShader = new PIXI.AbstractFilter([
174-
'//WebGLSpriteBatch Fragment Shader.',
175-
'precision lowp float;',
176-
'varying vec2 vTextureCoord;',
177-
'varying vec4 vColor;',
178-
'varying float vTextureIndex;',
179-
'uniform sampler2D uSampler;',
180-
'void main(void) {',
181-
' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;',
182-
'}'
183-
]);
182+
this.defaultShader = new Phaser.Filter(
183+
this.game,
184+
undefined,
185+
[
186+
'//WebGLSpriteBatch Fragment Shader.',
187+
'precision lowp float;',
188+
'varying vec2 vTextureCoord;',
189+
'varying vec4 vColor;',
190+
'varying float vTextureIndex;',
191+
'uniform sampler2D uSampler;',
192+
'void main(void) {',
193+
' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;',
194+
'}'
195+
]);
184196
}
185197

186198
// create a couple of buffers

0 commit comments

Comments
 (0)