@@ -15,6 +15,121 @@ var BitmapTextWebGLRenderer = function (renderer, src, interpolationPercentage,
1515 var f = cameraMatrix [ 5 ] ;
1616 var cameraScrollX = camera . scrollX ;
1717 var cameraScrollY = camera . scrollY ;
18+ var text = src . text ;
19+ var textLength = text . length ;
20+ var chars = src . fontData . chars ;
21+ var lineHeight = src . fontData . lineHeight ;
22+ var blitterBatch = renderer . blitterBatch ;
23+ var alpha = src . alpha ;
24+ var vertexDataBuffer = blitterBatch . vertexDataBuffer ;
25+ var vertexBuffer = vertexDataBuffer . floatView ;
26+ var vertexOffset = 0 ;
27+ var srcX = src . x ;
28+ var srcY = src . y ;
29+ var texture = src . texture . source [ 0 ] . glTexture
30+ var textureWidth = src . texture . source [ 0 ] . width ;
31+ var textureHeight = src . texture . source [ 0 ] . height
32+ var xAdvance = 0 ;
33+ var yAdvance = 0 ;
34+ var indexCount = 0 ;
35+ var charCode = 0 ;
36+ var glyph = null ;
37+ var glyphX = 0 ;
38+ var glyphY = 0 ;
39+ var glyphW = 0 ;
40+ var glyphH = 0 ;
41+ var x = 0 ;
42+ var y = 0 ;
43+ var xw = 0 ;
44+ var yh = 0 ;
45+ var tx = 0 ;
46+ var ty = 0 ;
47+ var txw = 0 ;
48+ var tyh = 0 ;
49+ var umin = 0 ;
50+ var umax = 0 ;
51+ var vmin = 0 ;
52+ var vmax = 0 ;
53+ var lastGlyph = null ;
54+ var lastCharCode = 0 ;
55+
56+ for ( var index = 0 ; index < textLength ; ++ index )
57+ {
58+ charCode = text . charCodeAt ( index ) ;
59+ if ( charCode === 10 )
60+ {
61+ xAdvance = 0 ;
62+ indexCount = 0 ;
63+ yAdvance += lineHeight ;
64+ lastGlyph = null ;
65+ continue ;
66+ }
67+
68+ glyph = chars [ charCode ] ;
69+ if ( ! glyph )
70+ {
71+ continue ;
72+ }
73+
74+ glyphX = glyph . x ;
75+ glyphY = glyph . y ;
76+ glyphW = glyph . width ;
77+ glyphH = glyph . height ;
78+ x = ( srcX + indexCount + glyph . xOffset + xAdvance ) - cameraScrollX ;
79+ y = ( srcY + glyph . yOffset + yAdvance ) - cameraScrollY ;
80+
81+ if ( lastGlyph !== null )
82+ {
83+ var kerningOffset = glyph . kerning [ lastCharCode ] ;
84+ x += ( kerningOffset !== undefined ) ? kerningOffset : 0 ;
85+ }
86+
87+ xw = x + glyphW ;
88+ yh = y + glyphH ;
89+ tx = x * a + y * c + e ;
90+ ty = x * b + y * d + f ;
91+ txw = xw * a + yh * c + e ;
92+ tyh = xw * b + yh * d + f ;
93+ umin = glyphX / textureWidth ;
94+ umax = ( glyphX + glyphW ) / textureWidth ;
95+ vmin = glyphY / textureHeight ;
96+ vmax = ( glyphY + glyphH ) / textureHeight ;
97+
98+ if ( blitterBatch . elementCount >= blitterBatch . maxParticles )
99+ {
100+ blitterBatch . flush ( ) ;
101+ }
102+
103+ renderer . setBatch ( blitterBatch , texture ) ;
104+ vertexOffset = vertexDataBuffer . allocate ( 20 ) ;
105+ blitterBatch . elementCount += 6 ;
106+
107+ vertexBuffer [ vertexOffset ++ ] = tx ;
108+ vertexBuffer [ vertexOffset ++ ] = ty ;
109+ vertexBuffer [ vertexOffset ++ ] = umin ;
110+ vertexBuffer [ vertexOffset ++ ] = vmin ;
111+ vertexBuffer [ vertexOffset ++ ] = alpha ;
112+ vertexBuffer [ vertexOffset ++ ] = tx ;
113+ vertexBuffer [ vertexOffset ++ ] = tyh ;
114+ vertexBuffer [ vertexOffset ++ ] = umin ;
115+ vertexBuffer [ vertexOffset ++ ] = vmax ;
116+ vertexBuffer [ vertexOffset ++ ] = alpha ;
117+ vertexBuffer [ vertexOffset ++ ] = txw ;
118+ vertexBuffer [ vertexOffset ++ ] = tyh ;
119+ vertexBuffer [ vertexOffset ++ ] = umax ;
120+ vertexBuffer [ vertexOffset ++ ] = vmax ;
121+ vertexBuffer [ vertexOffset ++ ] = alpha ;
122+ vertexBuffer [ vertexOffset ++ ] = txw ;
123+ vertexBuffer [ vertexOffset ++ ] = ty ;
124+ vertexBuffer [ vertexOffset ++ ] = umax ;
125+ vertexBuffer [ vertexOffset ++ ] = vmin ;
126+ vertexBuffer [ vertexOffset ++ ] = alpha ;
127+
128+ xAdvance += glyph . xAdvance ;
129+ indexCount += 1 ;
130+ lastGlyph = glyph ;
131+ lastCharCode = charCode ;
132+ }
18133} ;
19134
20135module . exports = BitmapTextWebGLRenderer ;
0 commit comments