Skip to content

Commit 389b480

Browse files
committed
Using new easier attribute config + moved some methods to WebGLPipeline
1 parent 15d8eab commit 389b480

1 file changed

Lines changed: 8 additions & 250 deletions

File tree

src/renderer/webgl/pipelines/MultiPipeline.js

Lines changed: 8 additions & 250 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var ShaderSourceFS = require('../shaders/Multi-frag.js');
1212
var ShaderSourceVS = require('../shaders/Multi-vert.js');
1313
var TransformMatrix = require('../../../gameobjects/components/TransformMatrix');
1414
var Utils = require('../Utils');
15+
var WEBGL_CONST = require('../const');
1516
var WebGLPipeline = require('../WebGLPipeline');
1617

1718
/**
@@ -75,59 +76,37 @@ var MultiPipeline = new Class({
7576
function MultiPipeline (config)
7677
{
7778
var renderer = config.game.renderer;
78-
var gl = renderer.gl;
7979

8080
var fragmentShaderSource = GetFastValue(config, 'fragShader', ShaderSourceFS);
8181

82-
// Vertex Size = attribute size added together (2 + 2 + 1 + 1 + 4) inc maxTextures
83-
8482
config.fragShader = Utils.parseFragmentShaderMaxTextures(fragmentShaderSource, renderer.maxTextures);
8583
config.vertShader = GetFastValue(config, 'vertShader', ShaderSourceVS);
8684
config.attributes = GetFastValue(config, 'attributes', [
8785
{
8886
name: 'inPosition',
8987
size: 2,
90-
type: gl.FLOAT,
91-
normalized: false,
92-
offset: 0,
93-
enabled: false,
94-
location: -1
88+
type: WEBGL_CONST.FLOAT
9589
},
9690
{
9791
name: 'inTexCoord',
9892
size: 2,
99-
type: gl.FLOAT,
100-
normalized: false,
101-
offset: 8,
102-
enabled: false,
103-
location: -1
93+
type: WEBGL_CONST.FLOAT
10494
},
10595
{
10696
name: 'inTexId',
10797
size: 1,
108-
type: gl.FLOAT,
109-
normalized: false,
110-
offset: 16,
111-
enabled: false,
112-
location: -1
98+
type: WEBGL_CONST.FLOAT
11399
},
114100
{
115101
name: 'inTintEffect',
116102
size: 1,
117-
type: gl.FLOAT,
118-
normalized: false,
119-
offset: 20,
120-
enabled: false,
121-
location: -1
103+
type: WEBGL_CONST.FLOAT
122104
},
123105
{
124106
name: 'inTint',
125107
size: 4,
126-
type: gl.UNSIGNED_BYTE,
127-
normalized: true,
128-
offset: 24,
129-
enabled: false,
130-
location: -1
108+
type: WEBGL_CONST.UNSIGNED_BYTE,
109+
normalized: true
131110
}
132111
]);
133112
config.uniforms = GetFastValue(config, 'uniforms', [
@@ -139,24 +118,6 @@ var MultiPipeline = new Class({
139118

140119
WebGLPipeline.call(this, config);
141120

142-
/**
143-
* Float32 view of the array buffer containing the pipeline's vertices.
144-
*
145-
* @name Phaser.Renderer.WebGL.Pipelines.MultiPipeline#vertexViewF32
146-
* @type {Float32Array}
147-
* @since 3.0.0
148-
*/
149-
this.vertexViewF32 = new Float32Array(this.vertexData);
150-
151-
/**
152-
* Uint32 view of the array buffer containing the pipeline's vertices.
153-
*
154-
* @name Phaser.Renderer.WebGL.Pipelines.MultiPipeline#vertexViewU32
155-
* @type {Uint32Array}
156-
* @since 3.0.0
157-
*/
158-
this.vertexViewU32 = new Uint32Array(this.vertexData);
159-
160121
/**
161122
* A temporary Transform Matrix, re-used internally during batching.
162123
*
@@ -342,7 +303,7 @@ var MultiPipeline = new Class({
342303
{
343304
var gl = this.gl;
344305
var vertexCount = this.vertexCount;
345-
var vertexSize = this.vertexSize;
306+
var vertexSize = this.currentShader.vertexSize;
346307

347308
if (vertexCount > 0)
348309
{
@@ -519,209 +480,6 @@ var MultiPipeline = new Class({
519480
this.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, unit);
520481
},
521482

522-
/**
523-
* Adds the vertices data into the batch and flushes if full.
524-
*
525-
* Assumes 6 vertices in the following arrangement:
526-
*
527-
* ```
528-
* 0----3
529-
* |\ B|
530-
* | \ |
531-
* | \ |
532-
* | A \|
533-
* | \
534-
* 1----2
535-
* ```
536-
*
537-
* Where tx0/ty0 = 0, tx1/ty1 = 1, tx2/ty2 = 2 and tx3/ty3 = 3
538-
*
539-
* @method Phaser.Renderer.WebGL.Pipelines.MultiPipeline#batchQuad
540-
* @since 3.12.0
541-
*
542-
* @param {number} x0 - The top-left x position.
543-
* @param {number} y0 - The top-left y position.
544-
* @param {number} x1 - The bottom-left x position.
545-
* @param {number} y1 - The bottom-left y position.
546-
* @param {number} x2 - The bottom-right x position.
547-
* @param {number} y2 - The bottom-right y position.
548-
* @param {number} x3 - The top-right x position.
549-
* @param {number} y3 - The top-right y position.
550-
* @param {number} u0 - UV u0 value.
551-
* @param {number} v0 - UV v0 value.
552-
* @param {number} u1 - UV u1 value.
553-
* @param {number} v1 - UV v1 value.
554-
* @param {number} tintTL - The top-left tint color value.
555-
* @param {number} tintTR - The top-right tint color value.
556-
* @param {number} tintBL - The bottom-left tint color value.
557-
* @param {number} tintBR - The bottom-right tint color value.
558-
* @param {(number|boolean)} tintEffect - The tint effect for the shader to use.
559-
* @param {WebGLTexture} [texture] - WebGLTexture that will be assigned to the current batch if a flush occurs.
560-
* @param {integer} [unit=0] - Texture unit to which the texture needs to be bound.
561-
*
562-
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
563-
*/
564-
batchQuad: function (x0, y0, x1, y1, x2, y2, x3, y3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, unit)
565-
{
566-
if (unit === undefined) { unit = this.currentUnit; }
567-
568-
var hasFlushed = false;
569-
570-
if (this.shouldFlush(6))
571-
{
572-
this.flush();
573-
574-
hasFlushed = true;
575-
576-
unit = this.setTexture2D(texture);
577-
}
578-
579-
var vertexViewF32 = this.vertexViewF32;
580-
var vertexViewU32 = this.vertexViewU32;
581-
582-
var vertexOffset = (this.vertexCount * this.vertexComponentCount) - 1;
583-
584-
vertexViewF32[++vertexOffset] = x0;
585-
vertexViewF32[++vertexOffset] = y0;
586-
vertexViewF32[++vertexOffset] = u0;
587-
vertexViewF32[++vertexOffset] = v0;
588-
vertexViewF32[++vertexOffset] = unit;
589-
vertexViewF32[++vertexOffset] = tintEffect;
590-
vertexViewU32[++vertexOffset] = tintTL;
591-
592-
vertexViewF32[++vertexOffset] = x1;
593-
vertexViewF32[++vertexOffset] = y1;
594-
vertexViewF32[++vertexOffset] = u0;
595-
vertexViewF32[++vertexOffset] = v1;
596-
vertexViewF32[++vertexOffset] = unit;
597-
vertexViewF32[++vertexOffset] = tintEffect;
598-
vertexViewU32[++vertexOffset] = tintBL;
599-
600-
vertexViewF32[++vertexOffset] = x2;
601-
vertexViewF32[++vertexOffset] = y2;
602-
vertexViewF32[++vertexOffset] = u1;
603-
vertexViewF32[++vertexOffset] = v1;
604-
vertexViewF32[++vertexOffset] = unit;
605-
vertexViewF32[++vertexOffset] = tintEffect;
606-
vertexViewU32[++vertexOffset] = tintBR;
607-
608-
vertexViewF32[++vertexOffset] = x0;
609-
vertexViewF32[++vertexOffset] = y0;
610-
vertexViewF32[++vertexOffset] = u0;
611-
vertexViewF32[++vertexOffset] = v0;
612-
vertexViewF32[++vertexOffset] = unit;
613-
vertexViewF32[++vertexOffset] = tintEffect;
614-
vertexViewU32[++vertexOffset] = tintTL;
615-
616-
vertexViewF32[++vertexOffset] = x2;
617-
vertexViewF32[++vertexOffset] = y2;
618-
vertexViewF32[++vertexOffset] = u1;
619-
vertexViewF32[++vertexOffset] = v1;
620-
vertexViewF32[++vertexOffset] = unit;
621-
vertexViewF32[++vertexOffset] = tintEffect;
622-
vertexViewU32[++vertexOffset] = tintBR;
623-
624-
vertexViewF32[++vertexOffset] = x3;
625-
vertexViewF32[++vertexOffset] = y3;
626-
vertexViewF32[++vertexOffset] = u1;
627-
vertexViewF32[++vertexOffset] = v0;
628-
vertexViewF32[++vertexOffset] = unit;
629-
vertexViewF32[++vertexOffset] = tintEffect;
630-
vertexViewU32[++vertexOffset] = tintTR;
631-
632-
this.vertexCount += 6;
633-
634-
return hasFlushed;
635-
},
636-
637-
/**
638-
* Adds the vertices data into the batch and flushes if full.
639-
*
640-
* Assumes 3 vertices in the following arrangement:
641-
*
642-
* ```
643-
* 0
644-
* |\
645-
* | \
646-
* | \
647-
* | \
648-
* | \
649-
* 1-----2
650-
* ```
651-
*
652-
* @method Phaser.Renderer.WebGL.Pipelines.MultiPipeline#batchTri
653-
* @since 3.12.0
654-
*
655-
* @param {number} x1 - The bottom-left x position.
656-
* @param {number} y1 - The bottom-left y position.
657-
* @param {number} x2 - The bottom-right x position.
658-
* @param {number} y2 - The bottom-right y position.
659-
* @param {number} x3 - The top-right x position.
660-
* @param {number} y3 - The top-right y position.
661-
* @param {number} u0 - UV u0 value.
662-
* @param {number} v0 - UV v0 value.
663-
* @param {number} u1 - UV u1 value.
664-
* @param {number} v1 - UV v1 value.
665-
* @param {number} tintTL - The top-left tint color value.
666-
* @param {number} tintTR - The top-right tint color value.
667-
* @param {number} tintBL - The bottom-left tint color value.
668-
* @param {(number|boolean)} tintEffect - The tint effect for the shader to use.
669-
* @param {WebGLTexture} [texture] - WebGLTexture that will be assigned to the current batch if a flush occurs.
670-
* @param {integer} [unit=0] - Texture unit to which the texture needs to be bound.
671-
*
672-
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
673-
*/
674-
batchTri: function (x1, y1, x2, y2, x3, y3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintEffect, texture, unit)
675-
{
676-
if (unit === undefined) { unit = this.currentUnit; }
677-
678-
var hasFlushed = false;
679-
680-
if (this.shouldFlush(3))
681-
{
682-
this.flush();
683-
684-
hasFlushed = true;
685-
686-
unit = this.setTexture2D(texture);
687-
}
688-
689-
var vertexViewF32 = this.vertexViewF32;
690-
var vertexViewU32 = this.vertexViewU32;
691-
692-
var vertexOffset = (this.vertexCount * this.vertexComponentCount) - 1;
693-
694-
tintEffect = 1;
695-
696-
vertexViewF32[++vertexOffset] = x1;
697-
vertexViewF32[++vertexOffset] = y1;
698-
vertexViewF32[++vertexOffset] = u0;
699-
vertexViewF32[++vertexOffset] = v0;
700-
vertexViewF32[++vertexOffset] = unit;
701-
vertexViewF32[++vertexOffset] = tintEffect;
702-
vertexViewU32[++vertexOffset] = tintTL;
703-
704-
vertexViewF32[++vertexOffset] = x2;
705-
vertexViewF32[++vertexOffset] = y2;
706-
vertexViewF32[++vertexOffset] = u0;
707-
vertexViewF32[++vertexOffset] = v1;
708-
vertexViewF32[++vertexOffset] = unit;
709-
vertexViewF32[++vertexOffset] = tintEffect;
710-
vertexViewU32[++vertexOffset] = tintTR;
711-
712-
vertexViewF32[++vertexOffset] = x3;
713-
vertexViewF32[++vertexOffset] = y3;
714-
vertexViewF32[++vertexOffset] = u1;
715-
vertexViewF32[++vertexOffset] = v1;
716-
vertexViewF32[++vertexOffset] = unit;
717-
vertexViewF32[++vertexOffset] = tintEffect;
718-
vertexViewU32[++vertexOffset] = tintBL;
719-
720-
this.vertexCount += 3;
721-
722-
return hasFlushed;
723-
},
724-
725483
/**
726484
* Generic function for batching a textured quad using argument values instead of a Game Object.
727485
*

0 commit comments

Comments
 (0)