forked from phaserjs/phaser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBitmapTextWebGLRenderer.js
More file actions
138 lines (127 loc) · 4.05 KB
/
Copy pathBitmapTextWebGLRenderer.js
File metadata and controls
138 lines (127 loc) · 4.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage, camera)
{
if (this.renderMask !== this.renderFlags)
{
return;
}
var textureFrame = src.frame;
var cameraMatrix = camera.matrix.matrix;
var a = cameraMatrix[0];
var b = cameraMatrix[1];
var c = cameraMatrix[2];
var d = cameraMatrix[3];
var e = cameraMatrix[4];
var f = cameraMatrix[5];
var cameraScrollX = camera.scrollX;
var cameraScrollY = camera.scrollY;
var text = src.text;
var textLength = text.length;
var chars = src.fontData.chars;
var lineHeight = src.fontData.lineHeight;
var blitterBatch = renderer.blitterBatch;
var alpha = src.alpha;
var vertexDataBuffer = blitterBatch.vertexDataBuffer;
var vertexBuffer = vertexDataBuffer.floatView;
var vertexOffset = 0;
var srcX = src.x;
var srcY = src.y;
var textureData = src.texture.source[textureFrame.sourceIndex];
var textureX = textureFrame.cutX;
var textureY = textureFrame.cutY;
var textureWidth = textureData.width;
var textureHeight = textureData.height;
var texture = textureData.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 yh = 0;
var tx = 0;
var ty = 0;
var txw = 0;
var tyh = 0;
var umin = 0;
var umax = 0;
var vmin = 0;
var vmax = 0;
var lastGlyph = null;
var lastCharCode = 0;
for (var index = 0; index < textLength; ++index)
{
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 = (srcX + indexCount + glyph.xOffset + xAdvance) - cameraScrollX;
y = (srcY + glyph.yOffset + yAdvance) - cameraScrollY;
if (lastGlyph !== null)
{
var kerningOffset = glyph.kerning[lastCharCode];
x += (kerningOffset !== undefined) ? kerningOffset : 0;
}
xw = x + glyphW;
yh = y + glyphH;
tx = x * a + y * c + e;
ty = x * b + y * d + f;
txw = xw * a + yh * c + e;
tyh = xw * b + yh * d + f;
umin = glyphX / textureWidth;
umax = (glyphX + glyphW) / textureWidth;
vmin = glyphY / textureHeight;
vmax = (glyphY + glyphH) / textureHeight;
if (blitterBatch.elementCount >= blitterBatch.maxParticles)
{
blitterBatch.flush();
}
renderer.setBatch(blitterBatch, texture);
vertexOffset = vertexDataBuffer.allocate(20);
blitterBatch.elementCount += 6;
vertexBuffer[vertexOffset++] = tx;
vertexBuffer[vertexOffset++] = ty;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmin;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = tx;
vertexBuffer[vertexOffset++] = tyh;
vertexBuffer[vertexOffset++] = umin;
vertexBuffer[vertexOffset++] = vmax;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = txw;
vertexBuffer[vertexOffset++] = tyh;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmax;
vertexBuffer[vertexOffset++] = alpha;
vertexBuffer[vertexOffset++] = txw;
vertexBuffer[vertexOffset++] = ty;
vertexBuffer[vertexOffset++] = umax;
vertexBuffer[vertexOffset++] = vmin;
vertexBuffer[vertexOffset++] = alpha;
xAdvance += glyph.xAdvance;
indexCount += 1;
lastGlyph = glyph;
lastCharCode = charCode;
}
};
module.exports = BitmapTextWebGLRenderer;