diff --git a/README.md b/README.md
index 3a4cd38e5..3df11e10b 100644
--- a/README.md
+++ b/README.md
@@ -344,6 +344,7 @@ You can read all about the philosophy behind Lazer [here](http://phaser.io/news/
* Math.isPowerOfTwo will return a boolean if the given width and height are a power of two.
* Color.hexToRGBArray converts a hex color value to an [R, G, B] array.
* Color.RGBArrayToHex converts an RGB color array, in the format: [R, G, B], to a hex color value.
+* PIXI.AbstractFilter has been merged into the Phaser.Filter class.All references to PIXI.AbstractFilter have been updated to use Phaser.Filter instead.
### Bug Fixes
@@ -367,6 +368,8 @@ Please note that Phaser uses a custom build of Pixi and always has done. The fol
* PIXI.TileSprite has been removed as it's no longer used internally.
* PIXI.EarCut has been removed as it's no longer used internally.
* PIXI.Utils has been removed. All functionality is now available in Phaser.
+* PIXI.EventTarget has been removed as it's no longer used internally.
+* PIXI.AbstractFilter has been removed as it's no longer used internally. All functionality is now available via Phaser.Filter.
For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).
diff --git a/build/config.php b/build/config.php
index 99c6e18fd..13682b514 100644
--- a/build/config.php
+++ b/build/config.php
@@ -92,8 +92,6 @@ EOL;
-
-
diff --git a/src/core/Filter.js b/src/core/Filter.js
index cd9e432db..207e45cfc 100644
--- a/src/core/Filter.js
+++ b/src/core/Filter.js
@@ -1,11 +1,27 @@
/**
* @author Richard Davey
+* @author Mat Groves (@Doormat23)
* @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License}
*/
/**
* This is a base Filter class to use for any Phaser filter development.
+* If you want to make a custom filter, this should be your base class.
+*
+* The default uniforms, types and values for all Filters are:
+*
+* ```
+* resolution: { type: '2f', value: { x: 256, y: 256 }}
+* time: { type: '1f', value: 0 }
+* mouse: { type: '2f', value: { x: 0.0, y: 0.0 } }
+* date: { type: '4fv', value: [ d.getFullYear(), d.getMonth(), d.getDate(), d.getHours() *60 * 60 + d.getMinutes() * 60 + d.getSeconds() ] }
+* sampleRate: { type: '1f', value: 44100.0 }
+* iChannel0: { type: 'sampler2D', value: null, textureData: { repeat: true } }
+* iChannel1: { type: 'sampler2D', value: null, textureData: { repeat: true } }
+* iChannel2: { type: 'sampler2D', value: null, textureData: { repeat: true } }
+* iChannel3: { type: 'sampler2D', value: null, textureData: { repeat: true } }
+* ```
*
* The vast majority of filters (including all of those that ship with Phaser) use fragment shaders, and
* therefore only work in WebGL and are not supported by Canvas at all.
@@ -13,8 +29,8 @@
* @class Phaser.Filter
* @constructor
* @param {Phaser.Game} game - A reference to the currently running game.
-* @param {object} uniforms - Uniform mappings object
-* @param {Array|string} fragmentSrc - The fragment shader code. Either an array, one element per line of code, or a string.
+* @param {object} [uniforms] - Uniform mappings object. The uniforms are added on the default uniforms, or replace them if the keys are the same.
+* @param {Array|string} [fragmentSrc] - The fragment shader code. Either an array, one element per line of code, or a string.
*/
Phaser.Filter = function (game, uniforms, fragmentSrc) {
@@ -35,7 +51,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
* @property {array} passes - An array of filter objects.
* @private
*/
- this.passes = [this];
+ this.passes = [ this ];
/**
* @property {array} shaders - Array an array of shaders.
@@ -83,7 +99,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
};
- // Copy over/replace any passed in the constructor
+ // Copy over / replace any passed in the constructor
if (uniforms)
{
for (var key in uniforms)
@@ -92,25 +108,35 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
}
}
+ // If fragmentSrc is a string, split it based on new-lines into an array
+ if (typeof fragmentSrc === 'string')
+ {
+ fragmentSrc = fragmentSrc.split('\n');
+ }
+
/**
* @property {array|string} fragmentSrc - The fragment shader code.
*/
- this.fragmentSrc = fragmentSrc || '';
+ this.fragmentSrc = fragmentSrc || [];
};
Phaser.Filter.prototype = {
/**
- * Should be over-ridden.
+ * This should be over-ridden. Will receive a variable number of arguments.
+ *
* @method Phaser.Filter#init
*/
init: function () {
+
// This should be over-ridden. Will receive a variable number of arguments.
+
},
/**
* Set the resolution uniforms on the filter.
+ *
* @method Phaser.Filter#setResolution
* @param {number} width - The width of the display.
* @param {number} height - The height of the display.
@@ -124,12 +150,13 @@ Phaser.Filter.prototype = {
/**
* Updates the filter.
+ *
* @method Phaser.Filter#update
* @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
*/
update: function (pointer) {
- if (typeof pointer !== 'undefined')
+ if (pointer)
{
var x = pointer.x / this.game.width;
var y = 1 - pointer.y / this.game.height;
@@ -201,12 +228,33 @@ Phaser.Filter.prototype = {
},
/**
- * Clear down this Filter and null out references
+ * Syncs the uniforms between the class object and the shaders.
+ *
+ * @method Phaser.Filter#syncUniforms
+ */
+ syncUniforms: function () {
+
+ for (var i = 0; i < this.shaders.length; i++)
+ {
+ this.shaders[i].dirty = true;
+ }
+
+ },
+
+ /**
+ * Clear down this Filter and null out references to game.
+ *
* @method Phaser.Filter#destroy
*/
destroy: function () {
+ this.passes.length = 0;
+ this.shaders.length = 0;
+ this.fragmentSrc.length = 0;
+
this.game = null;
+ this.uniforms = null;
+ this.prevPoint = null;
}
@@ -220,12 +268,16 @@ Phaser.Filter.prototype.constructor = Phaser.Filter;
*/
Object.defineProperty(Phaser.Filter.prototype, 'width', {
- get: function() {
+ get: function () {
+
return this.uniforms.resolution.value.x;
+
},
- set: function(value) {
+ set: function (value) {
+
this.uniforms.resolution.value.x = value;
+
}
});
@@ -236,12 +288,16 @@ Object.defineProperty(Phaser.Filter.prototype, 'width', {
*/
Object.defineProperty(Phaser.Filter.prototype, 'height', {
- get: function() {
+ get: function () {
+
return this.uniforms.resolution.value.y;
+
},
- set: function(value) {
+ set: function (value) {
+
this.uniforms.resolution.value.y = value;
+
}
});
diff --git a/src/pixi/display/DisplayObject.js b/src/pixi/display/DisplayObject.js
index e99bc03d3..60d39e037 100644
--- a/src/pixi/display/DisplayObject.js
+++ b/src/pixi/display/DisplayObject.js
@@ -718,7 +718,7 @@ Object.defineProperties(PIXI.DisplayObject.prototype, {
* filter will reset this DisplayObjects blend mode to NORMAL.
*
* @name PIXI.DisplayObject#filters
- * @property {Array} filters - An Array of PIXI.AbstractFilter objects, or objects that extend them.
+ * @property {Array} filters - An Array of Phaser.Filter objects, or objects that extend them.
*/
'filters': {
diff --git a/src/pixi/display/Sprite.js b/src/pixi/display/Sprite.js
index d8fc5dde3..49ce59bcb 100644
--- a/src/pixi/display/Sprite.js
+++ b/src/pixi/display/Sprite.js
@@ -95,7 +95,7 @@ PIXI.Sprite = function (texture) {
* Set to null to remove a current shader.
*
* @property shader
- * @type AbstractFilter
+ * @type Phaser.Filter
* @default null
*/
this.shader = null;
diff --git a/src/pixi/renderers/webgl/WebGLRenderer.js b/src/pixi/renderers/webgl/WebGLRenderer.js
index e4bc52554..c488934cf 100644
--- a/src/pixi/renderers/webgl/WebGLRenderer.js
+++ b/src/pixi/renderers/webgl/WebGLRenderer.js
@@ -144,7 +144,7 @@ PIXI.WebGLRenderer = function(game) {
* @property spriteBatch
* @type WebGLSpriteBatch
*/
- this.spriteBatch = new PIXI.WebGLSpriteBatch();
+ this.spriteBatch = new PIXI.WebGLSpriteBatch(game);
/**
* Manages the masks using the stencil buffer
diff --git a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js
index 8268c701a..c6c9a23bc 100644
--- a/src/pixi/renderers/webgl/utils/WebGLFilterManager.js
+++ b/src/pixi/renderers/webgl/utils/WebGLFilterManager.js
@@ -337,7 +337,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
* Applies the filter to the specified area.
*
* @method applyFilterPass
-* @param filter {AbstractFilter} the filter that needs to be applied
+* @param filter {Phaser.Filter} the filter that needs to be applied
* @param filterArea {Texture} TODO - might need an update
* @param width {Number} the horizontal range of the filter
* @param height {Number} the vertical range of the filter
diff --git a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js
index 5e91f9bac..0177bf4c2 100644
--- a/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js
+++ b/src/pixi/renderers/webgl/utils/WebGLSpriteBatch.js
@@ -15,7 +15,13 @@
* @private
* @constructor
*/
-PIXI.WebGLSpriteBatch = function () {
+PIXI.WebGLSpriteBatch = function (game) {
+
+ /**
+ * @property {Phaser.Game} game - A reference to the currently running game.
+ */
+ this.game = game;
+
/**
* @property vertSize
* @type Number
@@ -136,7 +142,7 @@ PIXI.WebGLSpriteBatch = function () {
/**
* @property defaultShader
- * @type AbstractFilter
+ * @type Phaser.Filter
*/
this.defaultShader = null;
};
@@ -155,32 +161,38 @@ PIXI.WebGLSpriteBatch.prototype.setContext = function (gl) {
index + '.0) gl_FragColor = texture2D(uSamplerArray[' +
index + '], vTextureCoord) * vColor;\n'
}
- this.defaultShader = new PIXI.AbstractFilter([
- '//WebGLSpriteBatch Fragment Shader.',
- 'precision lowp float;',
- 'varying vec2 vTextureCoord;',
- 'varying vec4 vColor;',
- 'varying float vTextureIndex;',
- 'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];',
- 'void main(void) {',
- dynamicIfs,
- '\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
- '}'
- ]);
+ this.defaultShader = new Phaser.Filter(
+ this.game,
+ undefined,
+ [
+ '//WebGLSpriteBatch Fragment Shader.',
+ 'precision lowp float;',
+ 'varying vec2 vTextureCoord;',
+ 'varying vec4 vColor;',
+ 'varying float vTextureIndex;',
+ 'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];',
+ 'void main(void) {',
+ dynamicIfs,
+ '\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
+ '}'
+ ]);
}
else
{
- this.defaultShader = new PIXI.AbstractFilter([
- '//WebGLSpriteBatch Fragment Shader.',
- 'precision lowp float;',
- 'varying vec2 vTextureCoord;',
- 'varying vec4 vColor;',
- 'varying float vTextureIndex;',
- 'uniform sampler2D uSampler;',
- 'void main(void) {',
- ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;',
- '}'
- ]);
+ this.defaultShader = new Phaser.Filter(
+ this.game,
+ undefined,
+ [
+ '//WebGLSpriteBatch Fragment Shader.',
+ 'precision lowp float;',
+ 'varying vec2 vTextureCoord;',
+ 'varying vec4 vColor;',
+ 'varying float vTextureIndex;',
+ 'uniform sampler2D uSampler;',
+ 'void main(void) {',
+ ' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;',
+ '}'
+ ]);
}
// create a couple of buffers