@openglobus/og 0.12.3 → 0.13.1

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 +888 -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 +804 -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 +603 -603
  56. package/src/og/shaders/label.js +595 -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 +5 -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,890 @@
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
+ gl.depthFunc(gl.EQUAL);
256
+
257
+ //
258
+ // no outline PASS
259
+ gl.uniform1i(shu.isOutlinePass, 0);
260
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
261
+
262
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rgbaBuffer);
263
+ gl.vertexAttribPointer(sha.a_rgba, this._rgbaBuffer.itemSize, gl.FLOAT, false, 0, 0);
264
+
265
+ gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
266
+
267
+ gl.depthFunc(gl.LESS);
268
+ }
269
+
270
+ _pickingPASS() {
271
+ var r = this._renderer;
272
+ var h = r.handler;
273
+ h.programs.labelPicking.activate();
274
+ var sh = h.programs.labelPicking._program;
275
+ var sha = sh.attributes,
276
+ shu = sh.uniforms;
277
+
278
+ var gl = h.gl,
279
+ ec = this._entityCollection;
280
+
281
+ var rn = ec.renderNode;
282
+
283
+ gl.uniformMatrix4fv(shu.viewMatrix, false, r.activeCamera._viewMatrix._m);
284
+ gl.uniformMatrix4fv(shu.projectionMatrix, false, r.activeCamera.getProjectionMatrix());
285
+ gl.uniform3fv(shu.eyePositionHigh, r.activeCamera.eyeHigh);
286
+ gl.uniform3fv(shu.eyePositionLow, r.activeCamera.eyeLow);
287
+ gl.uniform3fv(shu.scaleByDistance, ec.scaleByDistance);
288
+ gl.uniform1f(shu.opacity, ec._fadingOpacity);
289
+ gl.uniform1f(shu.planetRadius, rn._planetRadius2 || 0);
290
+ gl.uniform2fv(shu.viewport, [h.canvas.clientWidth, h.canvas.clientHeight]);
291
+
292
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._texCoordBuffer);
293
+ gl.vertexAttribPointer(sha.a_texCoord, this._texCoordBuffer.itemSize, gl.FLOAT, false, 0, 0);
294
+
295
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._gliphParamBuffer);
296
+ gl.vertexAttribPointer(sha.a_gliphParam, this._gliphParamBuffer.itemSize, gl.FLOAT, false, 0, 0);
297
+
298
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._vertexBuffer);
299
+ gl.vertexAttribPointer(sha.a_vertices, this._vertexBuffer.itemSize, gl.FLOAT, false, 0, 0);
300
+
301
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionHighBuffer);
302
+ gl.vertexAttribPointer(sha.a_positionsHigh, this._positionHighBuffer.itemSize, gl.FLOAT, false, 0, 0);
303
+
304
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._positionLowBuffer);
305
+ gl.vertexAttribPointer(sha.a_positionsLow, this._positionLowBuffer.itemSize, gl.FLOAT, false, 0, 0);
306
+
307
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._sizeBuffer);
308
+ gl.vertexAttribPointer(sha.a_size, this._sizeBuffer.itemSize, gl.FLOAT, false, 0, 0);
309
+
310
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._rotationBuffer);
311
+ gl.vertexAttribPointer(sha.a_rotation, this._rotationBuffer.itemSize, gl.FLOAT, false, 0, 0);
312
+
313
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._offsetBuffer);
314
+ gl.vertexAttribPointer(sha.a_offset, this._offsetBuffer.itemSize, gl.FLOAT, false, 0, 0);
315
+
316
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._pickingColorBuffer);
317
+ gl.vertexAttribPointer(sha.a_rgba, this._pickingColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
318
+
319
+ gl.uniform1f(shu.depthOffset, ec.polygonOffsetUnits + window.LABEL_DEPTH_OFFSET);
320
+
321
+
322
+ gl.drawArrays(gl.TRIANGLES, 0, this._vertexBuffer.numItems);
323
+ }
324
+
325
+ _removeBillboard(label) {
326
+ var li = label._handlerIndex;
327
+
328
+ this._billboards.splice(li, 1);
329
+
330
+ var ml = 24 * this._maxLetters;
331
+ var i = li * ml;
332
+ this._rgbaArr = spliceTypedArray(this._rgbaArr, i, ml);
333
+ this._outlineColorArr = spliceTypedArray(this._outlineColorArr, i, ml);
334
+ this._texCoordArr = spliceTypedArray(this._texCoordArr, i, ml);
335
+ this._gliphParamArr = spliceTypedArray(this._gliphParamArr, i, ml);
336
+
337
+ ml = 18 * this._maxLetters;
338
+ i = li * ml;
339
+ this._positionHighArr = spliceTypedArray(this._positionHighArr, i, ml);
340
+ this._positionLowArr = spliceTypedArray(this._positionLowArr, i, ml);
341
+ this._offsetArr = spliceTypedArray(this._offsetArr, i, ml);
342
+ this._pickingColorArr = spliceTypedArray(this._pickingColorArr, i, ml);
343
+
344
+ ml = 12 * this._maxLetters;
345
+ i = li * ml;
346
+ this._vertexArr = spliceTypedArray(this._vertexArr, i, ml);
347
+
348
+ ml = 6 * this._maxLetters;
349
+ i = li * ml;
350
+ this._sizeArr = spliceTypedArray(this._sizeArr, i, ml);
351
+ this._rotationArr = spliceTypedArray(this._rotationArr, i, ml);
352
+ this._fontIndexArr = spliceTypedArray(this._fontIndexArr, i, ml);
353
+ this._outlineArr = spliceTypedArray(this._outlineArr, i, ml);
354
+
355
+ this.reindexBillbordsArray(li);
356
+ this.refresh();
357
+
358
+ label._handlerIndex = -1;
472
359
  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
-
360
+ label._isReady = false;
361
+ }
362
+
363
+ setText(index, text, fontIndex, align) {
364
+ var fa = this._renderer.fontAtlas.atlasesArr[fontIndex];
365
+
366
+ if (!fa) return;
367
+
368
+ let i = index * 24 * this._maxLetters;
369
+ let a = this._texCoordArr,
370
+ g = this._gliphParamArr;
371
+
372
+ let c = 0;
373
+
374
+ let n = fa.nodes[text[c]];
375
+ let offset = 0.0;
376
+ let len = Math.min(this._maxLetters, text.length);
377
+ let kern = fa.kernings;
378
+
379
+ for (c = 0; c < len; c++) {
380
+ let j = i + c * 24;
381
+ let char = text[c];
382
+ n = fa.nodes[char] || fa.nodes[" "];
383
+ let tc = n.texCoords;
384
+
385
+ let m = n.metrics;
386
+
387
+ a[j] = tc[0];
388
+ a[j + 1] = tc[1];
389
+ a[j + 2] = offset;
390
+ a[j + 3] = 0.0;
391
+
392
+ a[j + 4] = tc[2];
393
+ a[j + 5] = tc[3];
394
+ a[j + 6] = offset;
395
+ a[j + 7] = 0.0;
396
+
397
+ a[j + 8] = tc[4];
398
+ a[j + 9] = tc[5];
399
+ a[j + 10] = offset;
400
+ a[j + 11] = 0.0;
401
+
402
+ a[j + 12] = tc[6];
403
+ a[j + 13] = tc[7];
404
+ a[j + 14] = offset;
405
+ a[j + 15] = 0.0;
406
+
407
+ a[j + 16] = tc[8];
408
+ a[j + 17] = tc[9];
409
+ a[j + 18] = offset;
410
+ a[j + 19] = 0.0;
411
+
412
+ a[j + 20] = tc[10];
413
+ a[j + 21] = tc[11];
414
+ a[j + 22] = offset;
415
+ a[j + 23] = 0.0;
416
+
417
+ //
418
+ // Gliph
419
+ //
420
+ g[j] = m.nWidth;
421
+ g[j + 1] = m.nHeight;
422
+ g[j + 2] = m.nXOffset;
423
+ g[j + 3] = m.nYOffset;
424
+
425
+ g[j + 4] = m.nWidth;
426
+ g[j + 5] = m.nHeight;
427
+ g[j + 6] = m.nXOffset;
428
+ g[j + 7] = m.nYOffset;
429
+
430
+ g[j + 8] = m.nWidth;
431
+ g[j + 9] = m.nHeight;
432
+ g[j + 10] = m.nXOffset;
433
+ g[j + 11] = m.nYOffset;
434
+
435
+ g[j + 12] = m.nWidth;
436
+ g[j + 13] = m.nHeight;
437
+ g[j + 14] = m.nXOffset;
438
+ g[j + 15] = m.nYOffset;
439
+
440
+ g[j + 16] = m.nWidth;
441
+ g[j + 17] = m.nHeight;
442
+ g[j + 18] = m.nXOffset;
443
+ g[j + 19] = m.nYOffset;
444
+
445
+ g[j + 20] = m.nWidth;
446
+ g[j + 21] = m.nHeight;
447
+ g[j + 22] = m.nXOffset;
448
+ g[j + 23] = m.nYOffset;
449
+
450
+ let k = kern[char];
451
+ if (k) {
452
+ k = k[text[c + 1]];
453
+ if (k) {
454
+ offset += m.nAdvance + k;
455
+ } else {
456
+ offset += m.nAdvance;
457
+ }
458
+ } else {
459
+ offset += m.nAdvance;
460
+ }
461
+ }
462
+
463
+ // 49/512 - font atlas left border letter offset
464
+ if (align === ALIGN.CENTER) {
465
+ offset *= -0.5;
466
+ for (c = 0; c < len; c++) {
467
+ let j = i + c * 24;
468
+ a[j + 3] = offset;
469
+ a[j + 7] = offset;
470
+ a[j + 11] = offset;
471
+ a[j + 15] = offset;
472
+ a[j + 19] = offset;
473
+ a[j + 23] = offset;
474
+ }
475
+ } else if (align === ALIGN.LEFT) {
476
+ for (c = 0; c < len; c++) {
477
+ let j = i + c * 24;
478
+ a[j + 3] = 0;
479
+ a[j + 7] = 0;
480
+ a[j + 11] = 0;
481
+ a[j + 15] = 0;
482
+ a[j + 19] = 0;
483
+ a[j + 23] = 0;
484
+ }
485
+ }
486
+
487
+ for (; c < this._maxLetters; c++) {
488
+ let j = i + c * 24;
489
+ a[j + 2] = -1.0;
490
+ a[j + 6] = -1.0;
491
+ a[j + 10] = -1.0;
492
+ a[j + 14] = -1.0;
493
+ a[j + 18] = -1.0;
494
+ a[j + 17] = -1.0;
495
+ }
496
+
497
+ this._changedBuffers[TEXCOORD_BUFFER] = true;
498
+ }
499
+
500
+ setPositionArr(index, positionHigh, positionLow) {
501
+ var i = index * 18 * this._maxLetters;
502
+ var a = this._positionHighArr,
503
+ x = positionHigh.x,
504
+ y = positionHigh.y,
505
+ z = positionHigh.z,
506
+ b = this._positionLowArr,
507
+ xl = positionLow.x,
508
+ yl = positionLow.y,
509
+ zl = positionLow.z;
510
+
511
+ for (var q = 0; q < this._maxLetters; q++) {
512
+ var j = i + q * 18;
513
+ a[j] = x;
514
+ a[j + 1] = y;
515
+ a[j + 2] = z;
516
+
517
+ a[j + 3] = x;
518
+ a[j + 4] = y;
519
+ a[j + 5] = z;
520
+
521
+ a[j + 6] = x;
522
+ a[j + 7] = y;
523
+ a[j + 8] = z;
524
+
525
+ a[j + 9] = x;
526
+ a[j + 10] = y;
527
+ a[j + 11] = z;
528
+
529
+ a[j + 12] = x;
530
+ a[j + 13] = y;
531
+ a[j + 14] = z;
532
+
533
+ a[j + 15] = x;
534
+ a[j + 16] = y;
535
+ a[j + 17] = z;
536
+
537
+ // low
538
+ b[j] = xl;
539
+ b[j + 1] = yl;
540
+ b[j + 2] = zl;
541
+
542
+ b[j + 3] = xl;
543
+ b[j + 4] = yl;
544
+ b[j + 5] = zl;
545
+
546
+ b[j + 6] = xl;
547
+ b[j + 7] = yl;
548
+ b[j + 8] = zl;
549
+
550
+ b[j + 9] = xl;
551
+ b[j + 10] = yl;
552
+ b[j + 11] = zl;
553
+
554
+ b[j + 12] = xl;
555
+ b[j + 13] = yl;
556
+ b[j + 14] = zl;
557
+
558
+ b[j + 15] = xl;
559
+ b[j + 16] = yl;
560
+ b[j + 17] = zl;
561
+ }
562
+
563
+ this._changedBuffers[POSITION_BUFFER] = true;
564
+ }
565
+
566
+ setPickingColorArr(index, color) {
567
+ var i = index * 18 * this._maxLetters;
568
+ var a = this._pickingColorArr,
569
+ x = color.x / 255,
570
+ y = color.y / 255,
571
+ z = color.z / 255;
572
+
573
+ for (var q = 0; q < this._maxLetters; q++) {
574
+ var j = i + q * 18;
575
+ a[j] = x;
576
+ a[j + 1] = y;
577
+ a[j + 2] = z;
578
+
579
+ a[j + 3] = x;
580
+ a[j + 4] = y;
581
+ a[j + 5] = z;
582
+
583
+ a[j + 6] = x;
584
+ a[j + 7] = y;
585
+ a[j + 8] = z;
586
+
587
+ a[j + 9] = x;
588
+ a[j + 10] = y;
589
+ a[j + 11] = z;
590
+
591
+ a[j + 12] = x;
592
+ a[j + 13] = y;
593
+ a[j + 14] = z;
594
+
595
+ a[j + 15] = x;
596
+ a[j + 16] = y;
597
+ a[j + 17] = z;
598
+ }
599
+
600
+ this._changedBuffers[PICKINGCOLOR_BUFFER] = true;
601
+ }
602
+
603
+ setSizeArr(index, size) {
604
+ var i = index * 6 * this._maxLetters;
605
+ var a = this._sizeArr;
606
+
607
+ for (var q = 0; q < this._maxLetters; q++) {
608
+ var j = i + q * 6;
609
+ a[j] = size;
610
+ a[j + 1] = size;
611
+ a[j + 2] = size;
612
+ a[j + 3] = size;
613
+ a[j + 4] = size;
614
+ a[j + 5] = size;
615
+ }
616
+
617
+ this._changedBuffers[SIZE_BUFFER] = true;
618
+ }
619
+
620
+ setOffsetArr(index, offset) {
621
+ var i = index * 18 * this._maxLetters;
622
+ var a = this._offsetArr,
623
+ x = offset.x,
624
+ y = offset.y,
625
+ z = offset.z;
626
+
627
+ for (var q = 0; q < this._maxLetters; q++) {
628
+ var j = i + q * 18;
629
+ a[j] = x;
630
+ a[j + 1] = y;
631
+ a[j + 2] = z;
632
+
633
+ a[j + 3] = x;
634
+ a[j + 4] = y;
635
+ a[j + 5] = z;
636
+
637
+ a[j + 6] = x;
638
+ a[j + 7] = y;
639
+ a[j + 8] = z;
640
+
641
+ a[j + 9] = x;
642
+ a[j + 10] = y;
643
+ a[j + 11] = z;
644
+
645
+ a[j + 12] = x;
646
+ a[j + 13] = y;
647
+ a[j + 14] = z;
648
+
649
+ a[j + 15] = x;
650
+ a[j + 16] = y;
651
+ a[j + 17] = z;
652
+ }
653
+
654
+ this._changedBuffers[OFFSET_BUFFER] = true;
655
+ }
656
+
657
+ setRgbaArr(index, rgba) {
658
+ var i = index * 24 * this._maxLetters;
659
+ var a = this._rgbaArr,
660
+ x = rgba.x,
661
+ y = rgba.y,
662
+ z = rgba.z,
663
+ w = rgba.w;
664
+
665
+ for (var q = 0; q < this._maxLetters; q++) {
666
+ var j = i + q * 24;
667
+
668
+ a[j] = x;
669
+ a[j + 1] = y;
670
+ a[j + 2] = z;
671
+ a[j + 3] = w;
672
+
673
+ a[j + 4] = x;
674
+ a[j + 5] = y;
675
+ a[j + 6] = z;
676
+ a[j + 7] = w;
677
+
678
+ a[j + 8] = x;
679
+ a[j + 9] = y;
680
+ a[j + 10] = z;
681
+ a[j + 11] = w;
682
+
683
+ a[j + 12] = x;
684
+ a[j + 13] = y;
685
+ a[j + 14] = z;
686
+ a[j + 15] = w;
687
+
688
+ a[j + 16] = x;
689
+ a[j + 17] = y;
690
+ a[j + 18] = z;
691
+ a[j + 19] = w;
692
+
693
+ a[j + 20] = x;
694
+ a[j + 21] = y;
695
+ a[j + 22] = z;
696
+ a[j + 23] = w;
697
+ }
698
+
699
+ this._changedBuffers[RGBA_BUFFER] = true;
700
+ }
701
+
702
+ setOutlineColorArr(index, rgba) {
703
+ var i = index * 24 * this._maxLetters;
704
+ var a = this._outlineColorArr,
705
+ x = rgba.x,
706
+ y = rgba.y,
707
+ z = rgba.z,
708
+ w = rgba.w;
709
+
710
+ for (var q = 0; q < this._maxLetters; q++) {
711
+ var j = i + q * 24;
712
+
713
+ a[j] = x;
714
+ a[j + 1] = y;
715
+ a[j + 2] = z;
716
+ a[j + 3] = w;
717
+
718
+ a[j + 4] = x;
719
+ a[j + 5] = y;
720
+ a[j + 6] = z;
721
+ a[j + 7] = w;
722
+
723
+ a[j + 8] = x;
724
+ a[j + 9] = y;
725
+ a[j + 10] = z;
726
+ a[j + 11] = w;
727
+
728
+ a[j + 12] = x;
729
+ a[j + 13] = y;
730
+ a[j + 14] = z;
731
+ a[j + 15] = w;
732
+
733
+ a[j + 16] = x;
734
+ a[j + 17] = y;
735
+ a[j + 18] = z;
736
+ a[j + 19] = w;
737
+
738
+ a[j + 20] = x;
739
+ a[j + 21] = y;
740
+ a[j + 22] = z;
741
+ a[j + 23] = w;
742
+ }
743
+
744
+ this._changedBuffers[OUTLINECOLOR_BUFFER] = true;
745
+ }
746
+
747
+ setOutlineArr(index, outline) {
748
+ var i = index * 6 * this._maxLetters;
749
+ var a = this._outlineArr;
750
+
751
+ for (var q = 0; q < this._maxLetters; q++) {
752
+ var j = i + q * 6;
753
+ a[j] = outline;
754
+ a[j + 1] = outline;
755
+ a[j + 2] = outline;
756
+ a[j + 3] = outline;
757
+ a[j + 4] = outline;
758
+ a[j + 5] = outline;
759
+ }
760
+
761
+ this._changedBuffers[OUTLINE_BUFFER] = true;
762
+ }
763
+
764
+ setRotationArr(index, rotation) {
765
+ var i = index * 6 * this._maxLetters;
766
+ var a = this._rotationArr;
767
+
768
+ for (var q = 0; q < this._maxLetters; q++) {
769
+ var j = i + q * 6;
770
+ a[j] = rotation;
771
+ a[j + 1] = rotation;
772
+ a[j + 2] = rotation;
773
+ a[j + 3] = rotation;
774
+ a[j + 4] = rotation;
775
+ a[j + 5] = rotation;
776
+ }
777
+
778
+ this._changedBuffers[ROTATION_BUFFER] = true;
779
+ }
780
+
781
+ setVisibility(index, visibility) {
782
+ var vArr;
783
+ if (visibility) {
784
+ vArr = [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0];
785
+ } else {
786
+ vArr = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
787
+ }
788
+ this.setVertexArr(index, vArr);
789
+ }
790
+
791
+ setVertexArr(index, vertexArr) {
792
+ var i = index * 12 * this._maxLetters;
793
+ var a = this._vertexArr;
794
+
795
+ for (var q = 0; q < this._maxLetters; q++) {
796
+ var j = i + q * 12;
797
+ a[j] = vertexArr[0];
798
+ a[j + 1] = vertexArr[1];
799
+ a[j + 2] = vertexArr[2];
800
+
801
+ a[j + 3] = vertexArr[3];
802
+ a[j + 4] = vertexArr[4];
803
+ a[j + 5] = vertexArr[5];
804
+
805
+ a[j + 6] = vertexArr[6];
806
+ a[j + 7] = vertexArr[7];
807
+ a[j + 8] = vertexArr[8];
808
+
809
+ a[j + 9] = vertexArr[9];
810
+ a[j + 10] = vertexArr[10];
811
+ a[j + 11] = vertexArr[11];
812
+ }
813
+
814
+ this._changedBuffers[VERTEX_BUFFER] = true;
815
+ }
816
+
817
+ setFontIndexArr(index, fontIndex) {
818
+ var i = index * 6 * this._maxLetters;
819
+ var a = this._fontIndexArr;
820
+
821
+ for (var q = 0; q < this._maxLetters; q++) {
822
+ var j = i + q * 6;
823
+ a[j] = fontIndex;
824
+ a[j + 1] = fontIndex;
825
+ a[j + 2] = fontIndex;
826
+ a[j + 3] = fontIndex;
827
+ a[j + 4] = fontIndex;
828
+ a[j + 5] = fontIndex;
829
+ }
830
+
831
+ this._changedBuffers[FONTINDEX_BUFFER] = true;
832
+ }
833
+
834
+ createSizeBuffer() {
835
+ var h = this._renderer.handler;
836
+ h.gl.deleteBuffer(this._sizeBuffer);
837
+ this._sizeBuffer = h.createArrayBuffer(this._sizeArr, 1, this._sizeArr.length);
838
+ }
839
+
840
+ createFontIndexBuffer() {
841
+ var h = this._renderer.handler;
842
+ h.gl.deleteBuffer(this._fontIndexBuffer);
843
+ this._fontIndexBuffer = h.createArrayBuffer(
844
+ this._fontIndexArr,
845
+ 1,
846
+ this._fontIndexArr.length
847
+ );
848
+ }
849
+
850
+ createTexCoordBuffer() {
851
+ var h = this._renderer.handler;
852
+ h.gl.deleteBuffer(this._texCoordBuffer);
853
+ this._texCoordBuffer = h.createArrayBuffer(
854
+ this._texCoordArr,
855
+ 4,
856
+ this._texCoordArr.length / 4
857
+ );
858
+
859
+ h.gl.deleteBuffer(this._gliphParamBuffer);
860
+ this._gliphParamBuffer = h.createArrayBuffer(
861
+ this._gliphParamArr,
862
+ 4,
863
+ this._gliphParamArr.length / 4
864
+ );
865
+ }
866
+
867
+ createOutlineBuffer() {
868
+ var h = this._renderer.handler;
869
+ h.gl.deleteBuffer(this._outlineBuffer);
870
+ this._outlineBuffer = h.createArrayBuffer(this._outlineArr, 1, this._outlineArr.length);
871
+ }
872
+
873
+ createOutlineColorBuffer() {
874
+ var h = this._renderer.handler;
875
+ h.gl.deleteBuffer(this._outlineColorBuffer);
876
+ this._outlineColorBuffer = h.createArrayBuffer(this._outlineColorArr, 4, this._outlineColorArr.length / 4);
877
+ }
878
+
879
+ setMaxLetters(c) {
880
+ this._maxLetters = c;
881
+ // TODO: ...
882
+ }
883
+
884
+ refreshTexCoordsArr() {
885
+ // it is empty
886
+ return null;
887
+ }
888
+ }
889
+
1042
890
  export { LabelHandler };