Skip to content

Commit 0538134

Browse files
committed
Merge branch 'master' of https://github.com/photonstorm/phaser
2 parents 1e6bfe6 + 6e82760 commit 0538134

9 files changed

Lines changed: 328 additions & 60 deletions

File tree

src/phaser.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ var Phaser = {
3333
Loader: require('./loader'),
3434
Math: require('./math'),
3535
Physics: require('./physics'),
36+
Renderer: require('./renderer'),
3637
Scene: require('./scene/Scene'),
3738
Scenes: require('./scene'),
3839
Sound: require('./sound'),

src/renderer/webgl/WebGLPipeline.js

Lines changed: 232 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,33 @@ var WebGLPipeline = new Class({
198198
this.flushLocked = false;
199199
},
200200

201+
/**
202+
* [description]
203+
*
204+
* @method Phaser.Renderer.WebGL.WebGLPipeline#addAttribute
205+
* @since 3.2.0
206+
*
207+
* @param {string} name - [description]
208+
* @param {int} size - [description]
209+
* @param {int} type - [description]
210+
* @param {boolean} normalized - [description]
211+
* @param {int} offset - [description]
212+
*
213+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
214+
*/
215+
addAttribute: function (name, size, type, normalized, offset)
216+
{
217+
this.attributes.push({
218+
name: name,
219+
size: size,
220+
type: this.renderer.glFormats[type],
221+
normalized: normalized,
222+
offset: offset
223+
});
224+
225+
return this;
226+
},
227+
201228
/**
202229
* [description]
203230
*
@@ -381,6 +408,211 @@ var WebGLPipeline = new Class({
381408
delete this.vertexBuffer;
382409
delete this.gl;
383410

411+
return this;
412+
},
413+
414+
/**
415+
* [description]
416+
*
417+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat1
418+
* @since 3.2.0
419+
*
420+
* @param {string} name - [description]
421+
* @param {float} x - [description]
422+
*
423+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
424+
*/
425+
setFloat1: function (name, x)
426+
{
427+
this.renderer.setFloat1(this.program, name, x);
428+
return this;
429+
},
430+
431+
/**
432+
* [description]
433+
*
434+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat2
435+
* @since 3.2.0
436+
*
437+
* @param {string} name - [description]
438+
* @param {float} x - [description]
439+
* @param {float} y - [description]
440+
*
441+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
442+
*/
443+
setFloat2: function (name, x, y)
444+
{
445+
446+
this.renderer.setFloat2(this.program, name, x, y);
447+
return this;
448+
},
449+
450+
/**
451+
* [description]
452+
*
453+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat3
454+
* @since 3.2.0
455+
*
456+
* @param {string} name - [description]
457+
* @param {float} x - [description]
458+
* @param {float} y - [description]
459+
* @param {float} z - [description]
460+
*
461+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
462+
*/
463+
setFloat3: function (name, x, y, z)
464+
{
465+
466+
this.renderer.setFloat3(this.program, name, x, y, z);
467+
return this;
468+
},
469+
470+
/**
471+
* [description]
472+
*
473+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setFloat4
474+
* @since 3.2.0
475+
*
476+
* @param {string} name - [description]
477+
* @param {float} x - [description]
478+
* @param {float} y - [description]
479+
* @param {float} z - [description]
480+
* @param {float} w - [description]
481+
*
482+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
483+
*/
484+
setFloat4: function (name, x, y, z, w)
485+
{
486+
487+
this.renderer.setFloat4(this.program, name, x, y, z, w);
488+
return this;
489+
},
490+
491+
/**
492+
* [description]
493+
*
494+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt1
495+
* @since 3.2.0
496+
*
497+
* @param {string} name - [description]
498+
* @param {int} x - [description]
499+
*
500+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
501+
*/
502+
setInt1: function (name, x)
503+
{
504+
this.renderer.setInt1(this.program, name, x);
505+
return this;
506+
},
507+
508+
/**
509+
* [description]
510+
*
511+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt2
512+
* @since 3.2.0
513+
*
514+
* @param {string} name - [description]
515+
* @param {int} x - [description]
516+
* @param {int} y - [description]
517+
*
518+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
519+
*/
520+
setInt2: function (name, x, y)
521+
{
522+
this.renderer.setInt2(this.program, name, x, y);
523+
return this;
524+
},
525+
526+
/**
527+
* [description]
528+
*
529+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt3
530+
* @since 3.2.0
531+
*
532+
* @param {string} name - [description]
533+
* @param {int} x - [description]
534+
* @param {int} y - [description]
535+
* @param {int} z - [description]
536+
*
537+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
538+
*/
539+
setInt3: function (name, x, y, z)
540+
{
541+
this.renderer.setInt3(this.program, name, x, y, z);
542+
return this;
543+
},
544+
545+
/**
546+
* [description]
547+
*
548+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setInt4
549+
* @since 3.2.0
550+
*
551+
* @param {string} name - [description]
552+
* @param {int} x - [description]
553+
* @param {int} y - [description]
554+
* @param {int} z - [description]
555+
* @param {int} w - [description]
556+
*
557+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
558+
*/
559+
setInt4: function (name, x, y, z, w)
560+
{
561+
this.renderer.setInt4(this.program, name, x, y, z, w);
562+
return this;
563+
},
564+
565+
/**
566+
* [description]
567+
*
568+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix2
569+
* @since 3.2.0
570+
*
571+
* @param {string} name - [description]
572+
* @param {boolean} transpose - [description]
573+
* @param {Float32Array} matrix - [description]
574+
*
575+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
576+
*/
577+
setMatrix2: function (name, transpose, matrix)
578+
{
579+
this.renderer.setMatrix2(this.program, name, transpose, matrix);
580+
return this;
581+
},
582+
583+
/**
584+
* [description]
585+
*
586+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix3
587+
* @since 3.2.0
588+
*
589+
* @param {string} name - [description]
590+
* @param {boolean} transpose - [description]
591+
* @param {Float32Array} matrix - [description]
592+
*
593+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
594+
*/
595+
setMatrix3: function (name, transpose, matrix)
596+
{
597+
this.renderer.setMatrix3(this.program, name, transpose, matrix);
598+
return this;
599+
},
600+
601+
/**
602+
* [description]
603+
*
604+
* @method Phaser.Renderer.WebGL.WebGLPipeline#setMatrix4
605+
* @since 3.2.0
606+
*
607+
* @param {string} name - [description]
608+
* @param {boolean} transpose - [description]
609+
* @param {Float32Array} matrix - [description]
610+
*
611+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
612+
*/
613+
setMatrix4: function (name, transpose, matrix)
614+
{
615+
this.renderer.setMatrix4(this.program, name, transpose, matrix);
384616
return this;
385617
}
386618

src/renderer/webgl/WebGLRenderer.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,16 @@ var WebGLRenderer = new Class({
354354
*/
355355
this.extensions = {};
356356

357+
/**
358+
* [description]
359+
*
360+
* @name Phaser.Renderer.WebGL.WebGLRenderer#glFormats
361+
* @type {array}
362+
* @default []
363+
* @since 3.2.0
364+
*/
365+
this.glFormats = [];
366+
357367
this.init(this.config);
358368
},
359369

@@ -390,6 +400,12 @@ var WebGLRenderer = new Class({
390400
this.blendModes[2].func = [ gl.DST_COLOR, gl.ONE_MINUS_SRC_ALPHA ];
391401
this.blendModes[3].func = [ gl.ONE, gl.ONE_MINUS_SRC_COLOR ];
392402

403+
this.glFormats[0] = gl.BYTE;
404+
this.glFormats[1] = gl.SHORT;
405+
this.glFormats[2] = gl.UNSIGNED_BYTE;
406+
this.glFormats[3] = gl.UNSIGNED_SHORT;
407+
this.glFormats[4] = gl.FLOAT;
408+
393409
// Load supported extensions
394410
this.supportedExtensions = gl.getSupportedExtensions();
395411

@@ -409,10 +425,10 @@ var WebGLRenderer = new Class({
409425
// Clear previous pipelines and reload default ones
410426
this.pipelines = {};
411427

412-
this.addPipeline('TextureTintPipeline', new TextureTintPipeline(this.game, gl, this));
413-
this.addPipeline('FlatTintPipeline', new FlatTintPipeline(this.game, gl, this));
414-
this.addPipeline('BitmapMaskPipeline', new BitmapMaskPipeline(this.game, gl, this));
415-
this.addPipeline('Light2D', new ForwardDiffuseLightPipeline(this.game, gl, this));
428+
this.addPipeline('TextureTintPipeline', new TextureTintPipeline({ game: this.game, renderer: this }));
429+
this.addPipeline('FlatTintPipeline', new FlatTintPipeline({ game: this.game, renderer: this }));
430+
this.addPipeline('BitmapMaskPipeline', new BitmapMaskPipeline({ game: this.game, renderer: this }));
431+
this.addPipeline('Light2D', new ForwardDiffuseLightPipeline({ game: this.game, renderer: this }));
416432

417433
this.setBlendMode(CONST.BlendModes.NORMAL);
418434
this.resize(this.width, this.height);
@@ -602,7 +618,7 @@ var WebGLRenderer = new Class({
602618
* @param {string} pipelineName - [description]
603619
* @param {Phaser.Renderer.WebGL.WebGLPipeline} pipelineInstance - [description]
604620
*
605-
* @return {Phaser.Renderer.WebGL.WebGLRenderer} [description]
621+
* @return {Phaser.Renderer.WebGL.WebGLPipeline} [description]
606622
*/
607623
addPipeline: function (pipelineName, pipelineInstance)
608624
{
@@ -612,7 +628,7 @@ var WebGLRenderer = new Class({
612628
pipelineInstance.name = pipelineName;
613629
this.pipelines[pipelineName].resize(this.width, this.height, this.config.resolution);
614630

615-
return this;
631+
return pipelineInstance;
616632
},
617633

618634
/**

src/renderer/webgl/index.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ module.exports = {
1212

1313
Utils: require('./Utils'),
1414
WebGLPipeline: require('./WebGLPipeline'),
15-
WebGLRenderer: require('./WebGLRenderer')
15+
WebGLRenderer: require('./WebGLRenderer'),
16+
Pipelines: require('./pipelines'),
17+
18+
// Constants
19+
BYTE: 0,
20+
SHORT: 1,
21+
UNSIGNED_BYTE: 2,
22+
UNSIGNED_SHORT: 3,
23+
FLOAT: 4
1624

1725
};

src/renderer/webgl/pipelines/BitmapMaskPipeline.js

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,27 @@ var WebGLPipeline = require('../WebGLPipeline');
1919
* @constructor
2020
* @since 3.0.0
2121
*
22-
* @param {Phaser.Game} game - [description]
23-
* @param {WebGLRenderingContext} gl - [description]
24-
* @param {Phaser.Renderer.WebGL.WebGLRenderer} renderer - [description]
22+
* @param {object} config - [description]
2523
*/
2624
var BitmapMaskPipeline = new Class({
2725

2826
Extends: WebGLPipeline,
2927

3028
initialize:
3129

32-
function BitmapMaskPipeline (game, gl, renderer)
30+
function BitmapMaskPipeline (config)
3331
{
3432
WebGLPipeline.call(this, {
35-
game: game,
36-
gl: gl,
37-
renderer: renderer,
38-
topology: gl.TRIANGLES,
39-
vertShader: ShaderSourceVS,
40-
fragShader: ShaderSourceFS,
41-
vertexCapacity: 3,
33+
game: config.game,
34+
renderer: config.renderer,
35+
gl: config.renderer.gl,
36+
topology: (config.topology ? config.topology : config.renderer.gl.TRIANGLES),
37+
vertShader: (config.vertShader ? config.vertShader : ShaderSourceVS),
38+
fragShader: (config.fragShader ? config.fragShader : ShaderSourceFS),
39+
vertexCapacity: (config.vertexCapacity ? config.vertexCapacity : 3),
4240

43-
vertexSize:
44-
Float32Array.BYTES_PER_ELEMENT * 2,
41+
vertexSize: (config.vertexSize ? config.vertexSize :
42+
Float32Array.BYTES_PER_ELEMENT * 2),
4543

4644
vertices: new Float32Array([
4745
-1, +1, -1, -7, +7, +1
@@ -51,7 +49,7 @@ var BitmapMaskPipeline = new Class({
5149
{
5250
name: 'inPosition',
5351
size: 2,
54-
type: gl.FLOAT,
52+
type: config.renderer.gl.FLOAT,
5553
normalized: false,
5654
offset: 0
5755
}

0 commit comments

Comments
 (0)