@openglobus/og 0.12.4 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +0 -2
  2. package/dist/@openglobus/og.esm.js +2 -2
  3. package/dist/@openglobus/og.esm.js.map +1 -1
  4. package/dist/@openglobus/og.umd.js +2 -2
  5. package/dist/@openglobus/og.umd.js.map +1 -1
  6. package/package.json +7 -7
  7. package/src/og/Extent.js +3 -3
  8. package/src/og/Globe.js +277 -275
  9. package/src/og/ImageCanvas.js +3 -3
  10. package/src/og/LonLat.js +9 -9
  11. package/src/og/QueueArray.js +2 -2
  12. package/src/og/Rectangle.js +5 -5
  13. package/src/og/bv/Box.js +1 -1
  14. package/src/og/bv/Sphere.js +2 -2
  15. package/src/og/camera/Camera.js +1 -1
  16. package/src/og/camera/PlanetCamera.js +649 -646
  17. package/src/og/control/LayerSwitcher.js +1 -1
  18. package/src/og/control/MouseNavigation.js +22 -13
  19. package/src/og/control/MouseWheelZoomControl.js +2 -2
  20. package/src/og/control/ScaleControl.js +1 -1
  21. package/src/og/control/TouchNavigation.js +319 -319
  22. package/src/og/control/ZoomControl.js +132 -132
  23. package/src/og/control/visibleExtent/Segment.js +12 -12
  24. package/src/og/ellipsoid/Ellipsoid.js +577 -567
  25. package/src/og/entity/BillboardHandler.js +878 -1051
  26. package/src/og/entity/Entity.js +1 -1
  27. package/src/og/entity/EntityCollection.js +847 -857
  28. package/src/og/entity/GeoObjectHandler.js +2 -2
  29. package/src/og/entity/LabelHandler.js +887 -1040
  30. package/src/og/entity/LabelWorker.js +0 -6
  31. package/src/og/entity/PointCloud.js +495 -495
  32. package/src/og/entity/Polyline.js +2218 -2222
  33. package/src/og/entity/RayHandler.js +1 -1
  34. package/src/og/layer/CanvasTiles.js +6 -3
  35. package/src/og/layer/GeoImage.js +1 -1
  36. package/src/og/layer/KML.js +5 -5
  37. package/src/og/layer/Layer.js +800 -752
  38. package/src/og/layer/Vector.js +997 -1010
  39. package/src/og/layer/XYZ.js +359 -357
  40. package/src/og/math/Line2.js +4 -4
  41. package/src/og/math/Quat.js +2 -2
  42. package/src/og/math/Ray.js +2 -2
  43. package/src/og/math/Vec2.js +524 -524
  44. package/src/og/math/Vec3.js +900 -900
  45. package/src/og/math/Vec4.js +261 -261
  46. package/src/og/math.js +397 -398
  47. package/src/og/quadTree/EntityCollectionNode.js +389 -387
  48. package/src/og/renderer/Renderer.js +14 -20
  49. package/src/og/renderer/RendererEvents.js +1034 -1045
  50. package/src/og/scene/Planet.js +12 -9
  51. package/src/og/scene/RenderNode.js +347 -354
  52. package/src/og/segment/Segment.js +3 -1
  53. package/src/og/segment/SegmentLonLat.js +1 -4
  54. package/src/og/shaders/billboard.js +220 -204
  55. package/src/og/shaders/drawnode.js +607 -603
  56. package/src/og/shaders/label.js +576 -456
  57. package/src/og/shaders/polyline.js +365 -361
  58. package/src/og/terrain/MapboxTerrain.js +1 -1
  59. package/src/og/utils/FontAtlas.js +209 -200
  60. package/src/og/utils/GeoImageCreator.js +4 -5
  61. package/src/og/utils/TextureAtlas.js +4 -4
  62. package/src/og/utils/VectorTileCreator.js +414 -414
  63. package/src/og/utils/shared.js +1 -1
  64. package/src/og/webgl/Handler.js +28 -60
  65. package/src/og/webgl/Multisample.js +260 -260
  66. package/src/og/webgl/Program.js +411 -396
  67. package/types/bv/Box.d.ts +1 -1
  68. package/types/bv/Sphere.d.ts +1 -1
  69. package/types/camera/PlanetCamera.d.ts +3 -3
  70. package/types/control/LayerSwitcher.d.ts +1 -1
  71. package/types/ellipsoid/Ellipsoid.d.ts +9 -2
  72. package/types/entity/BillboardHandler.d.ts +0 -4
  73. package/types/entity/EntityCollection.d.ts +0 -8
  74. package/types/entity/LabelHandler.d.ts +0 -2
  75. package/types/entity/Polyline.d.ts +1 -1
  76. package/types/layer/KML.d.ts +11 -11
  77. package/types/layer/Layer.d.ts +4 -0
  78. package/types/layer/Vector.d.ts +1 -8
  79. package/types/math/Line2.d.ts +4 -4
  80. package/types/math/Ray.d.ts +2 -2
  81. package/types/math/Vec2.d.ts +1 -1
  82. package/types/math/Vec3.d.ts +1 -1
  83. package/types/math/Vec4.d.ts +2 -2
  84. package/types/math.d.ts +1 -1
  85. package/types/renderer/Renderer.d.ts +1 -1
  86. package/types/renderer/RendererEvents.d.ts +1 -1
  87. package/types/shaders/label.d.ts +1 -1
  88. package/types/utils/FontAtlas.d.ts +3 -2
  89. package/types/utils/TextureAtlas.d.ts +3 -3
  90. package/types/utils/VectorTileCreator.d.ts +4 -4
  91. package/types/utils/shared.d.ts +1 -1
  92. package/types/webgl/Handler.d.ts +6 -31
  93. package/types/webgl/Program.d.ts +2 -0
