mirror of
https://github.com/photonstorm/phaser
synced 2024-11-23 13:13:43 +00:00
Added new temp matrix, fixed typo, removed old function
This commit is contained in:
parent
5128eecbeb
commit
340c53875c
1 changed files with 11 additions and 514 deletions
|
@ -22,7 +22,7 @@ var WebGLPipeline = require('../WebGLPipeline');
|
|||
* - renderer: Current WebGL renderer.
|
||||
* - topology: This indicates how the primitives are rendered. The default value is GL_TRIANGLES.
|
||||
* Here is the full list of rendering primitives (https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/Constants).
|
||||
* - vertShader: Source for vertex shaóder as a string.
|
||||
* - vertShader: Source for vertex shader as a string.
|
||||
* - fragShader: Source for fragment shader as a string.
|
||||
* - vertexCapacity: The amount of vertices that shall be allocated
|
||||
* - vertexSize: The size of a single vertex in bytes.
|
||||
|
@ -159,6 +159,16 @@ var TextureTintPipeline = new Class({
|
|||
*/
|
||||
this._tempMatrix3 = new TransformMatrix();
|
||||
|
||||
/**
|
||||
* A temporary Transform Matrix, re-used internally during batching.
|
||||
*
|
||||
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#_tempMatrix4
|
||||
* @private
|
||||
* @type {Phaser.GameObjects.Components.TransformMatrix}
|
||||
* @since 3.11.0
|
||||
*/
|
||||
this._tempMatrix4 = new TransformMatrix();
|
||||
|
||||
this.mvpInit();
|
||||
},
|
||||
|
||||
|
@ -609,157 +619,6 @@ var TextureTintPipeline = new Class({
|
|||
this.setTexture2D(texture, 0);
|
||||
},
|
||||
|
||||
/*
|
||||
OLDbatchSprite: function (sprite, camera, parentTransformMatrix)
|
||||
{
|
||||
var parentMatrix = null;
|
||||
|
||||
if (parentTransformMatrix)
|
||||
{
|
||||
parentMatrix = parentTransformMatrix.matrix;
|
||||
}
|
||||
|
||||
this.renderer.setPipeline(this);
|
||||
|
||||
if (this.vertexCount + 6 > this.vertexCapacity)
|
||||
{
|
||||
this.flush();
|
||||
}
|
||||
|
||||
var frame = sprite.frame;
|
||||
var texture = frame.texture.source[frame.sourceIndex].glTexture;
|
||||
var getTint = Utils.getTintAppendFloatAlpha;
|
||||
var alphaTL = camera.alpha * sprite._alphaTL;
|
||||
var alphaTR = camera.alpha * sprite._alphaTR;
|
||||
var alphaBL = camera.alpha * sprite._alphaBL;
|
||||
var alphaBR = camera.alpha * sprite._alphaBR;
|
||||
var tintTL = sprite._tintTL;
|
||||
var tintTR = sprite._tintTR;
|
||||
var tintBL = sprite._tintBL;
|
||||
var tintBR = sprite._tintBR;
|
||||
|
||||
var forceFlipY = (texture.isRenderTexture ? true : false);
|
||||
var flipX = sprite.flipX;
|
||||
var flipY = sprite.flipY ^ forceFlipY;
|
||||
|
||||
var scaleX = sprite.scaleX;
|
||||
var scaleY = sprite.scaleY;
|
||||
var rotation = sprite.rotation;
|
||||
|
||||
var roundPixels = camera.roundPixels;
|
||||
var cameraMatrix = camera.matrix.matrix;
|
||||
|
||||
var width = frame.width * (flipX ? -1.0 : 1.0);
|
||||
var height = frame.height * (flipY ? -1.0 : 1.0);
|
||||
|
||||
var x = -sprite.displayOriginX + frame.x + ((frame.width) * (flipX ? 1.0 : 0.0));
|
||||
var y = -sprite.displayOriginY + frame.y + ((frame.height) * (flipY ? 1.0 : 0.0));
|
||||
|
||||
var xw = (roundPixels ? (x | 0) : x) + width;
|
||||
var yh = (roundPixels ? (y | 0) : y) + height;
|
||||
|
||||
// ITRS
|
||||
|
||||
var sr = Math.sin(rotation);
|
||||
var cr = Math.cos(rotation);
|
||||
|
||||
var sra = cr * scaleX;
|
||||
var srb = sr * scaleX;
|
||||
var src = -sr * scaleY;
|
||||
var srd = cr * scaleY;
|
||||
var sre = sprite.x;
|
||||
var srf = sprite.y;
|
||||
|
||||
var cma = cameraMatrix[0];
|
||||
var cmb = cameraMatrix[1];
|
||||
var cmc = cameraMatrix[2];
|
||||
var cmd = cameraMatrix[3];
|
||||
var cme = cameraMatrix[4];
|
||||
var cmf = cameraMatrix[5];
|
||||
|
||||
var mva, mvb, mvc, mvd, mve, mvf;
|
||||
|
||||
if (parentMatrix)
|
||||
{
|
||||
var pma = parentMatrix[0];
|
||||
var pmb = parentMatrix[1];
|
||||
var pmc = parentMatrix[2];
|
||||
var pmd = parentMatrix[3];
|
||||
var pme = parentMatrix[4];
|
||||
var pmf = parentMatrix[5];
|
||||
var cse = -camera.scrollX * sprite.scrollFactorX;
|
||||
var csf = -camera.scrollY * sprite.scrollFactorY;
|
||||
var pse = cse * cma + csf * cmc + cme;
|
||||
var psf = cse * cmb + csf * cmd + cmf;
|
||||
var pca = pma * cma + pmb * cmc;
|
||||
var pcb = pma * cmb + pmb * cmd;
|
||||
var pcc = pmc * cma + pmd * cmc;
|
||||
var pcd = pmc * cmb + pmd * cmd;
|
||||
var pce = pme * cma + pmf * cmc + pse;
|
||||
var pcf = pme * cmb + pmf * cmd + psf;
|
||||
|
||||
mva = sra * pca + srb * pcc;
|
||||
mvb = sra * pcb + srb * pcd;
|
||||
mvc = src * pca + srd * pcc;
|
||||
mvd = src * pcb + srd * pcd;
|
||||
mve = sre * pca + srf * pcc + pce;
|
||||
mvf = sre * pcb + srf * pcd + pcf;
|
||||
}
|
||||
else
|
||||
{
|
||||
sre -= camera.scrollX * sprite.scrollFactorX;
|
||||
srf -= camera.scrollY * sprite.scrollFactorY;
|
||||
|
||||
// SRx = sprite matrix
|
||||
// CMx = camera matrix
|
||||
// MVx = matrix to store results in
|
||||
mva = sra * cma + srb * cmc;
|
||||
mvb = sra * cmb + srb * cmd;
|
||||
mvc = src * cma + srd * cmc;
|
||||
mvd = src * cmb + srd * cmd;
|
||||
mve = sre * cma + srf * cmc + cme;
|
||||
mvf = sre * cmb + srf * cmd + cmf;
|
||||
}
|
||||
|
||||
var tx0 = x * mva + y * mvc + mve;
|
||||
var ty0 = x * mvb + y * mvd + mvf;
|
||||
var tx1 = x * mva + yh * mvc + mve;
|
||||
var ty1 = x * mvb + yh * mvd + mvf;
|
||||
var tx2 = xw * mva + yh * mvc + mve;
|
||||
var ty2 = xw * mvb + yh * mvd + mvf;
|
||||
var tx3 = xw * mva + y * mvc + mve;
|
||||
var ty3 = xw * mvb + y * mvd + mvf;
|
||||
|
||||
var vTintTL = getTint(tintTL, alphaTL);
|
||||
var vTintTR = getTint(tintTR, alphaTR);
|
||||
var vTintBL = getTint(tintBL, alphaBL);
|
||||
var vTintBR = getTint(tintBR, alphaBR);
|
||||
|
||||
if (roundPixels)
|
||||
{
|
||||
tx0 |= 0;
|
||||
ty0 |= 0;
|
||||
tx1 |= 0;
|
||||
ty1 |= 0;
|
||||
tx2 |= 0;
|
||||
ty2 |= 0;
|
||||
tx3 |= 0;
|
||||
ty3 |= 0;
|
||||
}
|
||||
|
||||
this.setTexture2D(texture, 0);
|
||||
|
||||
var tintEffect = (sprite._isTinted && sprite.tintFill);
|
||||
|
||||
var u0 = frame.u0;
|
||||
var v0 = frame.v0;
|
||||
var u1 = frame.u1;
|
||||
var v1 = frame.v1;
|
||||
|
||||
this.batchVertices(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, vTintTL, vTintTR, vTintBL, vTintBR, tintEffect);
|
||||
},
|
||||
*/
|
||||
|
||||
/**
|
||||
* Batches Sprite game object
|
||||
*
|
||||
|
@ -1005,368 +864,6 @@ var TextureTintPipeline = new Class({
|
|||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Batches DynamicBitmapText game object
|
||||
*
|
||||
* @method Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#batchDynamicBitmapText
|
||||
* @since 3.0.0
|
||||
*
|
||||
* @param {Phaser.GameObjects.DynamicBitmapText} bitmapText - [description]
|
||||
* @param {Phaser.Cameras.Scene2D.Camera} camera - [description]
|
||||
* @param {Phaser.GameObjects.Components.TransformMatrix} parentTransformMatrix - [description]
|
||||
*/
|
||||
batchXDynamicBitmapText: function (bitmapText, camera, parentTransformMatrix)
|
||||
{
|
||||
var parentMatrix = null;
|
||||
|
||||
if (parentTransformMatrix)
|
||||
{
|
||||
parentMatrix = parentTransformMatrix.matrix;
|
||||
}
|
||||
|
||||
this.renderer.setPipeline(this);
|
||||
|
||||
if (this.vertexCount + 6 > this.vertexCapacity)
|
||||
{
|
||||
this.flush();
|
||||
}
|
||||
|
||||
var roundPixels = camera.roundPixels;
|
||||
var displayCallback = bitmapText.displayCallback;
|
||||
var text = bitmapText.text;
|
||||
var textLength = text.length;
|
||||
var getTint = Utils.getTintAppendFloatAlpha;
|
||||
var vertexViewF32 = this.vertexViewF32;
|
||||
var vertexViewU32 = this.vertexViewU32;
|
||||
var renderer = this.renderer;
|
||||
var cameraMatrix = camera.matrix.matrix;
|
||||
var frame = bitmapText.frame;
|
||||
var textureSource = bitmapText.texture.source[frame.sourceIndex];
|
||||
var cameraScrollX = camera.scrollX * bitmapText.scrollFactorX;
|
||||
var cameraScrollY = camera.scrollY * bitmapText.scrollFactorY;
|
||||
var scrollX = bitmapText.scrollX;
|
||||
var scrollY = bitmapText.scrollY;
|
||||
var fontData = bitmapText.fontData;
|
||||
var lineHeight = fontData.lineHeight;
|
||||
var scale = (bitmapText.fontSize / fontData.size);
|
||||
var chars = fontData.chars;
|
||||
var alpha = camera.alpha * bitmapText.alpha;
|
||||
var vTintTL = getTint(bitmapText._tintTL, alpha);
|
||||
var vTintTR = getTint(bitmapText._tintTR, alpha);
|
||||
var vTintBL = getTint(bitmapText._tintBL, alpha);
|
||||
var vTintBR = getTint(bitmapText._tintBR, alpha);
|
||||
var tintEffect = (bitmapText._isTinted && bitmapText.tintFill);
|
||||
var srcX = bitmapText.x;
|
||||
var srcY = bitmapText.y;
|
||||
var textureX = frame.cutX;
|
||||
var textureY = frame.cutY;
|
||||
var textureWidth = textureSource.width;
|
||||
var textureHeight = textureSource.height;
|
||||
var texture = textureSource.glTexture;
|
||||
var xAdvance = 0;
|
||||
var yAdvance = 0;
|
||||
var indexCount = 0;
|
||||
var charCode = 0;
|
||||
var glyph = null;
|
||||
var glyphX = 0;
|
||||
var glyphY = 0;
|
||||
var glyphW = 0;
|
||||
var glyphH = 0;
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
var xw = 0;
|
||||
var tx0;
|
||||
var ty0;
|
||||
var tx1;
|
||||
var ty1;
|
||||
var tx2;
|
||||
var ty2;
|
||||
var tx3;
|
||||
var ty3;
|
||||
var yh = 0;
|
||||
var umin = 0;
|
||||
var umax = 0;
|
||||
var vmin = 0;
|
||||
var vmax = 0;
|
||||
var lastGlyph = null;
|
||||
var lastCharCode = 0;
|
||||
var translateX = srcX + frame.x;
|
||||
var translateY = srcY + frame.y;
|
||||
var rotation = bitmapText.rotation;
|
||||
var scaleX = bitmapText.scaleX;
|
||||
var scaleY = bitmapText.scaleY;
|
||||
var letterSpacing = bitmapText.letterSpacing;
|
||||
var sr = Math.sin(rotation);
|
||||
var cr = Math.cos(rotation);
|
||||
var sra = cr * scaleX;
|
||||
var srb = sr * scaleX;
|
||||
var src = -sr * scaleY;
|
||||
var srd = cr * scaleY;
|
||||
var sre = translateX;
|
||||
var srf = translateY;
|
||||
var cma = cameraMatrix[0];
|
||||
var cmb = cameraMatrix[1];
|
||||
var cmc = cameraMatrix[2];
|
||||
var cmd = cameraMatrix[3];
|
||||
var cme = cameraMatrix[4];
|
||||
var cmf = cameraMatrix[5];
|
||||
var crop = (bitmapText.cropWidth > 0 || bitmapText.cropHeight > 0);
|
||||
var uta, utb, utc, utd, ute, utf;
|
||||
var vertexOffset = 0;
|
||||
var mva, mvb, mvc, mvd, mve, mvf;
|
||||
|
||||
if (parentMatrix)
|
||||
{
|
||||
var pma = parentMatrix[0];
|
||||
var pmb = parentMatrix[1];
|
||||
var pmc = parentMatrix[2];
|
||||
var pmd = parentMatrix[3];
|
||||
var pme = parentMatrix[4];
|
||||
var pmf = parentMatrix[5];
|
||||
var cse = -cameraScrollX;
|
||||
var csf = -cameraScrollY;
|
||||
var pse = cse * cma + csf * cmc + cme;
|
||||
var psf = cse * cmb + csf * cmd + cmf;
|
||||
var pca = pma * cma + pmb * cmc;
|
||||
var pcb = pma * cmb + pmb * cmd;
|
||||
var pcc = pmc * cma + pmd * cmc;
|
||||
var pcd = pmc * cmb + pmd * cmd;
|
||||
var pce = pme * cma + pmf * cmc + pse;
|
||||
var pcf = pme * cmb + pmf * cmd + psf;
|
||||
|
||||
mva = sra * pca + srb * pcc;
|
||||
mvb = sra * pcb + srb * pcd;
|
||||
mvc = src * pca + srd * pcc;
|
||||
mvd = src * pcb + srd * pcd;
|
||||
mve = sre * pca + srf * pcc + pce;
|
||||
mvf = sre * pcb + srf * pcd + pcf;
|
||||
}
|
||||
else
|
||||
{
|
||||
sre -= cameraScrollX;
|
||||
srf -= cameraScrollY;
|
||||
|
||||
mva = sra * cma + srb * cmc;
|
||||
mvb = sra * cmb + srb * cmd;
|
||||
mvc = src * cma + srd * cmc;
|
||||
mvd = src * cmb + srd * cmd;
|
||||
mve = sre * cma + srf * cmc + cme;
|
||||
mvf = sre * cmb + srf * cmd + cmf;
|
||||
}
|
||||
|
||||
this.setTexture2D(texture, 0);
|
||||
|
||||
if (crop)
|
||||
{
|
||||
renderer.pushScissor(
|
||||
bitmapText.x,
|
||||
bitmapText.y,
|
||||
bitmapText.cropWidth * bitmapText.scaleX,
|
||||
bitmapText.cropHeight * bitmapText.scaleY
|
||||
);
|
||||
}
|
||||
|
||||
for (var index = 0; index < textLength; ++index)
|
||||
{
|
||||
scale = (bitmapText.fontSize / bitmapText.fontData.size);
|
||||
rotation = 0;
|
||||
|
||||
charCode = text.charCodeAt(index);
|
||||
|
||||
if (charCode === 10)
|
||||
{
|
||||
xAdvance = 0;
|
||||
indexCount = 0;
|
||||
yAdvance += lineHeight;
|
||||
lastGlyph = null;
|
||||
continue;
|
||||
}
|
||||
|
||||
glyph = chars[charCode];
|
||||
|
||||
if (!glyph)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
glyphX = textureX + glyph.x;
|
||||
glyphY = textureY + glyph.y;
|
||||
|
||||
glyphW = glyph.width;
|
||||
glyphH = glyph.height;
|
||||
|
||||
x = (indexCount + glyph.xOffset + xAdvance) - scrollX;
|
||||
y = (glyph.yOffset + yAdvance) - scrollY;
|
||||
|
||||
if (lastGlyph !== null)
|
||||
{
|
||||
var kerningOffset = glyph.kerning[lastCharCode];
|
||||
x += (kerningOffset !== undefined) ? kerningOffset : 0;
|
||||
}
|
||||
|
||||
xAdvance += glyph.xAdvance + letterSpacing;
|
||||
indexCount += 1;
|
||||
lastGlyph = glyph;
|
||||
lastCharCode = charCode;
|
||||
|
||||
// Nothing to render or a space? Then skip to the next glyph
|
||||
if (glyphW === 0 || glyphH === 0 || charCode === 32)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (displayCallback)
|
||||
{
|
||||
var output = displayCallback({
|
||||
color: 0,
|
||||
tint: {
|
||||
topLeft: vTintTL,
|
||||
topRight: vTintTR,
|
||||
bottomLeft: vTintBL,
|
||||
bottomRight: vTintBR
|
||||
},
|
||||
index: index,
|
||||
charCode: charCode,
|
||||
x: x,
|
||||
y: y,
|
||||
scale: scale,
|
||||
rotation: 0,
|
||||
data: glyph.data
|
||||
});
|
||||
|
||||
x = output.x;
|
||||
y = output.y;
|
||||
scale = output.scale;
|
||||
rotation = output.rotation;
|
||||
|
||||
if (output.color)
|
||||
{
|
||||
vTintTL = output.color;
|
||||
vTintTR = output.color;
|
||||
vTintBL = output.color;
|
||||
vTintBR = output.color;
|
||||
}
|
||||
else
|
||||
{
|
||||
vTintTL = output.tint.topLeft;
|
||||
vTintTR = output.tint.topRight;
|
||||
vTintBL = output.tint.bottomLeft;
|
||||
vTintBR = output.tint.bottomRight;
|
||||
}
|
||||
|
||||
vTintTL = getTint(vTintTL, alpha);
|
||||
vTintTR = getTint(vTintTR, alpha);
|
||||
vTintBL = getTint(vTintBL, alpha);
|
||||
vTintBR = getTint(vTintBR, alpha);
|
||||
}
|
||||
|
||||
x -= bitmapText.displayOriginX;
|
||||
y -= bitmapText.displayOriginY;
|
||||
x *= scale;
|
||||
y *= scale;
|
||||
|
||||
sr = Math.sin(rotation);
|
||||
cr = Math.cos(rotation);
|
||||
uta = cr * scale;
|
||||
utb = sr * scale;
|
||||
utc = -sr * scale;
|
||||
utd = cr * scale;
|
||||
ute = x;
|
||||
utf = y;
|
||||
|
||||
sra = uta * mva + utb * mvc;
|
||||
srb = uta * mvb + utb * mvd;
|
||||
src = utc * mva + utd * mvc;
|
||||
srd = utc * mvb + utd * mvd;
|
||||
sre = ute * mva + utf * mvc + mve;
|
||||
srf = ute * mvb + utf * mvd + mvf;
|
||||
|
||||
xw = glyphW;
|
||||
yh = glyphH;
|
||||
tx0 = sre;
|
||||
ty0 = srf;
|
||||
tx1 = yh * src + sre;
|
||||
ty1 = yh * srd + srf;
|
||||
tx2 = xw * sra + yh * src + sre;
|
||||
ty2 = xw * srb + yh * srd + srf;
|
||||
tx3 = xw * sra + sre;
|
||||
ty3 = xw * srb + srf;
|
||||
|
||||
umin = glyphX / textureWidth;
|
||||
umax = (glyphX + glyphW) / textureWidth;
|
||||
vmin = glyphY / textureHeight;
|
||||
vmax = (glyphY + glyphH) / textureHeight;
|
||||
|
||||
if (this.vertexCount + 6 > this.vertexCapacity)
|
||||
{
|
||||
this.flush();
|
||||
}
|
||||
|
||||
if (roundPixels)
|
||||
{
|
||||
tx0 |= 0;
|
||||
ty0 |= 0;
|
||||
tx1 |= 0;
|
||||
ty1 |= 0;
|
||||
tx2 |= 0;
|
||||
ty2 |= 0;
|
||||
tx3 |= 0;
|
||||
ty3 |= 0;
|
||||
}
|
||||
|
||||
vertexOffset = (this.vertexCount * this.vertexComponentCount) - 1;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx0;
|
||||
vertexViewF32[++vertexOffset] = ty0;
|
||||
vertexViewF32[++vertexOffset] = umin;
|
||||
vertexViewF32[++vertexOffset] = vmin;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintTL;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx1;
|
||||
vertexViewF32[++vertexOffset] = ty1;
|
||||
vertexViewF32[++vertexOffset] = umin;
|
||||
vertexViewF32[++vertexOffset] = vmax;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintBL;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx2;
|
||||
vertexViewF32[++vertexOffset] = ty2;
|
||||
vertexViewF32[++vertexOffset] = umax;
|
||||
vertexViewF32[++vertexOffset] = vmax;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintBR;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx0;
|
||||
vertexViewF32[++vertexOffset] = ty0;
|
||||
vertexViewF32[++vertexOffset] = umin;
|
||||
vertexViewF32[++vertexOffset] = vmin;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintTL;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx2;
|
||||
vertexViewF32[++vertexOffset] = ty2;
|
||||
vertexViewF32[++vertexOffset] = umax;
|
||||
vertexViewF32[++vertexOffset] = vmax;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintBR;
|
||||
|
||||
vertexViewF32[++vertexOffset] = tx3;
|
||||
vertexViewF32[++vertexOffset] = ty3;
|
||||
vertexViewF32[++vertexOffset] = umax;
|
||||
vertexViewF32[++vertexOffset] = vmin;
|
||||
vertexViewF32[++vertexOffset] = tintEffect;
|
||||
vertexViewU32[++vertexOffset] = vTintTR;
|
||||
|
||||
this.vertexCount += 6;
|
||||
}
|
||||
|
||||
if (crop)
|
||||
{
|
||||
renderer.popScissor();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Generic function for batching a textured quad
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue