Skip to content

Commit c4a79bf

Browse files
committed
Pixel Batch rendering working, and passing through properly.
1 parent bd80999 commit c4a79bf

5 files changed

Lines changed: 63 additions & 29 deletions

File tree

src/Phaser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var Phaser = Phaser || { // jshint ignore:line
1616
* @constant
1717
* @type {string}
1818
*/
19-
VERSION: '3.0.0.r5',
19+
VERSION: '3.0.0.r6',
2020

2121
/**
2222
* An array of Phaser game instances.
@@ -552,5 +552,9 @@ var Phaser = Phaser || { // jshint ignore:line
552552

553553
};
554554

555+
// "Anybody who doesn’t change their mind a lot is
556+
// dramatically underestimating the complexity of
557+
// the world we live in.” - Jeff Bezos
558+
555559
// Remove when ready
556560
var PIXI = PIXI || {};

src/gameobjects/pixelfield/PixelField.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Phaser.GameObject.PixelField = function (game, x, y, pixelSize)
3434

3535
this.list = [];
3636

37+
this.getColor32 = function (r, g, b, a)
38+
{
39+
a *= 255;
40+
41+
return ((a << 24) | (b << 16) | (g << 8) | r) >>> 0;
42+
};
43+
3744
};
3845

3946
Phaser.GameObject.PixelField.prototype = Object.create(Phaser.GameObject.prototype);
@@ -53,6 +60,23 @@ Phaser.GameObject.PixelField.prototype.preUpdate = function ()
5360
}
5461
};
5562

63+
// Ideas:
64+
//
65+
// Pixel velocity?
66+
// Pixel fade (alpha out) duration?
67+
// Kill pixel
68+
// Remove pixel
69+
70+
Phaser.GameObject.PixelField.prototype.add = function (x, y, r, g, b, a)
71+
{
72+
this.list.push({
73+
x: x,
74+
y: y,
75+
a: a,
76+
color: this.getColor32(r, g, b, a)
77+
});
78+
};
79+
5680
// Phaser.GameObject.Image.prototype.update = function ()
5781
// {
5882
// };

src/gameobjects/pixelfield/PixelFieldWebGLRenderer.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ Phaser.Renderer.WebGL.GameObjects.PixelField = {
77
render: function (renderer, src)
88
{
99
var verts = src.transform.glVertextData;
10-
var color = src.color._glBg;
1110

12-
renderer.batch.addPixel(verts, color);
11+
for (var i = 0; i < src.list.length; i++)
12+
{
13+
var pixel = src.list[i];
14+
15+
renderer.batch.addPixel(
16+
verts.x0 + pixel.x,
17+
verts.y0 + pixel.y,
18+
verts.x1 + pixel.x,
19+
verts.y1 + pixel.y,
20+
verts.x2 + pixel.x,
21+
verts.y2 + pixel.y,
22+
verts.x3 + pixel.x,
23+
verts.y3 + pixel.y,
24+
pixel.color
25+
);
26+
}
1327
}
1428

1529
};

src/renderer/webgl/BatchManager.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
5555
this.currentBatch.stop();
5656
},
5757

58-
addPixel: function (verts, color)
58+
addPixel: function (x0, y0, x1, y1, x2, y2, x3, y3, color)
5959
{
6060
// Check Batch Size and flush if needed
6161
if (this.currentBatch.size >= this.currentBatch.maxSize)
6262
{
6363
this.currentBatch.flush();
6464
}
6565

66-
this.pixelBatch.add(verts, color);
66+
this.pixelBatch.add(x0, y0, x1, y1, x2, y2, x3, y3, color);
6767
},
6868

6969
add: function (source, blendMode, verts, uvs, textureIndex, alpha, tintColors, bgColors)
@@ -107,7 +107,7 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
107107

108108
// Shader?
109109

110-
// this.imageBatch.add(verts, uvs, textureIndex, alpha, tintColors, bgColors);
110+
this.imageBatch.add(verts, uvs, textureIndex, alpha, tintColors, bgColors);
111111
// this.fxBatch.add(verts, uvs, textureIndex, alpha, tintColors, bgColors);
112112
// this.multiTextureBatch.add(verts, uvs, textureIndex, alpha, tintColors, bgColors);
113113

src/renderer/webgl/batches/PixelBatch.js

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ Phaser.Renderer.WebGL.Batch.Pixel.prototype.init = function ()
7878
'varying vec4 vColor;', // the color value passed in from the vertex shader
7979

8080
'void main(void) {',
81-
// ' gl_FragColor = vColor;',
82-
' gl_FragColor = PINK;',
81+
' gl_FragColor = vColor;',
82+
// ' gl_FragColor = PINK;',
8383
'}'
8484
];
8585

@@ -197,40 +197,32 @@ Phaser.Renderer.WebGL.Batch.Pixel.prototype.bindShader = function ()
197197
gl.vertexAttribPointer(this.aColor, 4, gl.UNSIGNED_BYTE, true, vertSize, 8);
198198
};
199199

200-
Phaser.Renderer.WebGL.Batch.Pixel.prototype.add = function (verts, color)
200+
Phaser.Renderer.WebGL.Batch.Pixel.prototype.add = function (x0, y0, x1, y1, x2, y2, x3, y3, color)
201201
{
202202
// These are TypedArray Views into the vertices ArrayBuffer
203203
var colors = this.colors;
204204
var positions = this.positions;
205205

206206
var i = this._i;
207207

208-
// Top Left vert (xy, uv, color)
209-
positions[i++] = verts.x0;
210-
positions[i++] = verts.y0;
211-
// positions[i++] = uvs.x0;
212-
// positions[i++] = uvs.y0;
208+
// Top Left vert (xy, color)
209+
positions[i++] = x0;
210+
positions[i++] = y0;
213211
colors[i++] = color;
214212

215-
// Top Right vert (xy, uv, color)
216-
positions[i++] = verts.x1;
217-
positions[i++] = verts.y1;
218-
// positions[i++] = uvs.x1;
219-
// positions[i++] = uvs.y1;
213+
// Top Right vert (xy, color)
214+
positions[i++] = x1;
215+
positions[i++] = y1;
220216
colors[i++] = color;
221217

222-
// Bottom Right vert (xy, uv, color)
223-
positions[i++] = verts.x2;
224-
positions[i++] = verts.y2;
225-
// positions[i++] = uvs.x2;
226-
// positions[i++] = uvs.y2;
218+
// Bottom Right vert (xy, color)
219+
positions[i++] = x2;
220+
positions[i++] = y2;
227221
colors[i++] = color;
228222

229-
// Bottom Left vert (xy, uv, color)
230-
positions[i++] = verts.x3;
231-
positions[i++] = verts.y3;
232-
// positions[i++] = uvs.x3;
233-
// positions[i++] = uvs.y3;
223+
// Bottom Left vert (xy, color)
224+
positions[i++] = x3;
225+
positions[i++] = y3;
234226
colors[i++] = color;
235227

236228
this._i = i;

0 commit comments

Comments
 (0)