@pirireis/webglobeplugins 0.11.1-alpha → 0.13.0-alpha

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 (38) hide show
  1. package/Math/arc-cdf-points.js +252 -0
  2. package/Math/{arc-generate-points.js → arc-generate-points copy.js } +4 -0
  3. package/Math/arc-generate-points-exponantial.js +254 -0
  4. package/Math/arc.js +5 -5
  5. package/Math/circle-cdf-points.js +247 -0
  6. package/Math/circle.js +39 -0
  7. package/Math/methods.js +13 -3
  8. package/Math/vec3.js +3 -3
  9. package/package.json +1 -1
  10. package/programs/line-on-globe/circle-accurate.js +176 -175
  11. package/programs/line-on-globe/circle.js +166 -164
  12. package/programs/line-on-globe/linestrip/data.js +4 -0
  13. package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +38 -39
  14. package/programs/line-on-globe/to-the-surface.js +111 -109
  15. package/programs/rings/distancering/circleflatprogram.js +116 -120
  16. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
  17. package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
  18. package/programs/rings/distancering/index.js +6 -5
  19. package/programs/rings/distancering/paddyflatprogram.js +127 -136
  20. package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
  21. package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
  22. package/programs/totems/camerauniformblock.js +35 -8
  23. package/programs/totems/canvas-webglobe-info.js +55 -20
  24. package/programs/totems/{camerauniformblock copy.js → canvas-webglobe-info1.js} +11 -76
  25. package/programs/vectorfields/logics/pixelbased.js +4 -20
  26. package/shape-on-terrain/arc/naive/plugin.js +249 -288
  27. package/shape-on-terrain/circle/plugin.js +284 -0
  28. package/shape-on-terrain/type.js +1 -0
  29. package/util/account/index.js +2 -2
  30. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
  31. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +2 -2
  32. package/util/build-strategy/general-strategy.js +62 -0
  33. package/util/build-strategy/static-dynamic.js +31 -0
  34. package/util/gl-util/draw-options/types.js +1 -1
  35. package/globe-types.js +0 -1
  36. package/programs/interface.js +0 -1
  37. package/programs/rings/distancering/shader.js +0 -1
  38. package/programs/totems/camerauniformblock1.js +0 -171
