Bitmap Text renderer now uses tint component values.

This commit is contained in:
photonstorm 2017-07-24 14:07:59 +01:00
parent fb713ab5ec
commit 7a9f80e4df
2 changed files with 32 additions and 23 deletions

View file

@ -15,10 +15,14 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
var cameraScrollY = camera.scrollY * gameObject.scrollFactorY;
var text = gameObject.text;
var textLength = text.length;
var chars = gameObject.fontData.data.chars;
var chars = gameObject.fontData.chars;
var lineHeight = gameObject.fontData.lineHeight;
var spriteBatch = renderer.spriteBatch;
var alpha = gameObject.alpha;
var tintTL = gameObject._tintTL;
var tintTR = gameObject._tintTR;
var tintBL = gameObject._tintBL;
var tintBR = gameObject._tintBR;
var vertexDataBuffer = spriteBatch.vertexDataBuffer;
var vertexBuffer = vertexDataBuffer.floatView;
var vertexBufferU32 = vertexDataBuffer.uintView;
@ -38,7 +42,6 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
var glyphY = 0;
var glyphW = 0;
var glyphH = 0;
var vertexColor = 0xFFFFFFFF;
var x = 0;
var y = 0;
var rotation = 0;
@ -54,14 +57,14 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
var cameraMatrix = camera.matrix.matrix;
var mva, mvb, mvc, mvd, mve, mvf, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3;
var sra, srb, src, srd, sre, srf, cma, cmb, cmc, cmd, cme, cmf;
var scale = (gameObject.fontSize / gameObject.fontData.data.size);
var scale = (gameObject.fontSize / gameObject.fontData.size);
var uta, utb, utc, utd, ute, utf;
var tempMatrixCharMatrix = tempMatrixChar.matrix;
var renderTarget = gameObject.renderTarget;
tempMatrix.applyITRS(
gameObject.x - cameraScrollX, gameObject.y - cameraScrollY,
-gameObject.rotation,
gameObject.x - cameraScrollX, gameObject.y - cameraScrollY,
-gameObject.rotation,
gameObject.scaleX, gameObject.scaleY
);
@ -128,10 +131,13 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
glyphX = textureX + glyph.x;
glyphY = textureY + glyph.y;
glyphW = glyph.width;
glyphH = glyph.height;
x = (indexCount + glyph.xOffset + xAdvance) * scale;
y = (glyph.yOffset + yAdvance) * scale;
rotation = 0;
if (lastGlyph !== null)
@ -142,13 +148,17 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
if (displayCallback)
{
var output = displayCallback({ color: 0xFFFFFF, index: index, charCode: charCode, x: x, y: y, scale: scale, rotation: 0, data: glyph.data });
var output = displayCallback({ tint: { topLeft: tintTL, topRight: tintTR, bottomLeft: tintBL, bottomRight: tintBR }, 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;
vertexColor = output.color;
tintTL = output.tint.topLeft;
tintTR = output.tint.topRight;
tintBL = output.tint.bottomLeft;
tintBR = output.tint.bottomRight;
}
x -= gameObject.scrollX | 0;
@ -202,28 +212,28 @@ var DynamicBitmapTextWebGLRenderer = function (renderer, gameObject, interpolati
vertexBuffer[vertexOffset++] = ty0;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmin;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintTL;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx1;
vertexBuffer[vertexOffset++] = ty1;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmax;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintBL;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx2;
vertexBuffer[vertexOffset++] = ty2;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmax;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintBR;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx3;
vertexBuffer[vertexOffset++] = ty3;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmin;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintTR;
vertexBuffer[vertexOffset++] = alpha;
xAdvance += glyph.xAdvance;

View file

@ -17,11 +17,15 @@ var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPerce
var lineHeight = gameObject.fontData.lineHeight;
var spriteBatch = renderer.spriteBatch;
var alpha = gameObject.alpha;
var tintTL = gameObject._tintTL;
var tintTR = gameObject._tintTR;
var tintBL = gameObject._tintBL;
var tintBR = gameObject._tintBR;
var vertexDataBuffer = spriteBatch.vertexDataBuffer;
var vertexBuffer = vertexDataBuffer.floatView;
var vertexBufferU32 = vertexDataBuffer.uintView;
var vertexOffset = 0;
var srcX = gameObject.x;
var srcX = gameObject.x;
var srcY = gameObject.y;
var textureData = gameObject.texture.source[textureFrame.sourceIndex];
var textureX = textureFrame.cutX;
@ -38,15 +42,10 @@ var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPerce
var glyphY = 0;
var glyphW = 0;
var glyphH = 0;
var vertexColor = 0xFFFFFFFF;
var x = 0;
var y = 0;
var xw = 0;
var yh = 0;
var tx = 0;
var ty = 0;
var txw = 0;
var tyh = 0;
var umin = 0;
var umax = 0;
var vmin = 0;
@ -61,8 +60,8 @@ var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPerce
var renderTarget = gameObject.renderTarget;
tempMatrix.applyITRS(
(srcX - cameraScrollX) + textureFrame.x, (srcY - cameraScrollY) + textureFrame.y,
-gameObject.rotation,
(srcX - cameraScrollX) + textureFrame.x, (srcY - cameraScrollY) + textureFrame.y,
-gameObject.rotation,
gameObject.scaleX, gameObject.scaleY
);
@ -159,28 +158,28 @@ var BitmapTextWebGLRenderer = function (renderer, gameObject, interpolationPerce
vertexBuffer[vertexOffset++] = ty0;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmin;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintTL;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx1;
vertexBuffer[vertexOffset++] = ty1;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmax;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintBL;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx2;
vertexBuffer[vertexOffset++] = ty2;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmax;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintTR;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx3;
vertexBuffer[vertexOffset++] = ty3;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmin;
vertexBufferU32[vertexOffset++] = vertexColor;
vertexBufferU32[vertexOffset++] = tintBR;
vertexBuffer[vertexOffset++] = alpha;
}
};