Skip to content

Commit 39118a2

Browse files
authored
Merge pull request phaserjs#4700 from cristlee/master
add an optional textureData when initialize shader
2 parents 65c6cec + 217d1da commit 39118a2

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/gameobjects/shader/Shader.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ var TransformMatrix = require('../components/TransformMatrix');
7777
* @param {number} [width=128] - The width of the Game Object.
7878
* @param {number} [height=128] - The height of the Game Object.
7979
* @param {string[]} [textures] - Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager.
80+
* @param {any} [textureData] - Additional texture data if you want to create shader with none NPOT textures.
8081
*/
8182
var Shader = new Class({
8283

@@ -96,7 +97,7 @@ var Shader = new Class({
9697

9798
initialize:
9899

99-
function Shader (scene, key, x, y, width, height, textures)
100+
function Shader (scene, key, x, y, width, height, textures, textureData)
100101
{
101102
if (x === undefined) { x = 0; }
102103
if (y === undefined) { y = 0; }
@@ -348,7 +349,7 @@ var Shader = new Class({
348349
this.setPosition(x, y);
349350
this.setSize(width, height);
350351
this.setOrigin(0.5, 0.5);
351-
this.setShader(key, textures);
352+
this.setShader(key, textures, textureData);
352353
},
353354

354355
/**
@@ -469,10 +470,11 @@ var Shader = new Class({
469470
*
470471
* @param {(string|Phaser.Display.BaseShader)} key - The key of the shader to use from the shader cache, or a BaseShader instance.
471472
* @param {string[]} [textures] - Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager.
473+
* @param {any} [textureData] - Additional texture data.
472474
*
473475
* @return {this} This Shader instance.
474476
*/
475-
setShader: function (key, textures)
477+
setShader: function (key, textures, textureData)
476478
{
477479
if (textures === undefined) { textures = []; }
478480

@@ -538,7 +540,7 @@ var Shader = new Class({
538540
{
539541
if (textures[i])
540542
{
541-
this.setSampler2D('iChannel' + i, textures[i], i);
543+
this.setSampler2D('iChannel' + i, textures[i], i, textureData);
542544
}
543545
}
544546

src/gameobjects/shader/ShaderFactory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ var GameObjectFactory = require('../GameObjectFactory');
2222
* @param {number} [width=128] - The width of the Game Object.
2323
* @param {number} [height=128] - The height of the Game Object.
2424
* @param {string[]} [textures] - Optional array of texture keys to bind to the iChannel0...3 uniforms. The textures must already exist in the Texture Manager.
25+
* @param {object} [textureData] - Optional additional texture data.
2526
*
2627
* @return {Phaser.GameObjects.Shader} The Game Object that was created.
2728
*/
2829
if (typeof WEBGL_RENDERER)
2930
{
30-
GameObjectFactory.register('shader', function (key, x, y, width, height, textures)
31+
GameObjectFactory.register('shader', function (key, x, y, width, height, textures, textureData)
3132
{
32-
return this.displayList.add(new Shader(this.scene, key, x, y, width, height, textures));
33+
return this.displayList.add(new Shader(this.scene, key, x, y, width, height, textures, textureData));
3334
});
3435
}

0 commit comments

Comments
 (0)