@@ -1,354 +1,368 @@
1
- /**
2
- * ring data model
3
- * [centerX, centerY, range, padding, r, g, b, a, hide]
4
- *
5
- * Buffer is initialized with ring capacity and buffer is created with that capacity. It might be called buffer orphaning.
6
- *
7
- * */
8
- /**
9
- * TODO
10
- * delete registerCenter
11
- *
12
- *
13
- */
14
- const RING_SIZE = 9;
15
- export default class {
16
- /**
17
- * @param {WebGL2RenderingContext} gl
18
- * @param {Object} options
19
- * @param {Number} options.initialRingCapacity
20
- * @param {String} options.bufferType - "static" or "dynamic"
21
- * */
22
- constructor(gl, globe, { initialRingCapacity = 20, bufferType = "STATIC_DRAW", implicitExtentionRate = 1.2 } = {}) {
23
- this.gl = gl;
24
- this.globe = globe;
25
- this._capacity = initialRingCapacity;
26
- this._ringCounter = 0;
27
- this._length = 0;
28
- this._centerMap = new Map(); // key, new MAP(x,y, rings:[])
29
- this._ringOffsets = new Map();
30
- this._removedRingsOffsetStack = [];
31
- this._bufferType = gl[bufferType.toUpperCase()];
32
- this.implicitExtentionRate = implicitExtentionRate;
33
- this.buffer = gl.createBuffer();
34
- { // initilize data
35
- gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
36
- gl.bufferData(gl.ARRAY_BUFFER, initialRingCapacity * 4 * RING_SIZE, this._bufferType);
37
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
38
- }
39
- {
40
- this._circleVAO = gl.createVertexArray();
41
- gl.bindVertexArray(this._circleVAO);
42
- gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
43
- gl.enableVertexAttribArray(0);
44
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
45
- gl.enableVertexAttribArray(1);
46
- gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
47
- gl.enableVertexAttribArray(2);
48
- gl.vertexAttribPointer(2, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
49
- gl.enableVertexAttribArray(3);
50
- gl.vertexAttribPointer(3, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
51
- // set divisors to 1
52
- gl.vertexAttribDivisor(0, 1);
53
- gl.vertexAttribDivisor(1, 1);
54
- gl.vertexAttribDivisor(2, 1);
55
- gl.vertexAttribDivisor(3, 1);
56
- gl.bindVertexArray(null);
57
- }
58
- {
59
- this._paddingVAO = gl.createVertexArray();
60
- gl.bindVertexArray(this._paddingVAO);
61
- gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
62
- gl.enableVertexAttribArray(0);
63
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
64
- gl.enableVertexAttribArray(1);
65
- gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
66
- gl.enableVertexAttribArray(2);
67
- gl.vertexAttribPointer(2, 1, gl.FLOAT, false, RING_SIZE * 4, 3 * 4);
68
- gl.enableVertexAttribArray(3);
69
- gl.vertexAttribPointer(3, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
70
- gl.enableVertexAttribArray(4);
71
- gl.vertexAttribPointer(4, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
72
- gl.vertexAttribDivisor(0, 1);
73
- gl.vertexAttribDivisor(1, 1);
74
- gl.vertexAttribDivisor(2, 1);
75
- gl.vertexAttribDivisor(3, 1);
76
- gl.vertexAttribDivisor(4, 1);
77
- gl.bindVertexArray(null);
78
- }
79
- }
80
- /**
81
- * @param {String} centerID
82
- * @param {Object} options
83
- * @param {Number} options.x
84
- * @param {Number} options.y
85
- * */
86
- registerCenter(centerID, { x = 0, y = 0 } = {}) {
87
- this._centerMap.set(centerID, new Map([
88
- ["x", x],
89
- ["y", y],
90
- ["rings", []] // ring keys
91
- ]));
92
- }
93
- /**
94
- *
95
- * @param {null | number} newCapacity if null, vacuum defragmentation is applied -> capacity is set to the current ring count
96
- */
97
- defrag(newCapacity = null) {
98
- const { _removedRingsOffsetStack, _ringOffsets } = this;
99
- _removedRingsOffsetStack.sort();
100
- this._capacity = newCapacity || this._ringCounter;
101
- const arrayToLoad = new Float32Array(this._capacity * RING_SIZE);
102
- const bufferData = this._getBufferData();
103
- let arrayOffset = 0;
104
- const newRingOffsets = new Map();
105
- for (const [key, offset] of _ringOffsets) {
106
- const ringOffset = offset / 4;
107
- const ringData = bufferData.slice(ringOffset, ringOffset + RING_SIZE);
108
- arrayToLoad.set(ringData, arrayOffset);
109
- newRingOffsets.set(key, arrayOffset * 4);
110
- arrayOffset += RING_SIZE;
111
- }
112
- const { gl, buffer } = this;
113
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
114
- gl.bufferData(gl.ARRAY_BUFFER, arrayToLoad, this._bufferType);
115
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
116
- this._ringOffsets = newRingOffsets;
117
- this._removedRingsOffsetStack = [];
118
- this._length = this._ringCounter;
119
- }
120
- extendBuffer(newCapacity) {
121
- if (this._capacity >= newCapacity) {
122
- console.warn("New capacity is smaller than the current capacity");
123
- return;
124
- }
125
- this._capacity = newCapacity;
126
- const { gl, buffer } = this;
127
- const bufferData = this._getBufferData();
128
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
129
- gl.bufferData(gl.ARRAY_BUFFER, newCapacity * RING_SIZE * 4, this._bufferType);
130
- gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
131
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
132
- }
133
- checkCapacity(sizeLeft = 1) {
134
- return sizeLeft <= this._capacity - this._ringCounter;
135
- }
136
- capacityLeft() {
137
- return this._capacity - this._ringCounter;
138
- }
139
- get capacity() {
140
- return this._capacity;
141
- }
142
- get length() {
143
- return this._length;
144
- }
145
- get ringCount() {
146
- return this._ringCounter;
147
- }
148
- /**
149
- * @param {Array<string>} centerIDs
150
- * */
151
- removeCenters(centerIDs) {
152
- const { gl, buffer } = this;
153
- const zero = new Float32Array([0]);
154
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
155
- for (let centerID of centerIDs) {
156
- if (!this._centerMap.has(centerID)) {
157
- // console.warn("Center is not registered yet");
158
- // return;
159
- continue;
160
- }
161
- const center = this._centerMap.get(centerID);
162
- const rings = center.get("rings");
163
- for (let i = 0; i < rings.length; i++) {
164
- // set range to 0, 3rd index of float32array
165
- const offset = this._ringOffsets.get(rings[i]);
166
- gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, zero);
167
- this._removedRingsOffsetStack.push(offset);
168
- this._ringOffsets.delete(rings[i]);
169
- }
170
- this._ringCounter -= rings.length;
171
- this._centerMap.delete(centerID);
172
- }
173
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
174
- this.globe.DrawRender();
175
- }
176
- /**
177
- *
178
- * @property {String} centerID
179
- * @property {Number} x radians x
180
- * @property {Number} y radians y
181
- * @param {*} centerIDxyList
182
- */
183
- updateCentersXY(centerIDxyList) {
184
- const { gl, buffer } = this;
185
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
186
- for (let { centerID, x, y } of centerIDxyList) {
187
- const center = this._centerMap.get(centerID);
188
- center.set("x", x);
189
- center.set("y", y);
190
- const xyBlock = new Float32Array([x, y]);
191
- const rings = center.get("rings");
192
- for (let i = 0; i < rings.length; i++) {
193
- const offset = this._ringOffsets.get(rings[i]);
194
- gl.bufferSubData(gl.ARRAY_BUFFER, offset, xyBlock);
195
- }
196
- }
197
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
198
- this.globe.DrawRender();
199
- }
200
- updateCentersHide(data) {
201
- const { gl, buffer } = this;
202
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
203
- for (let { centerID, hide = null } of data) {
204
- if (hide === null)
205
- continue;
206
- const rings = this._centerMap.get(centerID).get("rings");
207
- for (let i = 0; i < rings.length; i++) {
208
- const offset = this._ringOffsets.get(rings[i]);
209
- gl.bufferSubData(gl.ARRAY_BUFFER, offset + 32, new Float32Array([hide]));
210
- }
211
- }
212
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
213
- this.globe.DrawRender();
214
- }
215
- insertBulk(rangeRingDatas) {
216
- const { gl, buffer } = this;
217
- { // remove existring centers
218
- const existingCenterIDs = [];
219
- for (let { centerID } of rangeRingDatas) {
220
- if (this._centerMap.has(centerID)) {
221
- existingCenterIDs.push(centerID);
222
- }
223
- }
224
- this.removeCenters(existingCenterIDs);
225
- }
226
- { // capacity check
227
- let incomingRingSize = 0;
228
- for (let { rings } of rangeRingDatas) {
229
- incomingRingSize += rings.length;
230
- // It should check if ring is already registered but for now it is not implemented.
231
- // Reasons: increase in complexity and performance
232
- }
233
- this._implicitExtendBufferInNeed(incomingRingSize);
234
- }
235
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
236
- for (const { centerID, x, y, rings, hide = 0 } of rangeRingDatas) {
237
- this.registerCenter(centerID, { x, y });
238
- for (const { ringID, radius, padding, rgba } of rings) {
239
- const key = this._ringKey(centerID, ringID);
240
- const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide]);
241
- const offset = this._nextBufferOffset();
242
- gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
243
- this._ringOffsets.set(key, offset);
244
- this._centerMap.get(centerID).get("rings").push(key);
245
- }
246
- }
247
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
248
- this.globe.DrawRender();
249
- }
250
- /**
251
- *
252
- * @param {Array<{centerID, rgba}} centersColors
253
- */
254
- updateCentersColor(centersColors) {
255
- const { gl, buffer } = this;
256
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
257
- for (let { centerID, rgba } of centersColors) {
258
- if (!this._centerMap.has(centerID)) {
259
- console.warn("Center is not registered yet");
260
- continue;
261
- }
262
- const rings = this._centerMap.get(centerID).get("rings");
263
- const block = new Float32Array(rgba);
264
- for (let i = 0; i < rings.length; i++) {
265
- const offset = this._ringOffsets.get(rings[i]);
266
- gl.bufferSubData(gl.ARRAY_BUFFER, offset + 16, block);
267
- }
268
- }
269
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
270
- this.globe.DrawRender();
271
- }
272
- // ----------------- INTERNAL METHODS ----------------- //
273
- bindCircleVAO() {
274
- this.gl.bindVertexArray(this._circleVAO);
275
- }
276
- bindPaddingVAO() {
277
- this.gl.bindVertexArray(this._paddingVAO);
278
- }
279
- free() {
280
- this.gl.deleteBuffer(this.buffer);
281
- this.gl.deleteVertexArray(this._circleVAO);
282
- this.gl.deleteVertexArray(this._paddingVAO);
283
- }
284
- // ----------------- PRIVATE METHODS ----------------- //
285
- _getBufferData() {
286
- const { gl, buffer } = this;
287
- const size = new Float32Array(this._length * RING_SIZE);
288
- const bufferData = new Float32Array(size);
289
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
290
- gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
291
- gl.bindBuffer(gl.ARRAY_BUFFER, null);
292
- return bufferData;
293
- }
294
- _ringKey(centerID, ringID) {
295
- return `C=${centerID},R=${ringID}`;
296
- }
297
- _nextBufferOffset() {
298
- if (!this.checkCapacity()) {
299
- throw new Error("Buffer is full");
300
- return;
301
- }
302
- let offset;
303
- if (this._removedRingsOffsetStack.length > 0) {
304
- offset = this._removedRingsOffsetStack.pop();
305
- }
306
- else {
307
- offset = this._ringCounter * RING_SIZE * 4;
308
- this._length++;
309
- }
310
- this._ringCounter++;
311
- return offset;
312
- }
313
- _implicitExtendBufferInNeed(incomingRingSize) {
314
- const overCapacity = incomingRingSize - this.capacityLeft();
315
- if (overCapacity <= 0)
316
- return;
317
- const newCapacity = Math.ceil((this._capacity + overCapacity) * this.implicitExtentionRate);
318
- this.extendBuffer(newCapacity);
319
- }
320
- async readRing(centerID, ringID) {
321
- const key = this._ringKey(centerID, ringID);
322
- if (!this._ringOffsets.has(key)) {
323
- console.warn("Ring is not registered yet");
324
- return;
325
- }
326
- const offset = this._ringOffsets.get(key);
327
- const { gl, buffer } = this;
328
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
329
- const bufferData = new Float32Array(9);
330
- gl.getBufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
331
- return {
332
- centerX: bufferData[0],
333
- centerY: bufferData[1],
334
- range: bufferData[2],
335
- padding: bufferData[3],
336
- rgba: [bufferData[4], bufferData[5], bufferData[6], bufferData[7]],
337
- hide: bufferData[8]
338
- };
339
- }
340
- }
341
- /**
342
- * Documentation
343
- *
344
- * Methods:
345
- * - insertRings(centerIdringIdRadiusPaddingRgbaHide)
346
- * - removeRings(centerIDringIDs)
347
- * - removeCenters(centerIDs)
348
- * - updateCentersXY(centerIDxyList)
349
- * - updateCenters(centerDatas)
350
- * - insertBulk(rangeRingDatas)
351
- * - updateRing(centerID, ringID, { radius, padding, rgba, hide })
352
- * - readRing(centerID, ringID)
353
- *
354
- */
1
+ "use strict";
2
+ // TODO: Delete this file if it is not needed anymore.
3
+ // /**
4
+ // * ring data model
5
+ // * [centerX, centerY, range, padding, r, g, b, a, hide]
6
+ // *
7
+ // * Buffer is initialized with ring capacity and buffer is created with that capacity. It might be called buffer orphaning.
8
+ // *
9
+ // * */
10
+ // /**
11
+ // * TODO
12
+ // * delete registerCenter
13
+ // *
14
+ // *
15
+ // */
16
+ // const RING_SIZE = 9;
17
+ // export default class {
18
+ // /**
19
+ // * @param {WebGL2RenderingContext} gl
20
+ // * @param {Object} options
21
+ // * @param {Number} options.initialRingCapacity
22
+ // * @param {String} options.bufferType - "static" or "dynamic"
23
+ // * */
24
+ // constructor(gl, globe, { initialRingCapacity = 20, bufferType = "STATIC_DRAW", implicitExtentionRate = 1.2 } = {}) {
25
+ // this.gl = gl;
26
+ // this.globe = globe;
27
+ // this._capacity = initialRingCapacity;
28
+ // this._ringCounter = 0;
29
+ // this._length = 0;
30
+ // this._centerMap = new Map(); // key, new MAP(x,y, rings:[])
31
+ // this._ringOffsets = new Map();
32
+ // this._removedRingsOffsetStack = [];
33
+ // this._bufferType = gl[bufferType.toUpperCase()];
34
+ // this.implicitExtentionRate = implicitExtentionRate;
35
+ // this.buffer = gl.createBuffer();
36
+ // { // initilize data
37
+ // gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
38
+ // gl.bufferData(gl.ARRAY_BUFFER, initialRingCapacity * 4 * RING_SIZE, this._bufferType);
39
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
40
+ // }
41
+ // {
42
+ // this._circleVAO = gl.createVertexArray();
43
+ // gl.bindVertexArray(this._circleVAO);
44
+ // gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
45
+ // gl.enableVertexAttribArray(0);
46
+ // gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
47
+ // gl.enableVertexAttribArray(1);
48
+ // gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
49
+ // gl.enableVertexAttribArray(2);
50
+ // gl.vertexAttribPointer(2, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
51
+ // gl.enableVertexAttribArray(3);
52
+ // gl.vertexAttribPointer(3, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
53
+ // // set divisors to 1
54
+ // gl.vertexAttribDivisor(0, 1);
55
+ // gl.vertexAttribDivisor(1, 1);
56
+ // gl.vertexAttribDivisor(2, 1);
57
+ // gl.vertexAttribDivisor(3, 1);
58
+ // gl.bindVertexArray(null);
59
+ // }
60
+ // {
61
+ // this._paddingVAO = gl.createVertexArray();
62
+ // gl.bindVertexArray(this._paddingVAO);
63
+ // gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
64
+ // gl.enableVertexAttribArray(0);
65
+ // gl.vertexAttribPointer(0, 2, gl.FLOAT, false, RING_SIZE * 4, 0);
66
+ // gl.enableVertexAttribArray(1);
67
+ // gl.vertexAttribPointer(1, 1, gl.FLOAT, false, RING_SIZE * 4, 2 * 4);
68
+ // gl.enableVertexAttribArray(2);
69
+ // gl.vertexAttribPointer(2, 1, gl.FLOAT, false, RING_SIZE * 4, 3 * 4);
70
+ // gl.enableVertexAttribArray(3);
71
+ // gl.vertexAttribPointer(3, 4, gl.FLOAT, false, RING_SIZE * 4, 4 * 4);
72
+ // gl.enableVertexAttribArray(4);
73
+ // gl.vertexAttribPointer(4, 3, gl.FLOAT, false, RING_SIZE * 4, 8 * 4);
74
+ // gl.vertexAttribDivisor(0, 1);
75
+ // gl.vertexAttribDivisor(1, 1);
76
+ // gl.vertexAttribDivisor(2, 1);
77
+ // gl.vertexAttribDivisor(3, 1);
78
+ // gl.vertexAttribDivisor(4, 1);
79
+ // gl.bindVertexArray(null);
80
+ // }
81
+ // }
82
+ // /**
83
+ // * @param {String} centerID
84
+ // * @param {Object} options
85
+ // * @param {Number} options.x
86
+ // * @param {Number} options.y
87
+ // * */
88
+ // registerCenter(centerID, { x = 0, y = 0 } = {}) {
89
+ // this._centerMap.set(centerID, new Map(
90
+ // [
91
+ // ["x", x],
92
+ // ["y", y],
93
+ // ["rings", []] // ring keys
94
+ // ]
95
+ // ));
96
+ // }
97
+ // /**
98
+ // *
99
+ // * @param {null | number} newCapacity if null, vacuum defragmentation is applied -> capacity is set to the current ring count
100
+ // */
101
+ // defrag(newCapacity = null) {
102
+ // const { _removedRingsOffsetStack, _ringOffsets } = this;
103
+ // _removedRingsOffsetStack.sort();
104
+ // this._capacity = newCapacity || this._ringCounter;
105
+ // const arrayToLoad = new Float32Array(this._capacity * RING_SIZE);
106
+ // const bufferData = this._getBufferData();
107
+ // let arrayOffset = 0;
108
+ // const newRingOffsets = new Map();
109
+ // for (const [key, offset] of _ringOffsets) {
110
+ // const ringOffset = offset / 4
111
+ // const ringData = bufferData.slice(ringOffset, ringOffset + RING_SIZE);
112
+ // arrayToLoad.set(ringData, arrayOffset);
113
+ // newRingOffsets.set(key, arrayOffset * 4);
114
+ // arrayOffset += RING_SIZE;
115
+ // }
116
+ // const { gl, buffer } = this;
117
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
118
+ // gl.bufferData(gl.ARRAY_BUFFER, arrayToLoad, this._bufferType);
119
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
120
+ // this._ringOffsets = newRingOffsets;
121
+ // this._removedRingsOffsetStack = [];
122
+ // this._length = this._ringCounter;
123
+ // }
124
+ // extendBuffer(newCapacity) {
125
+ // if (this._capacity >= newCapacity) {
126
+ // console.warn("New capacity is smaller than the current capacity");
127
+ // return;
128
+ // }
129
+ // this._capacity = newCapacity;
130
+ // const { gl, buffer } = this;
131
+ // const bufferData = this._getBufferData();
132
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
133
+ // gl.bufferData(gl.ARRAY_BUFFER, newCapacity * RING_SIZE * 4, this._bufferType);
134
+ // gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
135
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
136
+ // }
137
+ // checkCapacity(sizeLeft = 1) {
138
+ // return sizeLeft <= this._capacity - this._ringCounter;
139
+ // }
140
+ // capacityLeft() {
141
+ // return this._capacity - this._ringCounter;
142
+ // }
143
+ // get capacity() {
144
+ // return this._capacity;
145
+ // }
146
+ // get length() {
147
+ // return this._length;
148
+ // }
149
+ // get ringCount() {
150
+ // return this._ringCounter;
151
+ // }
152
+ // /**
153
+ // * @param {Array<string>} centerIDs
154
+ // * */
155
+ // removeCenters(centerIDs) {
156
+ // const { gl, buffer } = this;
157
+ // const zero = new Float32Array([0]);
158
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
159
+ // for (let centerID of centerIDs) {
160
+ // if (!this._centerMap.has(centerID)) {
161
+ // // console.warn("Center is not registered yet");
162
+ // // return;
163
+ // continue;
164
+ // }
165
+ // const center = this._centerMap.get(centerID);
166
+ // const rings = center.get("rings");
167
+ // for (let i = 0; i < rings.length; i++) {
168
+ // // set range to 0, 3rd index of float32array
169
+ // const offset = this._ringOffsets.get(rings[i]);
170
+ // gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, zero);
171
+ // this._removedRingsOffsetStack.push(offset);
172
+ // this._ringOffsets.delete(rings[i]);
173
+ // }
174
+ // this._ringCounter -= rings.length;
175
+ // this._centerMap.delete(centerID);
176
+ // }
177
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
178
+ // this.globe.DrawRender();
179
+ // }
180
+ // /**
181
+ // *
182
+ // * @property {String} centerID
183
+ // * @property {Number} x radians x
184
+ // * @property {Number} y radians y
185
+ // * @param {*} centerIDxyList
186
+ // */
187
+ // updateCentersXY(centerIDxyList) {
188
+ // const { gl, buffer } = this;
189
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
190
+ // for (let { centerID, x, y } of centerIDxyList) {
191
+ // const center = this._centerMap.get(centerID);
192
+ // center.set("x", x);
193
+ // center.set("y", y);
194
+ // const xyBlock = new Float32Array([x, y]);
195
+ // const rings = center.get("rings");
196
+ // for (let i = 0; i < rings.length; i++) {
197
+ // const offset = this._ringOffsets.get(rings[i]);
198
+ // gl.bufferSubData(gl.ARRAY_BUFFER, offset, xyBlock);
199
+ // }
200
+ // }
201
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
202
+ // this.globe.DrawRender();
203
+ // }
204
+ // updateCentersHide(data) {
205
+ // const { gl, buffer } = this;
206
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
207
+ // for (let { centerID, hide = null } of data) {
208
+ // if (hide === null) continue;
209
+ // const rings = this._centerMap.get(centerID).get("rings");
210
+ // for (let i = 0; i < rings.length; i++) {
211
+ // const offset = this._ringOffsets.get(rings[i]);
212
+ // gl.bufferSubData(gl.ARRAY_BUFFER, offset + 32, new Float32Array([hide]));
213
+ // }
214
+ // }
215
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
216
+ // this.globe.DrawRender();
217
+ // }
218
+ // insertBulk(rangeRingDatas) {
219
+ // const { gl, buffer } = this;
220
+ // {// remove existring centers
221
+ // const existingCenterIDs = [];
222
+ // for (let { centerID } of rangeRingDatas) {
223
+ // if (this._centerMap.has(centerID)) {
224
+ // existingCenterIDs.push(centerID);
225
+ // }
226
+ // }
227
+ // this.removeCenters(existingCenterIDs);
228
+ // }
229
+ // { // capacity check
230
+ // let incomingRingSize = 0;
231
+ // for (let { rings } of rangeRingDatas) {
232
+ // incomingRingSize += rings.length;
233
+ // // It should check if ring is already registered but for now it is not implemented.
234
+ // // Reasons: increase in complexity and performance
235
+ // }
236
+ // this._implicitExtendBufferInNeed(incomingRingSize);
237
+ // }
238
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
239
+ // for (const { centerID, x, y, rings, hide = 0 } of rangeRingDatas) {
240
+ // this.registerCenter(centerID, { x, y })
241
+ // for (const { ringID, radius, padding, rgba } of rings) {
242
+ // const key = this._ringKey(centerID, ringID);
243
+ // const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide]);
244
+ // const offset = this._nextBufferOffset();
245
+ // gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
246
+ // this._ringOffsets.set(key, offset);
247
+ // this._centerMap.get(centerID).get("rings").push(key);
248
+ // }
249
+ // }
250
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
251
+ // this.globe.DrawRender();
252
+ // }
253
+ // /**
254
+ // *
255
+ // * @param {Array<{centerID, rgba}} centersColors
256
+ // */
257
+ // updateCentersColor(centersColors) {
258
+ // const { gl, buffer } = this;
259
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
260
+ // for (let { centerID, rgba } of centersColors) {
261
+ // if (!this._centerMap.has(centerID)) {
262
+ // console.warn("Center is not registered yet");
263
+ // continue;
264
+ // }
265
+ // const rings = this._centerMap.get(centerID).get("rings");
266
+ // const block = new Float32Array(rgba);
267
+ // for (let i = 0; i < rings.length; i++) {
268
+ // const offset = this._ringOffsets.get(rings[i]);
269
+ // gl.bufferSubData(gl.ARRAY_BUFFER, offset + 16, block);
270
+ // }
271
+ // }
272
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
273
+ // this.globe.DrawRender();
274
+ // }
275
+ // // ----------------- INTERNAL METHODS ----------------- //
276
+ // bindCircleVAO() {
277
+ // this.gl.bindVertexArray(this._circleVAO);
278
+ // }
279
+ // bindPaddingVAO() {
280
+ // this.gl.bindVertexArray(this._paddingVAO);
281
+ // }
282
+ // free() {
283
+ // this.gl.deleteBuffer(this.buffer);
284
+ // this.gl.deleteVertexArray(this._circleVAO);
285
+ // this.gl.deleteVertexArray(this._paddingVAO);
286
+ // }
287
+ // // ----------------- PRIVATE METHODS ----------------- //
288
+ // _getBufferData() {
289
+ // const { gl, buffer } = this;
290
+ // const size = new Float32Array(this._length * RING_SIZE);
291
+ // const bufferData = new Float32Array(size);
292
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
293
+ // gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
294
+ // gl.bindBuffer(gl.ARRAY_BUFFER, null);
295
+ // return bufferData;
296
+ // }
297
+ // _ringKey(centerID, ringID) {
298
+ // return `C=${centerID},R=${ringID}`;
299
+ // }
300
+ // _nextBufferOffset() {
301
+ // if (!this.checkCapacity()) {
302
+ // throw new Error("Buffer is full");
303
+ // return;
304
+ // }
305
+ // let offset;
306
+ // if (this._removedRingsOffsetStack.length > 0) {
307
+ // offset = this._removedRingsOffsetStack.pop();
308
+ // } else {
309
+ // offset = this._ringCounter * RING_SIZE * 4;
310
+ // this._length++;
311
+ // }
312
+ // this._ringCounter++;
313
+ // return offset;
314
+ // }
315
+ // _implicitExtendBufferInNeed(incomingRingSize) {
316
+ // const overCapacity = incomingRingSize - this.capacityLeft();
317
+ // if (overCapacity <= 0) return;
318
+ // const newCapacity = Math.ceil((this._capacity + overCapacity) * this.implicitExtentionRate);
319
+ // this.extendBuffer(newCapacity);
320
+ // }
321
+ // async readRing(centerID, ringID) {
322
+ // const key = this._ringKey(centerID, ringID);
323
+ // if (!this._ringOffsets.has(key)) {
324
+ // console.warn("Ring is not registered yet");
325
+ // return;
326
+ // }
327
+ // const offset = this._ringOffsets.get(key);
328
+ // const { gl, buffer } = this;
329
+ // gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
330
+ // const bufferData = new Float32Array(9);
331
+ // gl.getBufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
332
+ // return {
333
+ // centerX: bufferData[0],
334
+ // centerY: bufferData[1],
335
+ // range: bufferData[2],
336
+ // padding: bufferData[3],
337
+ // rgba: [bufferData[4], bufferData[5], bufferData[6], bufferData[7]],
338
+ // hide: bufferData[8]
339
+ // }
340
+ // }
341
+ // /**
342
+ // * TODOS:
343
+ // * - bulk ring registration. This must be managed here to avoid binding and unbinding buffer multiple times
344
+ // * - bulk centers and rings registration
345
+ // *
346
+ // * - Check capacity on extend buffer and collect garbage
347
+ // * - set length to the filled part of the buffer. used for draw calls
348
+ // * */
349
+ // /**
350
+ // * collectGarbage with Defragmantation
351
+ // * Basic idea: on unregistration the last ring is moved to the removed ring's place. length is decreased by 1
352
+ // * Optimization: Reading buffer is expensive. So bulk defragmentation is needed to work with this approach
353
+ // * */
354
+ // }
355
+ // /**
356
+ // * Documentation
357
+ // *
358
+ // * Methods:
359
+ // * - insertRings(centerIdringIdRadiusPaddingRgbaHide)
360
+ // * - removeRings(centerIDringIDs)
361
+ // * - removeCenters(centerIDs)
362
+ // * - updateCentersXY(centerIDxyList)
363
+ // * - updateCenters(centerDatas)
364
+ // * - insertBulk(rangeRingDatas)
365
+ // * - updateRing(centerID, ringID, { radius, padding, rgba, hide })
366
+ // * - readRing(centerID, ringID)
367
+ // *
368
+ // */