PIXI.AbstractFilter has been merged into the Phaser.Filter class.All references to PIXI.AbstractFilter have been updated to use Phaser.Filter instead.

This commit is contained in:
photonstorm 2016-09-28 14:30:15 +01:00
parent 879bcffc88
commit a8d1bbcfdc
8 changed files with 112 additions and 43 deletions

View file

@ -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. * 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.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. * 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 ### 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.TileSprite has been removed as it's no longer used internally.
* PIXI.EarCut 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.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). For changes in previous releases please see the extensive [Version History](https://github.com/photonstorm/phaser/blob/master/CHANGELOG.md).

View file

@ -92,8 +92,6 @@ EOL;
<script src="$path/src/pixi/textures/BaseTexture.js"></script> <script src="$path/src/pixi/textures/BaseTexture.js"></script>
<script src="$path/src/pixi/textures/Texture.js"></script> <script src="$path/src/pixi/textures/Texture.js"></script>
<script src="$path/src/pixi/filters/AbstractFilter.js"></script>
<script src="$path/src/Phaser.js"></script> <script src="$path/src/Phaser.js"></script>
<script src="$path/src/polyfills.js"></script> <script src="$path/src/polyfills.js"></script>
<script src="$path/src/utils/Utils.js"></script> <script src="$path/src/utils/Utils.js"></script>

View file

@ -1,11 +1,27 @@
/** /**
* @author Richard Davey <rich@photonstorm.com> * @author Richard Davey <rich@photonstorm.com>
* @author Mat Groves (@Doormat23)
* @copyright 2016 Photon Storm Ltd. * @copyright 2016 Photon Storm Ltd.
* @license {@link https://github.com/photonstorm/phaser/blob/master/license.txt|MIT License} * @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. * 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 * 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. * therefore only work in WebGL and are not supported by Canvas at all.
@ -13,8 +29,8 @@
* @class Phaser.Filter * @class Phaser.Filter
* @constructor * @constructor
* @param {Phaser.Game} game - A reference to the currently running game. * @param {Phaser.Game} game - A reference to the currently running game.
* @param {object} uniforms - Uniform mappings object * @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. * @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) { Phaser.Filter = function (game, uniforms, fragmentSrc) {
@ -35,7 +51,7 @@ Phaser.Filter = function (game, uniforms, fragmentSrc) {
* @property {array} passes - An array of filter objects. * @property {array} passes - An array of filter objects.
* @private * @private
*/ */
this.passes = [this]; this.passes = [ this ];
/** /**
* @property {array} shaders - Array an array of shaders. * @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) if (uniforms)
{ {
for (var key in 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. * @property {array|string} fragmentSrc - The fragment shader code.
*/ */
this.fragmentSrc = fragmentSrc || ''; this.fragmentSrc = fragmentSrc || [];
}; };
Phaser.Filter.prototype = { Phaser.Filter.prototype = {
/** /**
* Should be over-ridden. * This should be over-ridden. Will receive a variable number of arguments.
*
* @method Phaser.Filter#init * @method Phaser.Filter#init
*/ */
init: function () { init: function () {
// This should be over-ridden. Will receive a variable number of arguments. // This should be over-ridden. Will receive a variable number of arguments.
}, },
/** /**
* Set the resolution uniforms on the filter. * Set the resolution uniforms on the filter.
*
* @method Phaser.Filter#setResolution * @method Phaser.Filter#setResolution
* @param {number} width - The width of the display. * @param {number} width - The width of the display.
* @param {number} height - The height of the display. * @param {number} height - The height of the display.
@ -124,12 +150,13 @@ Phaser.Filter.prototype = {
/** /**
* Updates the filter. * Updates the filter.
*
* @method Phaser.Filter#update * @method Phaser.Filter#update
* @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform. * @param {Phaser.Pointer} [pointer] - A Pointer object to use for the filter. The coordinates are mapped to the mouse uniform.
*/ */
update: function (pointer) { update: function (pointer) {
if (typeof pointer !== 'undefined') if (pointer)
{ {
var x = pointer.x / this.game.width; var x = pointer.x / this.game.width;
var y = 1 - pointer.y / this.game.height; 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 * @method Phaser.Filter#destroy
*/ */
destroy: function () { destroy: function () {
this.passes.length = 0;
this.shaders.length = 0;
this.fragmentSrc.length = 0;
this.game = null; 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', { Object.defineProperty(Phaser.Filter.prototype, 'width', {
get: function() { get: function () {
return this.uniforms.resolution.value.x; return this.uniforms.resolution.value.x;
}, },
set: function(value) { set: function (value) {
this.uniforms.resolution.value.x = value; this.uniforms.resolution.value.x = value;
} }
}); });
@ -236,12 +288,16 @@ Object.defineProperty(Phaser.Filter.prototype, 'width', {
*/ */
Object.defineProperty(Phaser.Filter.prototype, 'height', { Object.defineProperty(Phaser.Filter.prototype, 'height', {
get: function() { get: function () {
return this.uniforms.resolution.value.y; return this.uniforms.resolution.value.y;
}, },
set: function(value) { set: function (value) {
this.uniforms.resolution.value.y = value; this.uniforms.resolution.value.y = value;
} }
}); });

View file

@ -718,7 +718,7 @@ Object.defineProperties(PIXI.DisplayObject.prototype, {
* filter will reset this DisplayObjects blend mode to NORMAL. * filter will reset this DisplayObjects blend mode to NORMAL.
* *
* @name PIXI.DisplayObject#filters * @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': { 'filters': {

View file

@ -95,7 +95,7 @@ PIXI.Sprite = function (texture) {
* Set to null to remove a current shader. * Set to null to remove a current shader.
* *
* @property shader * @property shader
* @type AbstractFilter * @type Phaser.Filter
* @default null * @default null
*/ */
this.shader = null; this.shader = null;

View file

@ -144,7 +144,7 @@ PIXI.WebGLRenderer = function(game) {
* @property spriteBatch * @property spriteBatch
* @type WebGLSpriteBatch * @type WebGLSpriteBatch
*/ */
this.spriteBatch = new PIXI.WebGLSpriteBatch(); this.spriteBatch = new PIXI.WebGLSpriteBatch(game);
/** /**
* Manages the masks using the stencil buffer * Manages the masks using the stencil buffer

View file

@ -337,7 +337,7 @@ PIXI.WebGLFilterManager.prototype.popFilter = function()
* Applies the filter to the specified area. * Applies the filter to the specified area.
* *
* @method applyFilterPass * @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 filterArea {Texture} TODO - might need an update
* @param width {Number} the horizontal range of the filter * @param width {Number} the horizontal range of the filter
* @param height {Number} the vertical range of the filter * @param height {Number} the vertical range of the filter

View file

@ -15,7 +15,13 @@
* @private * @private
* @constructor * @constructor
*/ */
PIXI.WebGLSpriteBatch = function () { PIXI.WebGLSpriteBatch = function (game) {
/**
* @property {Phaser.Game} game - A reference to the currently running game.
*/
this.game = game;
/** /**
* @property vertSize * @property vertSize
* @type Number * @type Number
@ -136,7 +142,7 @@ PIXI.WebGLSpriteBatch = function () {
/** /**
* @property defaultShader * @property defaultShader
* @type AbstractFilter * @type Phaser.Filter
*/ */
this.defaultShader = null; this.defaultShader = null;
}; };
@ -155,32 +161,38 @@ PIXI.WebGLSpriteBatch.prototype.setContext = function (gl) {
index + '.0) gl_FragColor = texture2D(uSamplerArray[' + index + '.0) gl_FragColor = texture2D(uSamplerArray[' +
index + '], vTextureCoord) * vColor;\n' index + '], vTextureCoord) * vColor;\n'
} }
this.defaultShader = new PIXI.AbstractFilter([ this.defaultShader = new Phaser.Filter(
'//WebGLSpriteBatch Fragment Shader.', this.game,
'precision lowp float;', undefined,
'varying vec2 vTextureCoord;', [
'varying vec4 vColor;', '//WebGLSpriteBatch Fragment Shader.',
'varying float vTextureIndex;', 'precision lowp float;',
'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];', 'varying vec2 vTextureCoord;',
'void main(void) {', 'varying vec4 vColor;',
dynamicIfs, 'varying float vTextureIndex;',
'\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;', 'uniform sampler2D uSamplerArray[' + this.MAX_TEXTURES + '];',
'}' 'void main(void) {',
]); dynamicIfs,
'\telse gl_FragColor = texture2D(uSamplerArray[0], vTextureCoord) * vColor;',
'}'
]);
} }
else else
{ {
this.defaultShader = new PIXI.AbstractFilter([ this.defaultShader = new Phaser.Filter(
'//WebGLSpriteBatch Fragment Shader.', this.game,
'precision lowp float;', undefined,
'varying vec2 vTextureCoord;', [
'varying vec4 vColor;', '//WebGLSpriteBatch Fragment Shader.',
'varying float vTextureIndex;', 'precision lowp float;',
'uniform sampler2D uSampler;', 'varying vec2 vTextureCoord;',
'void main(void) {', 'varying vec4 vColor;',
' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;', 'varying float vTextureIndex;',
'}' 'uniform sampler2D uSampler;',
]); 'void main(void) {',
' gl_FragColor = texture2D(uSampler, vTextureCoord) * vColor;',
'}'
]);
} }
// create a couple of buffers // create a couple of buffers