New addVerts method working.

This commit is contained in:
Richard Davey 2016-10-23 11:25:44 +01:00
parent 7cfe3b3919
commit 3cb806c86e
2 changed files with 35 additions and 3 deletions

View file

@ -15,7 +15,27 @@ Phaser.Renderer.WebGL.GameObjects.Image = {
return;
}
var uvs = frame.uvs;
var verts = src.transform.glVertextData;
var index = src.glTextureIndex;
var alpha = src.color.worldAlpha * 255 << 24;
var tint = src.color._glTint;
var bg = src.color._glBg;
renderer.spriteBatch.render(src);
// Several options open to us... we can either just call 'render' and it works out
// everything for us.
//
// Or we can call addVerts 4 times
//
// Or we can call addVerts and pass in objects, but call it as many times as we like
// so we can do special FX from it
renderer.spriteBatch.addVert(verts.x0, verts.y0, uvs.x0, uvs.y0, index, tint.topLeft + alpha, bg);
renderer.spriteBatch.addVert(verts.x1, verts.y1, uvs.x1, uvs.y1, index, tint.topRight + alpha, bg);
renderer.spriteBatch.addVert(verts.x2, verts.y2, uvs.x2, uvs.y2, index, tint.bottomRight + alpha, bg);
renderer.spriteBatch.addVert(verts.x3, verts.y3, uvs.x3, uvs.y3, index, tint.bottomLeft + alpha, bg);
}
};

View file

@ -142,6 +142,8 @@ Phaser.Renderer.WebGL.BatchManager = function (renderer)
// @type {WebGLUniformLocation }
this.offsetVector;
this._i = 0;
};
Phaser.Renderer.WebGL.BatchManager.prototype.constructor = Phaser.Renderer.WebGL.BatchManager;
@ -323,6 +325,7 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
start: function ()
{
this.dirty = true;
this._i = 0;
},
end: function ()
@ -356,9 +359,9 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
// this.renderer.textureArray[textureSource.glTextureIndex] = textureSource;
},
render: function (sprite)
render: function (gameObject)
{
var source = sprite.frame.source;
var source = gameObject.frame.source;
if (this.currentTextureSource !== source)
{
@ -372,6 +375,11 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
this.currentTextureSource = source;
}
this.sprites[this.currentBatchSize++] = gameObject;
},
/*
// These are just views into the same typed array
var colors = this.colors;
var positions = this.positions;
@ -426,12 +434,14 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
this.sprites[this.currentBatchSize++] = gameObject;
},
*/
// Call this 4 times, once for each vert
// Then call addGameObject to complete it
addVert: function (x, y, uvx, uvy, textureIndex, tint, bg)
{
var i = this.currentBatchSize * (this.vertSize / 4);
var i = this._i;
this.positions[i++] = x;
this.positions[i++] = y;
@ -441,6 +451,8 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
this.colors[i++] = tint;
this.colors[i++] = bg;
this._i = i;
},
addVerts: function (gameObject, uvs, verts, textureIndex, tintColors, bgColors)