@@ -1,1042 +1,889 @@
1
- /**
2
- * @module og/entity/LabelHandler
3
- */
4
-
5
- "use strict";
6
-
7
- import * as shaders from "../shaders/label.js";
8
- import { ALIGN } from "./Label.js";
9
- import { BillboardHandler } from "./BillboardHandler.js";
10
- import { concatTypedArrays, spliceTypedArray } from "../utils/shared.js";
11
- import { LOCK_FREE } from "./LabelWorker.js";
12
-
13
- const PICKINGCOLOR_BUFFER = 0;
14
- const POSITION_BUFFER = 1;
15
- const SIZE_BUFFER = 2;
16
- const OFFSET_BUFFER = 3;
17
- const RGBA_BUFFER = 4;
18
- const ROTATION_BUFFER = 5;
19
- const TEXCOORD_BUFFER = 6;
20
- const VERTEX_BUFFER = 7;
21
- const ALIGNEDAXIS_BUFFER = 8;
22
- const FONTINDEX_BUFFER = 9;
23
- const OUTLINE_BUFFER = 10;
24
- const OUTLINECOLOR_BUFFER = 11;
25
-
26
- window.uZ = -2.0;
27
- window.dZ = 1.1;
28
- /*
29
- * og.LabelHandler
30
- *
31
- *
32
- */
33
- class LabelHandler extends BillboardHandler {
34
- /**
35
- *
36
- * @param {*} entityCollection
37
- * @param {*} maxLetters
38
- */
39
- constructor(entityCollection, maxLetters = 21) {
40
- super(entityCollection);
41
-
42
- this._gliphParamBuffer = null;
43
- this._fontIndexBuffer = null;
44
- this._noOutlineBuffer = null;
45
- this._outlineBuffer = null;
46
- this._outlineColorBuffer = null;
47
-
48
- this._gliphParamArr = new Float32Array();
49
- this._fontIndexArr = new Float32Array();
50
- this._noOutlineArr = new Float32Array();
51
- this._outlineArr = new Float32Array();
52
- this._outlineColorArr = new Float32Array();
53
-
54
- this._buffersUpdateCallbacks[FONTINDEX_BUFFER] = this.createFontIndexBuffer;
55
- this._buffersUpdateCallbacks[OUTLINE_BUFFER] = this.createOutlineBuffer;
56
- this._buffersUpdateCallbacks[OUTLINECOLOR_BUFFER] = this.createOutlineColorBuffer;
57
-
58
- this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
59
-
60
- this._maxLetters = maxLetters;
61
- }
62
-
63
- initProgram() {
64
- if (this._renderer.handler) {
65
- if (!this._renderer.handler.programs.label) {
66
- if (this._renderer.handler.gl.type === "webgl2") {
67
- this._renderer.handler.addProgram(shaders.label_webgl2());
68
- } else {
69
- this._renderer.handler.addProgram(shaders.label_screen());
70
- }
71
- }
72
-
73
- if (!this._renderer.handler.programs.labelPicking) {
74
- this._renderer.handler.addProgram(shaders.labelPicking());
75
- }
76
- }
77
- }
78
-
79
- add(label) {
80
- if (!label._handler) {
81
- label._handler = this;
82
- this.assignFontAtlas(label);
83
- this.refresh();
84
- }
85
- }
86
-
87
- _addLabelToArrays(label) {
88
- this._renderer.labelWorker.make(this, label);
89
- }
90
-
91
- assignFontAtlas(label) {
92
- if (this._entityCollection && this._renderer) {
93
- label.assignFontAtlas(this._renderer.fontAtlas);
94
- this._addLabelToArrays(label);
95
- } else {
96
- this._billboards.push(label);
97
- }
98
- }
99
-
100
- workerCallback(data, label) {
101
- if (label._lockId !== LOCK_FREE && this.isEqual(label._handler)) {
102
- label._isReady = true;
103
- label._lockId = LOCK_FREE;
104
- label._handlerIndex = this._billboards.length;
105
- this._billboards.push(label);
106
-
107
- this._vertexArr = concatTypedArrays(this._vertexArr, data.vertexArr);
108
- this._texCoordArr = concatTypedArrays(this._texCoordArr, data.texCoordArr);
109
- this._gliphParamArr = concatTypedArrays(this._gliphParamArr, data.gliphParamArr);
110
- this._positionHighArr = concatTypedArrays(this._positionHighArr, data.positionHighArr);
111
- this._positionLowArr = concatTypedArrays(this._positionLowArr, data.positionLowArr);
112
- this._sizeArr = concatTypedArrays(this._sizeArr, data.sizeArr);
113
- this._offsetArr = concatTypedArrays(this._offsetArr, data.offsetArr);
114
- this._rgbaArr = concatTypedArrays(this._rgbaArr, data.rgbaArr);
115
- this._rotationArr = concatTypedArrays(this._rotationArr, data.rotationArr);
116
- this._alignedAxisArr = concatTypedArrays(this._alignedAxisArr, data.alignedAxisArr);
117
- this._fontIndexArr = concatTypedArrays(this._fontIndexArr, data.fontIndexArr);
118
- this._outlineArr = concatTypedArrays(this._outlineArr, data.outlineArr);
119
- this._noOutlineArr = concatTypedArrays(this._noOutlineArr, data.noOutlineArr);
120
- this._outlineColorArr = concatTypedArrays(this._outlineColorArr, data.outlineColorArr);
121
- this._pickingColorArr = concatTypedArrays(this._pickingColorArr, data.pickingColorArr);
122
-
123
- label.update();
124
-
125
- this.refresh();
126
- }
127
- }
128
-
129
- clear() {
130
- this._texCoordArr = null;
131
- this._gliphParamArr = null;
132
- this._vertexArr = null;
133
- this._positionHighArr = null;
134
- this._positionLowArr = null;
135
- this._sizeArr = null;
136
- this._offsetArr = null;
137
- this._rgbaArr = null;
138
- this._rotationArr = null;
139
- this._alignedAxisArr = null;
140
- this._fontIndexArr = null;
141
- this._noOutlineArr = null;
142
- this._outlineArr = null;
143
- this._outlineColorArr = null;
144
-
145
- this._texCoordArr = new Float32Array();
146
- this._gliphParamArr = new Float32Array();
147
- this._vertexArr = new Float32Array();
148
- this._positionHighArr = new Float32Array();
149
- this._positionLowArr = new Float32Array();
150
- this._sizeArr = new Float32Array();
151
- this._offsetArr = new Float32Array();
152
- this._rgbaArr = new Float32Array();
153
- this._rotationArr = new Float32Array();
154
- this._alignedAxisArr = new Float32Array();
155
- this._fontIndexArr = new Float32Array();
156
- this._noOutlineArr = new Float32Array();
157
- this._outlineArr = new Float32Array();
158
- this._outlineColorArr = new Float32Array();
159
-
160
- this._removeBillboards();
161
- this._deleteBuffers();
162
- this.refresh();
163
- }
164
-
165
- _deleteBuffers() {
166
- if (this._renderer) {
167
- var gl = this._renderer.handler.gl;
168
- gl.deleteBuffer(this._gliphParamBuffer);
169
- gl.deleteBuffer(this._sizeBuffer);
170
- gl.deleteBuffer(this._fontIndexBuffer);
171
- gl.deleteBuffer(this._texCoordBuffer);
172
- gl.deleteBuffer(this._outlineBuffer);
173
- gl.deleteBuffer(this._noOutlineBuffer);
174
- gl.deleteBuffer(this._outlineColorBuffer);
175
- gl.deleteBuffer(this._positionHighBuffer);
176
- gl.deleteBuffer(this._positionLowBuffer);
177
- gl.deleteBuffer(this._sizeBuffer);
178
- gl.deleteBuffer(this._offsetBuffer);
179
- gl.deleteBuffer(this._rgbaBuffer);
180
- gl.deleteBuffer(this._rotationBuffer);
181
- gl.deleteBuffer(this._vertexBuffer);
182
- gl.deleteBuffer(this._texCoordBuffer);
183
- gl.deleteBuffer(this._alignedAxisBuffer);
184
- gl.deleteBuffer(this._pickingColorBuffer);
185
-
186
- this._gliphParamBuffer = null;
187
- this._sizeBuffer = null;
188
- this._fontIndexBuffer = null;
189
- this._texCoordBuffer = null;
190
- this._outlineBuffer = null;
191
- this._outlineColorBuffer = null;
192
- this._positionHighBuffer = null;
193
- this._positionLowBuffer = null;
194
- this._sizeBuffer = null;
195
- this._offsetBuffer = null;
196
- this._rgbaBuffer = null;
197
- this._rotationBuffer = null;
198
- this._vertexBuffer = null;
199
- this._texCoordBuffer = null;
200
- this._alignedAxisBuffer = null;
201
- this._pickingColorBuffer = null;
202
- }
203
- }
204
-
205
- _displayPASS() {
206
- var r = this._renderer;
207
- var h = r.handler;
208
- h.programs.label.activate();
209
- var sh = h.programs.label._program;
210
- var sha = sh.attributes,
211
- shu = sh.uniforms;
212
-
213
- var gl = h.gl,
214
- ec = this._entityCollection;
215
-
216
- gl.polygonOffset(ec.polygonOffsetFactor, ec.polygonOffsetUnits);
217
-
218
- var rn = ec.renderNode;
219
-
220
- gl.uniform1iv(shu.fontTextureArr, r.fontAtlas.samplerArr);
221
-
222
- gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera._viewMatrix._m);
223
- gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
224
-
225
- gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
226
- gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
227
-
228
- gl.uniform3fv(shu.scaleByDistance, ec.scaleByDistance);
229
-
230
- gl.uniform1f(shu.opacity, ec._fadingOpacity);
231
-
232
- gl.uniform1f(shu.planetRadius, rn._planetRadius2 || 0);
233
-
234
- gl.uniform2fv(shu.viewport, [h.canvas.width, h.canvas.height]);
235
-
236
- gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer);
237
- gl.vertexAttribPointer(
238
- sha.a_texCoord,
239
- this._texCoordBuffer.itemSize,
240
- gl.FLOAT,
241
- false,
242
- 0,
243
- 0
244
- );
245
-
246
- gl.bindBuffer(gl.ARRAY_BUFFER, this._gliphParamBuffer);
247
- gl.vertexAttribPointer(
248
- sha.a_gliphParam,
249
- this._gliphParamBuffer.itemSize,
250
- gl.FLOAT,
251
- false,
252
- 0,
253
- 0
254
- );
255
-
256
- gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
257
- gl.vertexAttribPointer(sha.a_vertices, this._vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
258
-
259
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer);
260
- gl.vertexAttribPointer(
261
- sha.a_positionsHigh,
262
- this._positionHighBuffer.itemSize,
263
- gl.FLOAT,
264
- false,
265
- 0,
266
- 0
267
- );
268
-
269
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer);
270
- gl.vertexAttribPointer(
271
- sha.a_positionsLow,
272
- this._positionLowBuffer.itemSize,
273
- gl.FLOAT,
274
- false,
275
- 0,
276
- 0
277
- );
278
-
279
- gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer);
280
- gl.vertexAttribPointer(sha.a_size, this._sizeBuffer.itemSize, gl.FLOAT, false, 0, 0);
281
-
282
- //gl.bindBuffer(gl.ARRAY_BUFFER, this._rotationBuffer);
283
- //gl.vertexAttribPointer(sha.a_rotation, this._rotationBuffer.itemSize, gl.FLOAT, false, 0, 0);
284
-
285
- //gl.bindBuffer(gl.ARRAY_BUFFER, this._alignedAxisBuffer);
286
- //gl.vertexAttribPointer(sha.a_alignedAxis, this._alignedAxisBuffer.itemSize, gl.FLOAT, false, 0, 0);
287
-
288
- gl.bindBuffer(gl.ARRAY_BUFFER, this._offsetBuffer);
289
- gl.vertexAttribPointer(sha.a_offset, this._offsetBuffer.itemSize, gl.FLOAT, false, 0, 0);
290
-
291
- gl.bindBuffer(gl.ARRAY_BUFFER, this._fontIndexBuffer);
292
- gl.vertexAttribPointer(
293
- sha.a_fontIndex,
294
- this._fontIndexBuffer.itemSize,
295
- gl.FLOAT,
296
- false,
297
- 0,
298
- 0
299
- );
300
-
301
- //
302
- // outline
303
- gl.bindBuffer(gl.ARRAY_BUFFER, this._outlineColorBuffer);
304
- gl.vertexAttribPointer(
305
- sha.a_rgba,
306
- this._outlineColorBuffer.itemSize,
307
- gl.FLOAT,
308
- false,
309
- 0,
310
- 0
311
- );
312
-
313
- gl.bindBuffer(gl.ARRAY_BUFFER, this._outlineBuffer);
314
- gl.vertexAttribPointer(sha.a_outline, this._outlineBuffer.itemSize, gl.FLOAT, false, 0, 0);
315
-
316
- gl.uniform1f(shu.uZ, window.uZ + window.dZ);
317
- gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
318
-
319
- //
320
- // nooutline
321
- gl.bindBuffer(gl.ARRAY_BUFFER, this._rgbaBuffer);
322
- gl.vertexAttribPointer(sha.a_rgba, this._rgbaBuffer.itemSize, gl.FLOAT, false, 0, 0);
323
-
324
- gl.bindBuffer(gl.ARRAY_BUFFER, this._noOutlineBuffer);
325
- gl.vertexAttribPointer(
326
- sha.a_outline,
327
- this._noOutlineBuffer.itemSize,
328
- gl.FLOAT,
329
- false,
330
- 0,
331
- 0
332
- );
333
-
334
- gl.uniform1f(shu.uZ, window.uZ);
335
- gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
336
- }
337
-
338
- _pickingPASS() {
339
- var r = this._renderer;
340
- var h = r.handler;
341
- h.programs.labelPicking.activate();
342
- var sh = h.programs.labelPicking._program;
343
- var sha = sh.attributes,
344
- shu = sh.uniforms;
345
-
346
- var gl = h.gl,
347
- ec = this._entityCollection;
348
-
349
- gl.polygonOffset(ec.polygonOffsetFactor, ec.polygonOffsetUnits);
350
-
351
- var rn = ec.renderNode;
352
-
353
- gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera._viewMatrix._m);
354
- gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
355
-
356
- gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
357
- gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
358
-
359
- gl.uniform3fv(shu.scaleByDistance, ec.scaleByDistance);
360
-
361
- gl.uniform1f(shu.opacity, ec._fadingOpacity);
362
-
363
- gl.uniform1f(shu.planetRadius, rn._planetRadius2 || 0);
364
-
365
- gl.uniform2fv(shu.viewport, [h.canvas.width, h.canvas.height]);
366
-
367
- gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer);
368
- gl.vertexAttribPointer(
369
- sha.a_texCoord,
370
- this._texCoordBuffer.itemSize,
371
- gl.FLOAT,
372
- false,
373
- 0,
374
- 0
375
- );
376
-
377
- gl.bindBuffer(gl.ARRAY_BUFFER, this._gliphParamBuffer);
378
- gl.vertexAttribPointer(
379
- sha.a_gliphParam,
380
- this._gliphParamBuffer.itemSize,
381
- gl.FLOAT,
382
- false,
383
- 0,
384
- 0
385
- );
386
-
387
- gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
388
- gl.vertexAttribPointer(sha.a_vertices, this._vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
389
-
390
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer);
391
- gl.vertexAttribPointer(
392
- sha.a_positionsHigh,
393
- this._positionHighBuffer.itemSize,
394
- gl.FLOAT,
395
- false,
396
- 0,
397
- 0
398
- );
399
-
400
- gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer);
401
- gl.vertexAttribPointer(
402
- sha.a_positionsLow,
403
- this._positionLowBuffer.itemSize,
404
- gl.FLOAT,
405
- false,
406
- 0,
407
- 0
408
- );
409
-
410
- gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer);
411
- gl.vertexAttribPointer(sha.a_size, this._sizeBuffer.itemSize, gl.FLOAT, false, 0, 0);
412
-
413
- //gl.bindBuffer(gl.ARRAY_BUFFER, this._rotationBuffer);
414
- //gl.vertexAttribPointer(sha.a_rotation, this._rotationBuffer.itemSize, gl.FLOAT, false, 0, 0);
415
-
416
- //gl.bindBuffer(gl.ARRAY_BUFFER, this._alignedAxisBuffer);
417
- //gl.vertexAttribPointer(sha.a_alignedAxis, this._alignedAxisBuffer.itemSize, gl.FLOAT, false, 0, 0);
418
-
419
- gl.bindBuffer(gl.ARRAY_BUFFER, this._offsetBuffer);
420
- gl.vertexAttribPointer(sha.a_offset, this._offsetBuffer.itemSize, gl.FLOAT, false, 0, 0);
421
-
422
- // no outline
423
- gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer);
424
- gl.vertexAttribPointer(
425
- sha.a_rgba,
426
- this._pickingColorBuffer.itemSize,
427
- gl.FLOAT,
428
- false,
429
- 0,
430
- 0
431
- );
432
-
433
- gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
434
- }
435
-
436
- _removeBillboard(label) {
437
- var li = label._handlerIndex;
438
-
439
- this._billboards.splice(li, 1);
440
-
441
- var ml = 24 * this._maxLetters;
442
- var i = li * ml;
443
- this._rgbaArr = spliceTypedArray(this._rgbaArr, i, ml);
444
- this._outlineColorArr = spliceTypedArray(this._outlineColorArr, i, ml);
445
- this._texCoordArr = spliceTypedArray(this._texCoordArr, i, ml);
446
- this._gliphParamArr = spliceTypedArray(this._gliphParamArr, i, ml);
447
-
448
- ml = 18 * this._maxLetters;
449
- i = li * ml;
450
- this._positionHighArr = spliceTypedArray(this._positionHighArr, i, ml);
451
- this._positionLowArr = spliceTypedArray(this._positionLowArr, i, ml);
452
- this._offsetArr = spliceTypedArray(this._offsetArr, i, ml);
453
- this._alignedAxisArr = spliceTypedArray(this._alignedAxisArr, i, ml);
454
- this._pickingColorArr = spliceTypedArray(this._pickingColorArr, i, ml);
455
-
456
- ml = 12 * this._maxLetters;
457
- i = li * ml;
458
- this._vertexArr = spliceTypedArray(this._vertexArr, i, ml);
459
-
460
- ml = 6 * this._maxLetters;
461
- i = li * ml;
462
- this._sizeArr = spliceTypedArray(this._sizeArr, i, ml);
463
- this._rotationArr = spliceTypedArray(this._rotationArr, i, ml);
464
- this._fontIndexArr = spliceTypedArray(this._fontIndexArr, i, ml);
465
- this._outlineArr = spliceTypedArray(this._outlineArr, i, ml);
466
- this._noOutlineArr = spliceTypedArray(this._noOutlineArr, i, ml);
467
-
468
- this.reindexBillbordsArray(li);
469
- this.refresh();
470
-
471
- label._handlerIndex = -1;
1
+ /**
2
+ * @module og/entity/LabelHandler
3
+ */
4
+
5
+ "use strict";
6
+
7
+ import * as shaders from "../shaders/label.js";
8
+ import { ALIGN } from "./Label.js";
9
+ import { BillboardHandler } from "./BillboardHandler.js";
10
+ import { concatTypedArrays, spliceTypedArray } from "../utils/shared.js";
11
+ import { LOCK_FREE } from "./LabelWorker.js";
12
+
13
+ const PICKINGCOLOR_BUFFER = 0;
14
+ const POSITION_BUFFER = 1;
15
+ const SIZE_BUFFER = 2;
16
+ const OFFSET_BUFFER = 3;
17
+ const RGBA_BUFFER = 4;
18
+ const ROTATION_BUFFER = 5;
19
+ const TEXCOORD_BUFFER = 6;
20
+ const VERTEX_BUFFER = 7;
21
+ const FONTINDEX_BUFFER = 8;
22
+ const OUTLINE_BUFFER = 9;
23
+ const OUTLINECOLOR_BUFFER = 10;
24
+
25
+ window.LABEL_DEPTH_OFFSET = -0;
26
+
27
+ /*
28
+ * og.LabelHandler
29
+ *
30
+ *
31
+ */
32
+ class LabelHandler extends BillboardHandler {
33
+ /**
34
+ *
35
+ * @param {*} entityCollection
36
+ * @param {*} maxLetters
37
+ */
38
+ constructor(entityCollection, maxLetters = 21) {
39
+ super(entityCollection);
40
+
41
+ this._gliphParamBuffer = null;
42
+ this._fontIndexBuffer = null;
43
+ this._outlineBuffer = null;
44
+ this._outlineColorBuffer = null;
45
+
46
+ this._gliphParamArr = new Float32Array();
47
+ this._fontIndexArr = new Float32Array();
48
+ this._outlineArr = new Float32Array();
49
+ this._outlineColorArr = new Float32Array();
50
+
51
+ this._buffersUpdateCallbacks[FONTINDEX_BUFFER] = this.createFontIndexBuffer;
52
+ this._buffersUpdateCallbacks[OUTLINE_BUFFER] = this.createOutlineBuffer;
53
+ this._buffersUpdateCallbacks[OUTLINECOLOR_BUFFER] = this.createOutlineColorBuffer;
54
+
55
+ this._changedBuffers = new Array(this._buffersUpdateCallbacks.length);
56
+
57
+ this._maxLetters = maxLetters;
58
+ }
59
+
60
+ initProgram() {
61
+ if (this._renderer.handler) {
62
+ if (!this._renderer.handler.programs.label) {
63
+ if (this._renderer.handler.gl.type === "webgl2") {
64
+ this._renderer.handler.addProgram(shaders.label_webgl2());
65
+ } else {
66
+ this._renderer.handler.addProgram(shaders.label_screen());
67
+ }
68
+ }
69
+
70
+ if (!this._renderer.handler.programs.labelPicking) {
71
+ this._renderer.handler.addProgram(shaders.labelPicking());
72
+ }
73
+ }
74
+ }
75
+
76
+ add(label) {
77
+ if (!label._handler) {
78
+ label._handler = this;
79
+ this.assignFontAtlas(label);
80
+ this.refresh();
81
+ }
82
+ }
83
+
84
+ _addLabelToArrays(label) {
85
+ this._renderer.labelWorker.make(this, label);
86
+ }
87
+
88
+ assignFontAtlas(label) {
89
+ if (this._entityCollection && this._renderer) {
90
+ label.assignFontAtlas(this._renderer.fontAtlas);
91
+ this._addLabelToArrays(label);
92
+ } else {
93
+ this._billboards.push(label);
94
+ }
95
+ }
96
+
97
+ workerCallback(data, label) {
98
+ if (label._lockId !== LOCK_FREE && this.isEqual(label._handler)) {
99
+ label._isReady = true;
100
+ label._lockId = LOCK_FREE;
101
+ label._handlerIndex = this._billboards.length;
102
+ this._billboards.push(label);
103
+
104
+ this._vertexArr = concatTypedArrays(this._vertexArr, data.vertexArr);
105
+ this._texCoordArr = concatTypedArrays(this._texCoordArr, data.texCoordArr);
106
+ this._gliphParamArr = concatTypedArrays(this._gliphParamArr, data.gliphParamArr);
107
+ this._positionHighArr = concatTypedArrays(this._positionHighArr, data.positionHighArr);
108
+ this._positionLowArr = concatTypedArrays(this._positionLowArr, data.positionLowArr);
109
+ this._sizeArr = concatTypedArrays(this._sizeArr, data.sizeArr);
110
+ this._offsetArr = concatTypedArrays(this._offsetArr, data.offsetArr);
111
+ this._rgbaArr = concatTypedArrays(this._rgbaArr, data.rgbaArr);
112
+ this._rotationArr = concatTypedArrays(this._rotationArr, data.rotationArr);
113
+ this._fontIndexArr = concatTypedArrays(this._fontIndexArr, data.fontIndexArr);
114
+ this._outlineArr = concatTypedArrays(this._outlineArr, data.outlineArr);
115
+ this._outlineColorArr = concatTypedArrays(this._outlineColorArr, data.outlineColorArr);
116
+ this._pickingColorArr = concatTypedArrays(this._pickingColorArr, data.pickingColorArr);
117
+
118
+ label.update();
119
+
120
+ this.refresh();
121
+ }
122
+ }
123
+
124
+ clear() {
125
+ this._texCoordArr = null;
126
+ this._gliphParamArr = null;
127
+ this._vertexArr = null;
128
+ this._positionHighArr = null;
129
+ this._positionLowArr = null;
130
+ this._sizeArr = null;
131
+ this._offsetArr = null;
132
+ this._rgbaArr = null;
133
+ this._rotationArr = null;
134
+ this._fontIndexArr = null;
135
+ this._outlineArr = null;
136
+ this._outlineColorArr = null;
137
+
138
+ this._texCoordArr = new Float32Array();
139
+ this._gliphParamArr = new Float32Array();
140
+ this._vertexArr = new Float32Array();
141
+ this._positionHighArr = new Float32Array();
142
+ this._positionLowArr = new Float32Array();
143
+ this._sizeArr = new Float32Array();
144
+ this._offsetArr = new Float32Array();
145
+ this._rgbaArr = new Float32Array();
146
+ this._rotationArr = new Float32Array();
147
+ this._fontIndexArr = new Float32Array();
148
+ this._outlineArr = new Float32Array();
149
+ this._outlineColorArr = new Float32Array();
150
+
151
+ this._removeBillboards();
152
+ this._deleteBuffers();
153
+ this.refresh();
154
+ }
155
+
156
+ _deleteBuffers() {
157
+ if (this._renderer) {
158
+ var gl = this._renderer.handler.gl;
159
+ gl.deleteBuffer(this._gliphParamBuffer);
160
+ gl.deleteBuffer(this._sizeBuffer);
161
+ gl.deleteBuffer(this._fontIndexBuffer);
162
+ gl.deleteBuffer(this._texCoordBuffer);
163
+ gl.deleteBuffer(this._outlineBuffer);
164
+ gl.deleteBuffer(this._outlineColorBuffer);
165
+ gl.deleteBuffer(this._positionHighBuffer);
166
+ gl.deleteBuffer(this._positionLowBuffer);
167
+ gl.deleteBuffer(this._sizeBuffer);
168
+ gl.deleteBuffer(this._offsetBuffer);
169
+ gl.deleteBuffer(this._rgbaBuffer);
170
+ gl.deleteBuffer(this._rotationBuffer);
171
+ gl.deleteBuffer(this._vertexBuffer);
172
+ gl.deleteBuffer(this._texCoordBuffer);
173
+ gl.deleteBuffer(this._pickingColorBuffer);
174
+
175
+ this._gliphParamBuffer = null;
176
+ this._sizeBuffer = null;
177
+ this._fontIndexBuffer = null;
178
+ this._texCoordBuffer = null;
179
+ this._outlineBuffer = null;
180
+ this._outlineColorBuffer = null;
181
+ this._positionHighBuffer = null;
182
+ this._positionLowBuffer = null;
183
+ this._sizeBuffer = null;
184
+ this._offsetBuffer = null;
185
+ this._rgbaBuffer = null;
186
+ this._rotationBuffer = null;
187
+ this._vertexBuffer = null;
188
+ this._texCoordBuffer = null;
189
+ this._pickingColorBuffer = null;
190
+ }
191
+ }
192
+
193
+ _displayPASS() {
194
+ var r = this._renderer;
195
+ var h = r.handler;
196
+ h.programs.label.activate();
197
+ var sh = h.programs.label._program;
198
+ var sha = sh.attributes,
199
+ shu = sh.uniforms;
200
+
201
+ var gl = h.gl,
202
+ ec = this._entityCollection;
203
+
204
+ gl.uniform1iv(shu.fontTextureArr, r.fontAtlas.samplerArr);
205
+ gl.uniform4fv(shu.sdfParamsArr, r.fontAtlas.sdfParamsArr);
206
+ gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera._viewMatrix._m);
207
+ gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
208
+ gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
209
+ gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
210
+ gl.uniform3fv(shu.scaleByDistance, ec.scaleByDistance);
211
+ gl.uniform1f(shu.opacity, ec._fadingOpacity);
212
+ gl.uniform1f(shu.planetRadius, ec.renderNode._planetRadius2 || 0);
213
+ gl.uniform2fv(shu.viewport, [h.canvas.clientWidth, h.canvas.clientHeight]);
214
+
215
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer);
216
+ gl.vertexAttribPointer(sha.a_texCoord, this._texCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
217
+
218
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._gliphParamBuffer);
219
+ gl.vertexAttribPointer(sha.a_gliphParam, this._gliphParamBuffer.itemSize, gl.FLOAT, false, 0, 0);
220
+
221
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
222
+ gl.vertexAttribPointer(sha.a_vertices, this._vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
223
+
224
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer);
225
+ gl.vertexAttribPointer(sha.a_positionsHigh, this._positionHighBuffer.itemSize, gl.FLOAT, false, 0, 0);
226
+
227
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer);
228
+ gl.vertexAttribPointer(sha.a_positionsLow, this._positionLowBuffer.itemSize, gl.FLOAT, false, 0, 0);
229
+
230
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer);
231
+ gl.vertexAttribPointer(sha.a_size, this._sizeBuffer.itemSize, gl.FLOAT, false, 0, 0);
232
+
233
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rotationBuffer);
234
+ gl.vertexAttribPointer(sha.a_rotation, this._rotationBuffer.itemSize, gl.FLOAT, false, 0, 0);
235
+
236
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._offsetBuffer);
237
+ gl.vertexAttribPointer(sha.a_offset, this._offsetBuffer.itemSize, gl.FLOAT, false, 0, 0);
238
+
239
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._fontIndexBuffer);
240
+ gl.vertexAttribPointer(sha.a_fontIndex, this._fontIndexBuffer.itemSize, gl.FLOAT, false, 0, 0);
241
+
242
+ //
243
+ // outline PASS
244
+ gl.uniform1i(shu.isOutlinePass, 1);
245
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
246
+
247
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._outlineColorBuffer);
248
+ gl.vertexAttribPointer(sha.a_rgba, this._outlineColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
249
+
250
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._outlineBuffer);
251
+ gl.vertexAttribPointer(sha.a_outline, this._outlineBuffer.itemSize, gl.FLOAT, false, 0, 0);
252
+
253
+ gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
254
+
255
+ //
256
+ // no outline PASS
257
+ gl.depthFunc(gl.EQUAL);
258
+ gl.uniform1i(shu.isOutlinePass, 0);
259
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
260
+
261
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rgbaBuffer);
262
+ gl.vertexAttribPointer(sha.a_rgba, this._rgbaBuffer.itemSize, gl.FLOAT, false, 0, 0);
263
+
264
+ gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
265
+
266
+ gl.depthFunc(gl.LESS);
267
+ }
268
+
269
+ _pickingPASS() {
270
+ var r = this._renderer;
271
+ var h = r.handler;
272
+ h.programs.labelPicking.activate();
273
+ var sh = h.programs.labelPicking._program;
274
+ var sha = sh.attributes,
275
+ shu = sh.uniforms;
276
+
277
+ var gl = h.gl,
278
+ ec = this._entityCollection;
279
+
280
+ var rn = ec.renderNode;
281
+
282
+ gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera._viewMatrix._m);
283
+ gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
284
+ gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
285
+ gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
286
+ gl.uniform3fv(shu.scaleByDistance, ec.scaleByDistance);
287
+ gl.uniform1f(shu.opacity, ec._fadingOpacity);
288
+ gl.uniform1f(shu.planetRadius, rn._planetRadius2 || 0);
289
+ gl.uniform2fv(shu.viewport, [h.canvas.clientWidth, h.canvas.clientHeight]);
290
+
291
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer);
292
+ gl.vertexAttribPointer(sha.a_texCoord, this._texCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
293
+
294
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._gliphParamBuffer);
295
+ gl.vertexAttribPointer(sha.a_gliphParam, this._gliphParamBuffer.itemSize, gl.FLOAT, false, 0, 0);
296
+
297
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
298
+ gl.vertexAttribPointer(sha.a_vertices, this._vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
299
+
300
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer);
301
+ gl.vertexAttribPointer(sha.a_positionsHigh, this._positionHighBuffer.itemSize, gl.FLOAT, false, 0, 0);
302
+
303
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer);
304
+ gl.vertexAttribPointer(sha.a_positionsLow, this._positionLowBuffer.itemSize, gl.FLOAT, false, 0, 0);
305
+
306
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer);
307
+ gl.vertexAttribPointer(sha.a_size, this._sizeBuffer.itemSize, gl.FLOAT, false, 0, 0);
308
+
309
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rotationBuffer);
310
+ gl.vertexAttribPointer(sha.a_rotation, this._rotationBuffer.itemSize, gl.FLOAT, false, 0, 0);
311
+
312
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._offsetBuffer);
313
+ gl.vertexAttribPointer(sha.a_offset, this._offsetBuffer.itemSize, gl.FLOAT, false, 0, 0);
314
+
315
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer);
316
+ gl.vertexAttribPointer(sha.a_rgba, this._pickingColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
317
+
318
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
319
+
320
+
321
+ gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
322
+ }
323
+
324
+ _removeBillboard(label) {
325
+ var li = label._handlerIndex;
326
+
327
+ this._billboards.splice(li, 1);
328
+
329
+ var ml = 24 * this._maxLetters;
330
+ var i = li * ml;
331
+ this._rgbaArr = spliceTypedArray(this._rgbaArr, i, ml);
332
+ this._outlineColorArr = spliceTypedArray(this._outlineColorArr, i, ml);
333
+ this._texCoordArr = spliceTypedArray(this._texCoordArr, i, ml);
334
+ this._gliphParamArr = spliceTypedArray(this._gliphParamArr, i, ml);
335
+
336
+ ml = 18 * this._maxLetters;
337
+ i = li * ml;
338
+ this._positionHighArr = spliceTypedArray(this._positionHighArr, i, ml);
339
+ this._positionLowArr = spliceTypedArray(this._positionLowArr, i, ml);
340
+ this._offsetArr = spliceTypedArray(this._offsetArr, i, ml);
341
+ this._pickingColorArr = spliceTypedArray(this._pickingColorArr, i, ml);
342
+
343
+ ml = 12 * this._maxLetters;
344
+ i = li * ml;
345
+ this._vertexArr = spliceTypedArray(this._vertexArr, i, ml);
346
+
347
+ ml = 6 * this._maxLetters;
348
+ i = li * ml;
349
+ this._sizeArr = spliceTypedArray(this._sizeArr, i, ml);
350
+ this._rotationArr = spliceTypedArray(this._rotationArr, i, ml);
351
+ this._fontIndexArr = spliceTypedArray(this._fontIndexArr, i, ml);
352
+ this._outlineArr = spliceTypedArray(this._outlineArr, i, ml);
353
+
354
+ this.reindexBillbordsArray(li);
355
+ this.refresh();
356
+
357
+ label._handlerIndex = -1;
472
358
  label._handler = null;
473
- label._isReady = false;
474
- }
475
-
476
- setText(index, text, fontIndex, align) {
477
- var fa = this._renderer.fontAtlas.atlasesArr[fontIndex];
478
-
479
- if (!fa) return;
480
-
481
- let i = index * 24 * this._maxLetters;
482
- let a = this._texCoordArr,
483
- g = this._gliphParamArr;
484
-
485
- let c = 0;
486
-
487
- let n = fa.nodes[text[c]];
488
- let offset = 0.0;
489
- let len = Math.min(this._maxLetters, text.length);
490
- let kern = fa.kernings;
491
-
492
- for (c = 0; c < len; c++) {
493
- let j = i + c * 24;
494
- let char = text[c];
495
- n = fa.nodes[char] || fa.nodes[" "];
496
- let tc = n.texCoords;
497
-
498
- let m = n.metrics;
499
-
500
- a[j] = tc[0];
501
- a[j + 1] = tc[1];
502
- a[j + 2] = offset;
503
- a[j + 3] = 0.0;
504
-
505
- a[j + 4] = tc[2];
506
- a[j + 5] = tc[3];
507
- a[j + 6] = offset;
508
- a[j + 7] = 0.0;
509
-
510
- a[j + 8] = tc[4];
511
- a[j + 9] = tc[5];
512
- a[j + 10] = offset;
513
- a[j + 11] = 0.0;
514
-
515
- a[j + 12] = tc[6];
516
- a[j + 13] = tc[7];
517
- a[j + 14] = offset;
518
- a[j + 15] = 0.0;
519
-
520
- a[j + 16] = tc[8];
521
- a[j + 17] = tc[9];
522
- a[j + 18] = offset;
523
- a[j + 19] = 0.0;
524
-
525
- a[j + 20] = tc[10];
526
- a[j + 21] = tc[11];
527
- a[j + 22] = offset;
528
- a[j + 23] = 0.0;
529
-
530
- //
531
- // Gliph
532
- //
533
- g[j] = m.nWidth;
534
- g[j + 1] = m.nHeight;
535
- g[j + 2] = m.nXOffset;
536
- g[j + 3] = m.nYOffset;
537
-
538
- g[j + 4] = m.nWidth;
539
- g[j + 5] = m.nHeight;
540
- g[j + 6] = m.nXOffset;
541
- g[j + 7] = m.nYOffset;
542
-
543
- g[j + 8] = m.nWidth;
544
- g[j + 9] = m.nHeight;
545
- g[j + 10] = m.nXOffset;
546
- g[j + 11] = m.nYOffset;
547
-
548
- g[j + 12] = m.nWidth;
549
- g[j + 13] = m.nHeight;
550
- g[j + 14] = m.nXOffset;
551
- g[j + 15] = m.nYOffset;
552
-
553
- g[j + 16] = m.nWidth;
554
- g[j + 17] = m.nHeight;
555
- g[j + 18] = m.nXOffset;
556
- g[j + 19] = m.nYOffset;
557
-
558
- g[j + 20] = m.nWidth;
559
- g[j + 21] = m.nHeight;
560
- g[j + 22] = m.nXOffset;
561
- g[j + 23] = m.nYOffset;
562
-
563
- let k = kern[char];
564
- if (k) {
565
- k = k[text[c + 1]];
566
- if (k) {
567
- offset += m.nAdvance + k;
568
- } else {
569
- offset += m.nAdvance;
570
- }
571
- } else {
572
- offset += m.nAdvance;
573
- }
574
- }
575
-
576
- // 49/512 - font atlas left border letter offset
577
- if (align === ALIGN.CENTER) {
578
- offset *= -0.5;
579
- for (c = 0; c < len; c++) {
580
- let j = i + c * 24;
581
- a[j + 3] = offset;
582
- a[j + 7] = offset;
583
- a[j + 11] = offset;
584
- a[j + 15] = offset;
585
- a[j + 19] = offset;
586
- a[j + 23] = offset;
587
- }
588
- } else if (align === ALIGN.LEFT) {
589
- for (c = 0; c < len; c++) {
590
- let j = i + c * 24;
591
- a[j + 3] = 0;
592
- a[j + 7] = 0;
593
- a[j + 11] = 0;
594
- a[j + 15] = 0;
595
- a[j + 19] = 0;
596
- a[j + 23] = 0;
597
- }
598
- }
599
-
600
- for (; c < this._maxLetters; c++) {
601
- let j = i + c * 24;
602
- a[j + 2] = -1.0;
603
- a[j + 6] = -1.0;
604
- a[j + 10] = -1.0;
605
- a[j + 14] = -1.0;
606
- a[j + 18] = -1.0;
607
- a[j + 17] = -1.0;
608
- }
609
-
610
- this._changedBuffers[TEXCOORD_BUFFER] = true;
611
- }
612
-
613
- setPositionArr(index, positionHigh, positionLow) {
614
- var i = index * 18 * this._maxLetters;
615
- var a = this._positionHighArr,
616
- x = positionHigh.x,
617
- y = positionHigh.y,
618
- z = positionHigh.z,
619
- b = this._positionLowArr,
620
- xl = positionLow.x,
621
- yl = positionLow.y,
622
- zl = positionLow.z;
623
-
624
- for (var q = 0; q < this._maxLetters; q++) {
625
- var j = i + q * 18;
626
- a[j] = x;
627
- a[j + 1] = y;
628
- a[j + 2] = z;
629
-
630
- a[j + 3] = x;
631
- a[j + 4] = y;
632
- a[j + 5] = z;
633
-
634
- a[j + 6] = x;
635
- a[j + 7] = y;
636
- a[j + 8] = z;
637
-
638
- a[j + 9] = x;
639
- a[j + 10] = y;
640
- a[j + 11] = z;
641
-
642
- a[j + 12] = x;
643
- a[j + 13] = y;
644
- a[j + 14] = z;
645
-
646
- a[j + 15] = x;
647
- a[j + 16] = y;
648
- a[j + 17] = z;
649
-
650
- // low
651
- b[j] = xl;
652
- b[j + 1] = yl;
653
- b[j + 2] = zl;
654
-
655
- b[j + 3] = xl;
656
- b[j + 4] = yl;
657
- b[j + 5] = zl;
658
-
659
- b[j + 6] = xl;
660
- b[j + 7] = yl;
661
- b[j + 8] = zl;
662
-
663
- b[j + 9] = xl;
664
- b[j + 10] = yl;
665
- b[j + 11] = zl;
666
-
667
- b[j + 12] = xl;
668
- b[j + 13] = yl;
669
- b[j + 14] = zl;
670
-
671
- b[j + 15] = xl;
672
- b[j + 16] = yl;
673
- b[j + 17] = zl;
674
- }
675
-
676
- this._changedBuffers[POSITION_BUFFER] = true;
677
- }
678
-
679
- setPickingColorArr(index, color) {
680
- var i = index * 18 * this._maxLetters;
681
- var a = this._pickingColorArr,
682
- x = color.x / 255,
683
- y = color.y / 255,
684
- z = color.z / 255;
685
-
686
- for (var q = 0; q < this._maxLetters; q++) {
687
- var j = i + q * 18;
688
- a[j] = x;
689
- a[j + 1] = y;
690
- a[j + 2] = z;
691
-
692
- a[j + 3] = x;
693
- a[j + 4] = y;
694
- a[j + 5] = z;
695
-
696
- a[j + 6] = x;
697
- a[j + 7] = y;
698
- a[j + 8] = z;
699
-
700
- a[j + 9] = x;
701
- a[j + 10] = y;
702
- a[j + 11] = z;
703
-
704
- a[j + 12] = x;
705
- a[j + 13] = y;
706
- a[j + 14] = z;
707
-
708
- a[j + 15] = x;
709
- a[j + 16] = y;
710
- a[j + 17] = z;
711
- }
712
-
713
- this._changedBuffers[PICKINGCOLOR_BUFFER] = true;
714
- }
715
-
716
- setSizeArr(index, size) {
717
- var i = index * 6 * this._maxLetters;
718
- var a = this._sizeArr;
719
-
720
- for (var q = 0; q < this._maxLetters; q++) {
721
- var j = i + q * 6;
722
- a[j] = size;
723
- a[j + 1] = size;
724
- a[j + 2] = size;
725
- a[j + 3] = size;
726
- a[j + 4] = size;
727
- a[j + 5] = size;
728
- }
729
-
730
- this._changedBuffers[SIZE_BUFFER] = true;
731
- }
732
-
733
- setOffsetArr(index, offset) {
734
- var i = index * 18 * this._maxLetters;
735
- var a = this._offsetArr,
736
- x = offset.x,
737
- y = offset.y,
738
- z = offset.z;
739
-
740
- for (var q = 0; q < this._maxLetters; q++) {
741
- var j = i + q * 18;
742
- a[j] = x;
743
- a[j + 1] = y;
744
- a[j + 2] = z;
745
-
746
- a[j + 3] = x;
747
- a[j + 4] = y;
748
- a[j + 5] = z;
749
-
750
- a[j + 6] = x;
751
- a[j + 7] = y;
752
- a[j + 8] = z;
753
-
754
- a[j + 9] = x;
755
- a[j + 10] = y;
756
- a[j + 11] = z;
757
-
758
- a[j + 12] = x;
759
- a[j + 13] = y;
760
- a[j + 14] = z;
761
-
762
- a[j + 15] = x;
763
- a[j + 16] = y;
764
- a[j + 17] = z;
765
- }
766
-
767
- this._changedBuffers[OFFSET_BUFFER] = true;
768
- }
769
-
770
- setRgbaArr(index, rgba) {
771
- var i = index * 24 * this._maxLetters;
772
- var a = this._rgbaArr,
773
- x = rgba.x,
774
- y = rgba.y,
775
- z = rgba.z,
776
- w = rgba.w;
777
-
778
- for (var q = 0; q < this._maxLetters; q++) {
779
- var j = i + q * 24;
780
-
781
- a[j] = x;
782
- a[j + 1] = y;
783
- a[j + 2] = z;
784
- a[j + 3] = w;
785
-
786
- a[j + 4] = x;
787
- a[j + 5] = y;
788
- a[j + 6] = z;
789
- a[j + 7] = w;
790
-
791
- a[j + 8] = x;
792
- a[j + 9] = y;
793
- a[j + 10] = z;
794
- a[j + 11] = w;
795
-
796
- a[j + 12] = x;
797
- a[j + 13] = y;
798
- a[j + 14] = z;
799
- a[j + 15] = w;
800
-
801
- a[j + 16] = x;
802
- a[j + 17] = y;
803
- a[j + 18] = z;
804
- a[j + 19] = w;
805
-
806
- a[j + 20] = x;
807
- a[j + 21] = y;
808
- a[j + 22] = z;
809
- a[j + 23] = w;
810
- }
811
-
812
- this._changedBuffers[RGBA_BUFFER] = true;
813
- }
814
-
815
- setOutlineColorArr(index, rgba) {
816
- var i = index * 24 * this._maxLetters;
817
- var a = this._outlineColorArr,
818
- x = rgba.x,
819
- y = rgba.y,
820
- z = rgba.z,
821
- w = rgba.w;
822
-
823
- for (var q = 0; q < this._maxLetters; q++) {
824
- var j = i + q * 24;
825
-
826
- a[j] = x;
827
- a[j + 1] = y;
828
- a[j + 2] = z;
829
- a[j + 3] = w;
830
-
831
- a[j + 4] = x;
832
- a[j + 5] = y;
833
- a[j + 6] = z;
834
- a[j + 7] = w;
835
-
836
- a[j + 8] = x;
837
- a[j + 9] = y;
838
- a[j + 10] = z;
839
- a[j + 11] = w;
840
-
841
- a[j + 12] = x;
842
- a[j + 13] = y;
843
- a[j + 14] = z;
844
- a[j + 15] = w;
845
-
846
- a[j + 16] = x;
847
- a[j + 17] = y;
848
- a[j + 18] = z;
849
- a[j + 19] = w;
850
-
851
- a[j + 20] = x;
852
- a[j + 21] = y;
853
- a[j + 22] = z;
854
- a[j + 23] = w;
855
- }
856
-
857
- this._changedBuffers[OUTLINECOLOR_BUFFER] = true;
858
- }
859
-
860
- setOutlineArr(index, outline) {
861
- var i = index * 6 * this._maxLetters;
862
- var a = this._outlineArr;
863
-
864
- for (var q = 0; q < this._maxLetters; q++) {
865
- var j = i + q * 6;
866
- a[j] = outline;
867
- a[j + 1] = outline;
868
- a[j + 2] = outline;
869
- a[j + 3] = outline;
870
- a[j + 4] = outline;
871
- a[j + 5] = outline;
872
- }
873
-
874
- this._changedBuffers[OUTLINE_BUFFER] = true;
875
- }
876
-
877
- setRotationArr(index, rotation) {
878
- var i = index * 6 * this._maxLetters;
879
- var a = this._rotationArr;
880
-
881
- for (var q = 0; q < this._maxLetters; q++) {
882
- var j = i + q * 6;
883
- a[j] = rotation;
884
- a[j + 1] = rotation;
885
- a[j + 2] = rotation;
886
- a[j + 3] = rotation;
887
- a[j + 4] = rotation;
888
- a[j + 5] = rotation;
889
- }
890
-
891
- this._changedBuffers[ROTATION_BUFFER] = true;
892
- }
893
-
894
- setVertexArr(index, vertexArr) {
895
- var i = index * 12 * this._maxLetters;
896
- var a = this._vertexArr;
897
-
898
- for (var q = 0; q < this._maxLetters; q++) {
899
- var j = i + q * 12;
900
- a[j] = vertexArr[0];
901
- a[j + 1] = vertexArr[1];
902
- a[j + 2] = vertexArr[2];
903
-
904
- a[j + 3] = vertexArr[3];
905
- a[j + 4] = vertexArr[4];
906
- a[j + 5] = vertexArr[5];
907
-
908
- a[j + 6] = vertexArr[6];
909
- a[j + 7] = vertexArr[7];
910
- a[j + 8] = vertexArr[8];
911
-
912
- a[j + 9] = vertexArr[9];
913
- a[j + 10] = vertexArr[10];
914
- a[j + 11] = vertexArr[11];
915
- }
916
-
917
- this._changedBuffers[VERTEX_BUFFER] = true;
918
- }
919
-
920
- setAlignedAxisArr(index, alignedAxis) {
921
- var i = index * 18 * this._maxLetters;
922
- var a = this._alignedAxisArr,
923
- x = alignedAxis.x,
924
- y = alignedAxis.y,
925
- z = alignedAxis.z;
926
-
927
- for (var q = 0; q < this._maxLetters; q++) {
928
- var j = i + q * 18;
929
- a[j] = x;
930
- a[j + 1] = y;
931
- a[j + 2] = z;
932
-
933
- a[j + 3] = x;
934
- a[j + 4] = y;
935
- a[j + 5] = z;
936
-
937
- a[j + 6] = x;
938
- a[j + 7] = y;
939
- a[j + 8] = z;
940
-
941
- a[j + 9] = x;
942
- a[j + 10] = y;
943
- a[j + 11] = z;
944
-
945
- a[j + 12] = x;
946
- a[j + 13] = y;
947
- a[j + 14] = z;
948
-
949
- a[j + 15] = x;
950
- a[j + 16] = y;
951
- a[j + 17] = z;
952
- }
953
-
954
- this._changedBuffers[ALIGNEDAXIS_BUFFER] = true;
955
- }
956
-
957
- setFontIndexArr(index, fontIndex) {
958
- var i = index * 6 * this._maxLetters;
959
- var a = this._fontIndexArr;
960
-
961
- for (var q = 0; q < this._maxLetters; q++) {
962
- var j = i + q * 6;
963
- a[j] = fontIndex;
964
- a[j + 1] = fontIndex;
965
- a[j + 2] = fontIndex;
966
- a[j + 3] = fontIndex;
967
- a[j + 4] = fontIndex;
968
- a[j + 5] = fontIndex;
969
- }
970
-
971
- this._changedBuffers[FONTINDEX_BUFFER] = true;
972
- }
973
-
974
- createSizeBuffer() {
975
- var h = this._renderer.handler;
976
- h.gl.deleteBuffer(this._sizeBuffer);
977
- this._sizeBuffer = h.createArrayBuffer(this._sizeArr, 1, this._sizeArr.length);
978
- }
979
-
980
- createFontIndexBuffer() {
981
- var h = this._renderer.handler;
982
- h.gl.deleteBuffer(this._fontIndexBuffer);
983
- this._fontIndexBuffer = h.createArrayBuffer(
984
- this._fontIndexArr,
985
- 1,
986
- this._fontIndexArr.length
987
- );
988
- }
989
-
990
- createTexCoordBuffer() {
991
- var h = this._renderer.handler;
992
- h.gl.deleteBuffer(this._texCoordBuffer);
993
- this._texCoordBuffer = h.createArrayBuffer(
994
- this._texCoordArr,
995
- 4,
996
- this._texCoordArr.length / 4
997
- );
998
-
999
- h.gl.deleteBuffer(this._gliphParamBuffer);
1000
- this._gliphParamBuffer = h.createArrayBuffer(
1001
- this._gliphParamArr,
1002
- 4,
1003
- this._gliphParamArr.length / 4
1004
- );
1005
- }
1006
-
1007
- createOutlineBuffer() {
1008
- var h = this._renderer.handler;
1009
-
1010
- h.gl.deleteBuffer(this._outlineBuffer);
1011
- this._outlineBuffer = h.createArrayBuffer(this._outlineArr, 1, this._outlineArr.length);
1012
-
1013
- h.gl.deleteBuffer(this._noOutlineBuffer);
1014
- this._noOutlineBuffer = h.createArrayBuffer(
1015
- this._noOutlineArr,
1016
- 1,
1017
- this._noOutlineArr.length
1018
- );
1019
- }
1020
-
1021
- createOutlineColorBuffer() {
1022
- var h = this._renderer.handler;
1023
- h.gl.deleteBuffer(this._outlineColorBuffer);
1024
- this._outlineColorBuffer = h.createArrayBuffer(
1025
- this._outlineColorArr,
1026
- 4,
1027
- this._outlineColorArr.length / 4
1028
- );
1029
- }
1030
-
1031
- setMaxLetters(c) {
1032
- this._maxLetters = c;
1033
- // TODO: ...
1034
- }
1035
-
1036
- refreshTexCoordsArr() {
1037
- // it is empty
1038
- return null;
1039
- }
1040
- }
1041
-
359
+ label._isReady = false;
360
+ }
361
+
362
+ setText(index, text, fontIndex, align) {
363
+ var fa = this._renderer.fontAtlas.atlasesArr[fontIndex];
364
+
365
+ if (!fa) return;
366
+
367
+ let i = index * 24 * this._maxLetters;
368
+ let a = this._texCoordArr,
369
+ g = this._gliphParamArr;
370
+
371
+ let c = 0;
372
+
373
+ let n = fa.nodes[text[c]];
374
+ let offset = 0.0;
375
+ let len = Math.min(this._maxLetters, text.length);
376
+ let kern = fa.kernings;
377
+
378
+ for (c = 0; c < len; c++) {
379
+ let j = i + c * 24;
380
+ let char = text[c];
381
+ n = fa.nodes[char] || fa.nodes[" "];
382
+ let tc = n.texCoords;
383
+
384
+ let m = n.metrics;
385
+
386
+ a[j] = tc[0];
387
+ a[j + 1] = tc[1];
388
+ a[j + 2] = offset;
389
+ a[j + 3] = 0.0;
390
+
391
+ a[j + 4] = tc[2];
392
+ a[j + 5] = tc[3];
393
+ a[j + 6] = offset;
394
+ a[j + 7] = 0.0;
395
+
396
+ a[j + 8] = tc[4];
397
+ a[j + 9] = tc[5];
398
+ a[j + 10] = offset;
399
+ a[j + 11] = 0.0;
400
+
401
+ a[j + 12] = tc[6];
402
+ a[j + 13] = tc[7];
403
+ a[j + 14] = offset;
404
+ a[j + 15] = 0.0;
405
+
406
+ a[j + 16] = tc[8];
407
+ a[j + 17] = tc[9];
408
+ a[j + 18] = offset;
409
+ a[j + 19] = 0.0;
410
+
411
+ a[j + 20] = tc[10];
412
+ a[j + 21] = tc[11];
413
+ a[j + 22] = offset;
414
+ a[j + 23] = 0.0;
415
+
416
+ //
417
+ // Gliph
418
+ //
419
+ g[j] = m.nWidth;
420
+ g[j + 1] = m.nHeight;
421
+ g[j + 2] = m.nXOffset;
422
+ g[j + 3] = m.nYOffset;
423
+
424
+ g[j + 4] = m.nWidth;
425
+ g[j + 5] = m.nHeight;
426
+ g[j + 6] = m.nXOffset;
427
+ g[j + 7] = m.nYOffset;
428
+
429
+ g[j + 8] = m.nWidth;
430
+ g[j + 9] = m.nHeight;
431
+ g[j + 10] = m.nXOffset;
432
+ g[j + 11] = m.nYOffset;
433
+
434
+ g[j + 12] = m.nWidth;
435
+ g[j + 13] = m.nHeight;
436
+ g[j + 14] = m.nXOffset;
437
+ g[j + 15] = m.nYOffset;
438
+
439
+ g[j + 16] = m.nWidth;
440
+ g[j + 17] = m.nHeight;
441
+ g[j + 18] = m.nXOffset;
442
+ g[j + 19] = m.nYOffset;
443
+
444
+ g[j + 20] = m.nWidth;
445
+ g[j + 21] = m.nHeight;
446
+ g[j + 22] = m.nXOffset;
447
+ g[j + 23] = m.nYOffset;
448
+
449
+ let k = kern[char];
450
+ if (k) {
451
+ k = k[text[c + 1]];
452
+ if (k) {
453
+ offset += m.nAdvance + k;
454
+ } else {
455
+ offset += m.nAdvance;
456
+ }
457
+ } else {
458
+ offset += m.nAdvance;
459
+ }
460
+ }
461
+
462
+ // 49/512 - font atlas left border letter offset
463
+ if (align === ALIGN.CENTER) {
464
+ offset *= -0.5;
465
+ for (c = 0; c < len; c++) {
466
+ let j = i + c * 24;
467
+ a[j + 3] = offset;
468
+ a[j + 7] = offset;
469
+ a[j + 11] = offset;
470
+ a[j + 15] = offset;
471
+ a[j + 19] = offset;
472
+ a[j + 23] = offset;
473
+ }
474
+ } else if (align === ALIGN.LEFT) {
475
+ for (c = 0; c < len; c++) {
476
+ let j = i + c * 24;
477
+ a[j + 3] = 0;
478
+ a[j + 7] = 0;
479
+ a[j + 11] = 0;
480
+ a[j + 15] = 0;
481
+ a[j + 19] = 0;
482
+ a[j + 23] = 0;
483
+ }
484
+ }
485
+
486
+ for (; c < this._maxLetters; c++) {
487
+ let j = i + c * 24;
488
+ a[j + 2] = -1.0;
489
+ a[j + 6] = -1.0;
490
+ a[j + 10] = -1.0;
491
+ a[j + 14] = -1.0;
492
+ a[j + 18] = -1.0;
493
+ a[j + 17] = -1.0;
494
+ }
495
+
496
+ this._changedBuffers[TEXCOORD_BUFFER] = true;
497
+ }
498
+
499
+ setPositionArr(index, positionHigh, positionLow) {
500
+ var i = index * 18 * this._maxLetters;
501
+ var a = this._positionHighArr,
502
+ x = positionHigh.x,
503
+ y = positionHigh.y,
504
+ z = positionHigh.z,
505
+ b = this._positionLowArr,
506
+ xl = positionLow.x,
507
+ yl = positionLow.y,
508
+ zl = positionLow.z;
509
+
510
+ for (var q = 0; q < this._maxLetters; q++) {
511
+ var j = i + q * 18;
512
+ a[j] = x;
513
+ a[j + 1] = y;
514
+ a[j + 2] = z;
515
+
516
+ a[j + 3] = x;
517
+ a[j + 4] = y;
518
+ a[j + 5] = z;
519
+
520
+ a[j + 6] = x;
521
+ a[j + 7] = y;
522
+ a[j + 8] = z;
523
+
524
+ a[j + 9] = x;
525
+ a[j + 10] = y;
526
+ a[j + 11] = z;
527
+
528
+ a[j + 12] = x;
529
+ a[j + 13] = y;
530
+ a[j + 14] = z;
531
+
532
+ a[j + 15] = x;
533
+ a[j + 16] = y;
534
+ a[j + 17] = z;
535
+
536
+ // low
537
+ b[j] = xl;
538
+ b[j + 1] = yl;
539
+ b[j + 2] = zl;
540
+
541
+ b[j + 3] = xl;
542
+ b[j + 4] = yl;
543
+ b[j + 5] = zl;
544
+
545
+ b[j + 6] = xl;
546
+ b[j + 7] = yl;
547
+ b[j + 8] = zl;
548
+
549
+ b[j + 9] = xl;
550
+ b[j + 10] = yl;
551
+ b[j + 11] = zl;
552
+
553
+ b[j + 12] = xl;
554
+ b[j + 13] = yl;
555
+ b[j + 14] = zl;
556
+
557
+ b[j + 15] = xl;
558
+ b[j + 16] = yl;
559
+ b[j + 17] = zl;
560
+ }
561
+
562
+ this._changedBuffers[POSITION_BUFFER] = true;
563
+ }
564
+
565
+ setPickingColorArr(index, color) {
566
+ var i = index * 18 * this._maxLetters;
567
+ var a = this._pickingColorArr,
568
+ x = color.x / 255,
569
+ y = color.y / 255,
570
+ z = color.z / 255;
571
+
572
+ for (var q = 0; q < this._maxLetters; q++) {
573
+ var j = i + q * 18;
574
+ a[j] = x;
575
+ a[j + 1] = y;
576
+ a[j + 2] = z;
577
+
578
+ a[j + 3] = x;
579
+ a[j + 4] = y;
580
+ a[j + 5] = z;
581
+
582
+ a[j + 6] = x;
583
+ a[j + 7] = y;
584
+ a[j + 8] = z;
585
+
586
+ a[j + 9] = x;
587
+ a[j + 10] = y;
588
+ a[j + 11] = z;
589
+
590
+ a[j + 12] = x;
591
+ a[j + 13] = y;
592
+ a[j + 14] = z;
593
+
594
+ a[j + 15] = x;
595
+ a[j + 16] = y;
596
+ a[j + 17] = z;
597
+ }
598
+
599
+ this._changedBuffers[PICKINGCOLOR_BUFFER] = true;
600
+ }
601
+
602
+ setSizeArr(index, size) {
603
+ var i = index * 6 * this._maxLetters;
604
+ var a = this._sizeArr;
605
+
606
+ for (var q = 0; q < this._maxLetters; q++) {
607
+ var j = i + q * 6;
608
+ a[j] = size;
609
+ a[j + 1] = size;
610
+ a[j + 2] = size;
611
+ a[j + 3] = size;
612
+ a[j + 4] = size;
613
+ a[j + 5] = size;
614
+ }
615
+
616
+ this._changedBuffers[SIZE_BUFFER] = true;
617
+ }
618
+
619
+ setOffsetArr(index, offset) {
620
+ var i = index * 18 * this._maxLetters;
621
+ var a = this._offsetArr,
622
+ x = offset.x,
623
+ y = offset.y,
624
+ z = offset.z;
625
+
626
+ for (var q = 0; q < this._maxLetters; q++) {
627
+ var j = i + q * 18;
628
+ a[j] = x;
629
+ a[j + 1] = y;
630
+ a[j + 2] = z;
631
+
632
+ a[j + 3] = x;
633
+ a[j + 4] = y;
634
+ a[j + 5] = z;
635
+
636
+ a[j + 6] = x;
637
+ a[j + 7] = y;
638
+ a[j + 8] = z;
639
+
640
+ a[j + 9] = x;
641
+ a[j + 10] = y;
642
+ a[j + 11] = z;
643
+
644
+ a[j + 12] = x;
645
+ a[j + 13] = y;
646
+ a[j + 14] = z;
647
+
648
+ a[j + 15] = x;
649
+ a[j + 16] = y;
650
+ a[j + 17] = z;
651
+ }
652
+
653
+ this._changedBuffers[OFFSET_BUFFER] = true;
654
+ }
655
+
656
+ setRgbaArr(index, rgba) {
657
+ var i = index * 24 * this._maxLetters;
658
+ var a = this._rgbaArr,
659
+ x = rgba.x,
660
+ y = rgba.y,
661
+ z = rgba.z,
662
+ w = rgba.w;
663
+
664
+ for (var q = 0; q < this._maxLetters; q++) {
665
+ var j = i + q * 24;
666
+
667
+ a[j] = x;
668
+ a[j + 1] = y;
669
+ a[j + 2] = z;
670
+ a[j + 3] = w;
671
+
672
+ a[j + 4] = x;
673
+ a[j + 5] = y;
674
+ a[j + 6] = z;
675
+ a[j + 7] = w;
676
+
677
+ a[j + 8] = x;
678
+ a[j + 9] = y;
679
+ a[j + 10] = z;
680
+ a[j + 11] = w;
681
+
682
+ a[j + 12] = x;
683
+ a[j + 13] = y;
684
+ a[j + 14] = z;
685
+ a[j + 15] = w;
686
+
687
+ a[j + 16] = x;
688
+ a[j + 17] = y;
689
+ a[j + 18] = z;
690
+ a[j + 19] = w;
691
+
692
+ a[j + 20] = x;
693
+ a[j + 21] = y;
694
+ a[j + 22] = z;
695
+ a[j + 23] = w;
696
+ }
697
+
698
+ this._changedBuffers[RGBA_BUFFER] = true;
699
+ }
700
+
701
+ setOutlineColorArr(index, rgba) {
702
+ var i = index * 24 * this._maxLetters;
703
+ var a = this._outlineColorArr,
704
+ x = rgba.x,
705
+ y = rgba.y,
706
+ z = rgba.z,
707
+ w = rgba.w;
708
+
709
+ for (var q = 0; q < this._maxLetters; q++) {
710
+ var j = i + q * 24;
711
+
712
+ a[j] = x;
713
+ a[j + 1] = y;
714
+ a[j + 2] = z;
715
+ a[j + 3] = w;
716
+
717
+ a[j + 4] = x;
718
+ a[j + 5] = y;
719
+ a[j + 6] = z;
720
+ a[j + 7] = w;
721
+
722
+ a[j + 8] = x;
723
+ a[j + 9] = y;
724
+ a[j + 10] = z;
725
+ a[j + 11] = w;
726
+
727
+ a[j + 12] = x;
728
+ a[j + 13] = y;
729
+ a[j + 14] = z;
730
+ a[j + 15] = w;
731
+
732
+ a[j + 16] = x;
733
+ a[j + 17] = y;
734
+ a[j + 18] = z;
735
+ a[j + 19] = w;
736
+
737
+ a[j + 20] = x;
738
+ a[j + 21] = y;
739
+ a[j + 22] = z;
740
+ a[j + 23] = w;
741
+ }
742
+
743
+ this._changedBuffers[OUTLINECOLOR_BUFFER] = true;
744
+ }
745
+
746
+ setOutlineArr(index, outline) {
747
+ var i = index * 6 * this._maxLetters;
748
+ var a = this._outlineArr;
749
+
750
+ for (var q = 0; q < this._maxLetters; q++) {
751
+ var j = i + q * 6;
752
+ a[j] = outline;
753
+ a[j + 1] = outline;
754
+ a[j + 2] = outline;
755
+ a[j + 3] = outline;
756
+ a[j + 4] = outline;
757
+ a[j + 5] = outline;
758
+ }
759
+
760
+ this._changedBuffers[OUTLINE_BUFFER] = true;
761
+ }
762
+
763
+ setRotationArr(index, rotation) {
764
+ var i = index * 6 * this._maxLetters;
765
+ var a = this._rotationArr;
766
+
767
+ for (var q = 0; q < this._maxLetters; q++) {
768
+ var j = i + q * 6;
769
+ a[j] = rotation;
770
+ a[j + 1] = rotation;
771
+ a[j + 2] = rotation;
772
+ a[j + 3] = rotation;
773
+ a[j + 4] = rotation;
774
+ a[j + 5] = rotation;
775
+ }
776
+
777
+ this._changedBuffers[ROTATION_BUFFER] = true;
778
+ }
779
+
780
+ setVisibility(index, visibility) {
781
+ var vArr;
782
+ if (visibility) {
783
+ vArr = [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0];
784
+ } else {
785
+ vArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
786
+ }
787
+ this.setVertexArr(index, vArr);
788
+ }
789
+
790
+ setVertexArr(index, vertexArr) {
791
+ var i = index * 12 * this._maxLetters;
792
+ var a = this._vertexArr;
793
+
794
+ for (var q = 0; q < this._maxLetters; q++) {
795
+ var j = i + q * 12;
796
+ a[j] = vertexArr[0];
797
+ a[j + 1] = vertexArr[1];
798
+ a[j + 2] = vertexArr[2];
799
+
800
+ a[j + 3] = vertexArr[3];
801
+ a[j + 4] = vertexArr[4];
802
+ a[j + 5] = vertexArr[5];
803
+
804
+ a[j + 6] = vertexArr[6];
805
+ a[j + 7] = vertexArr[7];
806
+ a[j + 8] = vertexArr[8];
807
+
808
+ a[j + 9] = vertexArr[9];
809
+ a[j + 10] = vertexArr[10];
810
+ a[j + 11] = vertexArr[11];
811
+ }
812
+
813
+ this._changedBuffers[VERTEX_BUFFER] = true;
814
+ }
815
+
816
+ setFontIndexArr(index, fontIndex) {
817
+ var i = index * 6 * this._maxLetters;
818
+ var a = this._fontIndexArr;
819
+
820
+ for (var q = 0; q < this._maxLetters; q++) {
821
+ var j = i + q * 6;
822
+ a[j] = fontIndex;
823
+ a[j + 1] = fontIndex;
824
+ a[j + 2] = fontIndex;
825
+ a[j + 3] = fontIndex;
826
+ a[j + 4] = fontIndex;
827
+ a[j + 5] = fontIndex;
828
+ }
829
+
830
+ this._changedBuffers[FONTINDEX_BUFFER] = true;
831
+ }
832
+
833
+ createSizeBuffer() {
834
+ var h = this._renderer.handler;
835
+ h.gl.deleteBuffer(this._sizeBuffer);
836
+ this._sizeBuffer = h.createArrayBuffer(this._sizeArr, 1, this._sizeArr.length);
837
+ }
838
+
839
+ createFontIndexBuffer() {
840
+ var h = this._renderer.handler;
841
+ h.gl.deleteBuffer(this._fontIndexBuffer);
842
+ this._fontIndexBuffer = h.createArrayBuffer(
843
+ this._fontIndexArr,
844
+ 1,
845
+ this._fontIndexArr.length
846
+ );
847
+ }
848
+
849
+ createTexCoordBuffer() {
850
+ var h = this._renderer.handler;
851
+ h.gl.deleteBuffer(this._texCoordBuffer);
852
+ this._texCoordBuffer = h.createArrayBuffer(
853
+ this._texCoordArr,
854
+ 4,
855
+ this._texCoordArr.length / 4
856
+ );
857
+
858
+ h.gl.deleteBuffer(this._gliphParamBuffer);
859
+ this._gliphParamBuffer = h.createArrayBuffer(
860
+ this._gliphParamArr,
861
+ 4,
862
+ this._gliphParamArr.length / 4
863
+ );
864
+ }
865
+
866
+ createOutlineBuffer() {
867
+ var h = this._renderer.handler;
868
+ h.gl.deleteBuffer(this._outlineBuffer);
869
+ this._outlineBuffer = h.createArrayBuffer(this._outlineArr, 1, this._outlineArr.length);
870
+ }
871
+
872
+ createOutlineColorBuffer() {
873
+ var h = this._renderer.handler;
874
+ h.gl.deleteBuffer(this._outlineColorBuffer);
875
+ this._outlineColorBuffer = h.createArrayBuffer(this._outlineColorArr, 4, this._outlineColorArr.length / 4);
876
+ }
877
+
878
+ setMaxLetters(c) {
879
+ this._maxLetters = c;
880
+ // TODO: ...
881
+ }
882
+
883
+ refreshTexCoordsArr() {
884
+ // it is empty
885
+ return null;
886
+ }
887
+ }
888
+
1042
889
  export { LabelHandler };