@pirireis/webglobeplugins 0.0.5 → 0.0.6
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.
- package/package.json +1 -1
- package/partialrings/program.js +0 -2
- package/programs/rings/distancering/circleflatprogram.js +1 -1
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +382 -0
- package/programs/rings/distancering/circlepaddysharedbuffer.js +52 -94
- package/programs/rings/distancering/index.js +2 -2
- package/programs/rings/distancering/paddyflatprogram.js +5 -2
- package/rangerings/index.js +2 -2
- package/rangerings/rangerings.js +93 -14
- package/util/account/bufferoffsetmanager.js +29 -18
package/package.json
CHANGED
package/partialrings/program.js
CHANGED
|
@@ -105,7 +105,7 @@ class Logic {
|
|
|
105
105
|
gl.uniform1f(this._circleEdgeCountLocation, circle_edge_count);
|
|
106
106
|
this._circle_edge_count = circle_edge_count;
|
|
107
107
|
}
|
|
108
|
-
gl.drawArraysInstanced(gl.LINE_LOOP, 0,
|
|
108
|
+
gl.drawArraysInstanced(gl.LINE_LOOP, 0, circle_edge_count, attrBufferManager.length);
|
|
109
109
|
gl.bindVertexArray(null);
|
|
110
110
|
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
111
111
|
}
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { createProgram, shaderfunctions } from "../../../util";
|
|
2
|
+
import { BufferOffsetManager } from "../../../util/account";
|
|
3
|
+
import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
|
|
4
|
+
import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const vertexShader = `#version 300 es ` +
|
|
8
|
+
shaderfunctions.PI +
|
|
9
|
+
shaderfunctions.R +
|
|
10
|
+
shaderfunctions.POLE +
|
|
11
|
+
CameraUniformBlockString +
|
|
12
|
+
shaderfunctions.mercatorXYTo2DPoint +
|
|
13
|
+
shaderfunctions.longLatRadToMercator +
|
|
14
|
+
shaderfunctions.longLatRadToCartesian3D +
|
|
15
|
+
shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
|
|
16
|
+
shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
|
|
17
|
+
shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
|
|
18
|
+
|
|
19
|
+
in vec2 center;
|
|
20
|
+
in float radius;
|
|
21
|
+
in float pad_range;
|
|
22
|
+
in vec4 color;
|
|
23
|
+
in float flag;
|
|
24
|
+
in float pad_angle;
|
|
25
|
+
|
|
26
|
+
uniform int compass;
|
|
27
|
+
|
|
28
|
+
out vec2 v_limp;
|
|
29
|
+
out vec4 v_color;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
void main() {
|
|
33
|
+
if( flag == 1.0 || radius == 0.0 ) return; // 1.0 is hide
|
|
34
|
+
v_color = color;
|
|
35
|
+
gl_PointSize = 2.0;
|
|
36
|
+
|
|
37
|
+
float odd = mod(float(gl_VertexID), 2.0);
|
|
38
|
+
float index = (float(gl_VertexID)- odd ) / 2.0;
|
|
39
|
+
float angle = pad_angle - 1.5707963267948966192313216916398;
|
|
40
|
+
float radius_ = radius - (pad_range * odd);
|
|
41
|
+
|
|
42
|
+
if ( is3D){
|
|
43
|
+
gl_Position = projection * view * vec4(
|
|
44
|
+
circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
|
|
45
|
+
v_limp = vec2(0.0, 0.0);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
vec2 limp;
|
|
49
|
+
if ( compass == 1 ){
|
|
50
|
+
limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
|
|
51
|
+
} else {
|
|
52
|
+
limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
|
|
53
|
+
}
|
|
54
|
+
v_limp = limp;
|
|
55
|
+
gl_Position = mercatorXYTo2DPoint(limp);
|
|
56
|
+
}`;
|
|
57
|
+
|
|
58
|
+
const fragmentShader = `#version 300 es
|
|
59
|
+
precision highp float; ` +
|
|
60
|
+
shaderfunctions.POLE + `
|
|
61
|
+
in vec4 v_color;
|
|
62
|
+
in vec2 v_limp;
|
|
63
|
+
out vec4 outColor;
|
|
64
|
+
void main() {
|
|
65
|
+
if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
|
|
66
|
+
outColor = v_color;
|
|
67
|
+
}`;
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class Logic {
|
|
73
|
+
|
|
74
|
+
constructor(globe) {
|
|
75
|
+
|
|
76
|
+
this.globe = globe;
|
|
77
|
+
this.gl = globe.gl;
|
|
78
|
+
this.program = createProgram(this.gl, vertexShader, fragmentShader);
|
|
79
|
+
|
|
80
|
+
{
|
|
81
|
+
const gl = this.gl;
|
|
82
|
+
this.center = gl.getAttribLocation(this.program, "center");
|
|
83
|
+
this.radius = gl.getAttribLocation(this.program, "radius");
|
|
84
|
+
this.pad_range = gl.getAttribLocation(this.program, "pad_range");
|
|
85
|
+
this.color = gl.getAttribLocation(this.program, "color");
|
|
86
|
+
this.flag = gl.getAttribLocation(this.program, "flag");
|
|
87
|
+
this.pad_angle = gl.getAttribLocation(this.program, "pad_angle");
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this.cameraBlockBindingPoint = 0;
|
|
92
|
+
const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
|
|
93
|
+
this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
|
|
94
|
+
this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
|
|
95
|
+
this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
{
|
|
99
|
+
const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
|
|
100
|
+
this.gl.useProgram(this.program);
|
|
101
|
+
this.gl.uniform1i(this._compassLocation, 1);
|
|
102
|
+
this._lastCompass = 1;
|
|
103
|
+
this.gl.useProgram(currentProgram);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
draw(attrBufferManager, compass) {
|
|
109
|
+
|
|
110
|
+
const { gl, program, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
|
|
111
|
+
|
|
112
|
+
gl.useProgram(program);
|
|
113
|
+
attrBufferManager.bindPaddingVAO();
|
|
114
|
+
cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
115
|
+
if (compass !== this._lastCompass) {
|
|
116
|
+
gl.uniform1i(_compassLocation, compass);
|
|
117
|
+
this._lastCompass = compass;
|
|
118
|
+
}
|
|
119
|
+
gl.disable(gl.DEPTH_TEST);
|
|
120
|
+
gl.drawArraysInstanced(gl.LINES, 0, 2, attrBufferManager.length);
|
|
121
|
+
gl.enable(gl.DEPTH_TEST);
|
|
122
|
+
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
123
|
+
gl.bindVertexArray(null);
|
|
124
|
+
|
|
125
|
+
}
|
|
126
|
+
initilizeBufferManager({ bufferType = "DYNAMIC_DRAW", initialRingCapacity = 10 } = {}) {
|
|
127
|
+
return new BufferManager(this.gl, bufferType, initialRingCapacity);
|
|
128
|
+
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
export const PaddingFreeAngleCache = Object.freeze({
|
|
135
|
+
getProgram: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
136
|
+
releaseProgram: (globe) => globeProgramCache.releaseProgram(globe, Logic)
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
export class BufferManager extends BufferOffsetManager {
|
|
142
|
+
constructor(gl, bufferType, initialRingCapacity = 10) {
|
|
143
|
+
super(10, { capacity: initialRingCapacity, bufferType });
|
|
144
|
+
this.gl = gl;
|
|
145
|
+
this.bufferType = bufferType;
|
|
146
|
+
this.buffer = gl.createBuffer();
|
|
147
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
148
|
+
gl.bufferData(gl.ARRAY_BUFFER, this.capacity * this.itemSize * 4, gl[bufferType]);
|
|
149
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
150
|
+
this._centerMaps = new Map();
|
|
151
|
+
this.vao = gl.createVertexArray();
|
|
152
|
+
|
|
153
|
+
{
|
|
154
|
+
gl.bindVertexArray(this.vao);
|
|
155
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this.buffer);
|
|
156
|
+
gl.enableVertexAttribArray(0);
|
|
157
|
+
gl.enableVertexAttribArray(1);
|
|
158
|
+
gl.enableVertexAttribArray(2);
|
|
159
|
+
gl.enableVertexAttribArray(3);
|
|
160
|
+
gl.enableVertexAttribArray(4);
|
|
161
|
+
gl.enableVertexAttribArray(5);
|
|
162
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, 40, 0);
|
|
163
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, 40, 8);
|
|
164
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, 40, 12);
|
|
165
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, 40, 16);
|
|
166
|
+
gl.vertexAttribPointer(4, 1, gl.FLOAT, false, 40, 32);
|
|
167
|
+
gl.vertexAttribPointer(5, 1, gl.FLOAT, false, 40, 36);
|
|
168
|
+
// divisor
|
|
169
|
+
gl.vertexAttribDivisor(0, 1);
|
|
170
|
+
gl.vertexAttribDivisor(1, 1);
|
|
171
|
+
gl.vertexAttribDivisor(2, 1);
|
|
172
|
+
gl.vertexAttribDivisor(3, 1);
|
|
173
|
+
gl.vertexAttribDivisor(4, 1);
|
|
174
|
+
gl.vertexAttribDivisor(5, 1);
|
|
175
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
176
|
+
gl.bindVertexArray(null);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
__centerMapMethod(x, y, rgba, rings, hide, paddingAngles) {
|
|
182
|
+
return new Map([
|
|
183
|
+
["x", x],
|
|
184
|
+
["y", y],
|
|
185
|
+
["rgba", rgba],
|
|
186
|
+
["rings", rings],
|
|
187
|
+
["hide", hide],
|
|
188
|
+
["paddingAngles", paddingAngles]
|
|
189
|
+
])
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
bindPaddingVAO() {
|
|
196
|
+
this.gl.bindVertexArray(this.vao);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
//TODO: implement this
|
|
200
|
+
// insertBulk is gone. no update feature
|
|
201
|
+
// addBulk is added.
|
|
202
|
+
// deletes old centers given
|
|
203
|
+
insertBulk(data) {
|
|
204
|
+
const { gl, buffer } = this;
|
|
205
|
+
|
|
206
|
+
const deleteCentersList = [];
|
|
207
|
+
for (const { centerID } of data) {
|
|
208
|
+
if (this._centerMaps.has(centerID)) {
|
|
209
|
+
deleteCentersList.push(centerID);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
if (deleteCentersList.length > 0) {
|
|
213
|
+
this.removeCenters(deleteCentersList);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
const requiredSpace = this.__requiredSpaceForBulk(data);
|
|
218
|
+
|
|
219
|
+
const spaceLeft = this.spaceLeft;
|
|
220
|
+
console.log("space left:", spaceLeft, "required space:", requiredSpace);
|
|
221
|
+
if (requiredSpace > spaceLeft) {
|
|
222
|
+
console.log("new capacity:", this.capacity + requiredSpace - spaceLeft)
|
|
223
|
+
this.extendBuffer(gl, buffer, this.bufferType, this.capacity + requiredSpace - spaceLeft);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const items = [];
|
|
227
|
+
|
|
228
|
+
for (const { centerID, x, y, rgba, paddingAngles, hide = false, rings } of data) {
|
|
229
|
+
|
|
230
|
+
this._centerMaps.set(centerID, this.__centerMapMethod(x, y, rgba, rings, hide, paddingAngles)); // x,y, rgba, hide prograbably not needed
|
|
231
|
+
|
|
232
|
+
const hideFlag = hide ? 1 : 0;
|
|
233
|
+
for (const { ringID, radius, padding } of rings) {
|
|
234
|
+
for (const paddingAngle of paddingAngles) {
|
|
235
|
+
const _offsetMapKey = `${centerID}_${ringID}_${paddingAngle}`;
|
|
236
|
+
const offset = this.getOffset(_offsetMapKey) | this.nextOffset();
|
|
237
|
+
items.push({
|
|
238
|
+
offset: offset,
|
|
239
|
+
payload: new Float32Array([x, y, radius, padding, rgba[0], rgba[1], rgba[2], rgba[3], hideFlag, paddingAngle])
|
|
240
|
+
})
|
|
241
|
+
this.offSetMap.set(_offsetMapKey, offset);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
const partOffset = 0;
|
|
246
|
+
|
|
247
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
248
|
+
for (let { offset, payload } of items) {
|
|
249
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, payload);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
updateCentersXY(data) {
|
|
255
|
+
const { gl, buffer } = this;
|
|
256
|
+
const items = [];
|
|
257
|
+
|
|
258
|
+
for (const { centerID, x, y } of data) {
|
|
259
|
+
const center = this._centerMaps.get(centerID);
|
|
260
|
+
center.set("x", x);
|
|
261
|
+
center.set("y", y);
|
|
262
|
+
const payload = new Float32Array([x, y]);
|
|
263
|
+
const paddingAngles = center.get("paddingAngles");
|
|
264
|
+
const rings = center.get("rings");
|
|
265
|
+
for (const { ringID } of rings) {
|
|
266
|
+
for (const paddingAngle of paddingAngles) {
|
|
267
|
+
const offsetKey = offsetMapKey(centerID, ringID, paddingAngle);
|
|
268
|
+
items.push({ offset: this.getOffset(offsetKey), payload });
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
273
|
+
for (let { offset, payload } of items) {
|
|
274
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, payload);
|
|
275
|
+
}
|
|
276
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
//TODO: test
|
|
282
|
+
updateCentersHide(data) {
|
|
283
|
+
const { gl, buffer } = this;
|
|
284
|
+
const items = [];
|
|
285
|
+
for (const { centerID, hide } of data) {
|
|
286
|
+
const block = new Float32Array([hide]);
|
|
287
|
+
const center = this._centerMaps.get(centerID);
|
|
288
|
+
if (!center) continue;
|
|
289
|
+
const paddingAngles = center.get("paddingAngles");
|
|
290
|
+
const rings = center.get("rings");
|
|
291
|
+
for (const { ringID } of rings) {
|
|
292
|
+
for (const paddingAngle of paddingAngles) {
|
|
293
|
+
const offsetKey = offsetMapKey(centerID, ringID, paddingAngle);
|
|
294
|
+
items.push({ key: offsetKey, payload: block });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
this._updatePartial(items, 8, gl, buffer);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
updateCentersColor(data) {
|
|
302
|
+
const { gl, buffer } = this;
|
|
303
|
+
const items = [];
|
|
304
|
+
for (const { centerID, rgba } of data) {
|
|
305
|
+
const center = this._centerMaps.get(centerID);
|
|
306
|
+
if (!center) continue;
|
|
307
|
+
center.set("rgba", rgba);
|
|
308
|
+
const paddingAngles = center.get("paddingAngles");
|
|
309
|
+
const rings = center.get("rings");
|
|
310
|
+
const payload = new Float32Array(rgba);
|
|
311
|
+
for (const { ringID } of rings) {
|
|
312
|
+
for (const paddingAngle of paddingAngles) {
|
|
313
|
+
const offsetKey = offsetMapKey(centerID, ringID, paddingAngle);
|
|
314
|
+
items.push({ key: offsetKey, payload });
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
this._updatePartial(items, 4, gl, buffer);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
__requiredSpaceForBulk(data) {
|
|
324
|
+
let space = 0;
|
|
325
|
+
for (const { paddingAngles, rings } of data) {
|
|
326
|
+
space += paddingAngles.length * rings.length;
|
|
327
|
+
}
|
|
328
|
+
return space;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// TODO: TEST IT WITH INSERT
|
|
332
|
+
removeCenters(centerIDs) {
|
|
333
|
+
const keys = [];
|
|
334
|
+
for (const centerID of centerIDs) {
|
|
335
|
+
const center = this._centerMaps.get(centerID);
|
|
336
|
+
if (!center) continue;
|
|
337
|
+
const rings = center.get("rings");
|
|
338
|
+
const paddingAngles = center.get("paddingAngles");
|
|
339
|
+
for (const { ringID } of rings) {
|
|
340
|
+
for (const paddingAngle of paddingAngles) {
|
|
341
|
+
keys.push(offsetMapKey(centerID, ringID, paddingAngle));
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
this._centerMaps.delete(centerID);
|
|
345
|
+
}
|
|
346
|
+
this._removeFromBuffer(keys);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
|
|
351
|
+
const offsetMapKey = (centerID, ringID, paddingAngle) => `${centerID}_${ringID}_${paddingAngle}`;
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* {center has x,y, color, paddingAngles, rings} key: centerID
|
|
357
|
+
* {ring has ranges, paddings} key: ringKey
|
|
358
|
+
* _offSetMap => | key: centerID_ringKey_paddingAngle | value: offset |
|
|
359
|
+
*
|
|
360
|
+
* insertCenter
|
|
361
|
+
*
|
|
362
|
+
* insertRing
|
|
363
|
+
*
|
|
364
|
+
* updateCenter ---> updatesRings ---> updatesPaddings
|
|
365
|
+
* centerMap ringMap
|
|
366
|
+
* keeps keeps
|
|
367
|
+
* list of Rings list of Paddings
|
|
368
|
+
*
|
|
369
|
+
*
|
|
370
|
+
* needs an adaptor to convert currently implemented data into this format.
|
|
371
|
+
* current format:
|
|
372
|
+
* center = {
|
|
373
|
+
* centerID,
|
|
374
|
+
* x,
|
|
375
|
+
* y,
|
|
376
|
+
* rings: [
|
|
377
|
+
* radius,
|
|
378
|
+
* paddingRadius,
|
|
379
|
+
* rgba,
|
|
380
|
+
* ]
|
|
381
|
+
* }
|
|
382
|
+
*/
|
|
@@ -5,6 +5,14 @@
|
|
|
5
5
|
* Buffer is initialized with ring capacity and buffer is created with that capacity. It might be called buffer orphaning.
|
|
6
6
|
*
|
|
7
7
|
* */
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* TODO
|
|
12
|
+
* delete registerCenter
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
8
16
|
const RING_SIZE = 9;
|
|
9
17
|
|
|
10
18
|
export default class {
|
|
@@ -14,7 +22,7 @@ export default class {
|
|
|
14
22
|
* @param {Number} options.initialRingCapacity
|
|
15
23
|
* @param {String} options.bufferType - "static" or "dynamic"
|
|
16
24
|
* */
|
|
17
|
-
constructor(gl, globe, { initialRingCapacity = 20, bufferType = "
|
|
25
|
+
constructor(gl, globe, { initialRingCapacity = 20, bufferType = "STATIC_DRAW", implicitExtentionRate = 1.2 } = {}) {
|
|
18
26
|
this.gl = gl;
|
|
19
27
|
this.globe = globe;
|
|
20
28
|
this._capacity = initialRingCapacity;
|
|
@@ -158,78 +166,8 @@ export default class {
|
|
|
158
166
|
}
|
|
159
167
|
|
|
160
168
|
|
|
161
|
-
/**
|
|
162
|
-
* @typedef centerIdringIdRadiusPaddingRgbaHide
|
|
163
|
-
* @property {String} centerID
|
|
164
|
-
* @property {String} ringID
|
|
165
|
-
* @property {Number} radius
|
|
166
|
-
* @property {Number} padding
|
|
167
|
-
* @property {Array<Number>} rgba - [r,g,b,a]
|
|
168
|
-
* @param {Array<centerIdringIdRadiusPaddingRgbaHide>} centerIdringIdRadiusPaddingRgbaHideList
|
|
169
|
-
* */
|
|
170
|
-
insertRings(centerIdringIdRadiusPaddingRgbaHideList) {
|
|
171
|
-
{ // capacity check
|
|
172
|
-
this._implicitExtendBufferInNeed(centerIdringIdRadiusPaddingRgbaHideList.length);
|
|
173
|
-
}
|
|
174
|
-
const { gl, buffer } = this;
|
|
175
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
176
|
-
for (let { centerID, ringID, radius, padding, rgba, hide = false } of centerIdringIdRadiusPaddingRgbaHideList) {
|
|
177
|
-
if (!this._centerMap.has(centerID)) {
|
|
178
|
-
console.warn("Center is not registered yet");
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
const x = this._centerMap.get(centerID).get("x");
|
|
182
|
-
const y = this._centerMap.get(centerID).get("y");
|
|
183
|
-
const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide ? 1 : 0]);
|
|
184
|
-
const key = this._ringKey(centerID, ringID);
|
|
185
|
-
let offset;
|
|
186
|
-
if (!this._ringOffsets.has(key)) {
|
|
187
|
-
offset = this._nextBufferOffset();
|
|
188
|
-
this._ringOffsets.set(key, offset);
|
|
189
|
-
this._centerMap.get(centerID).get("rings").push(key);
|
|
190
|
-
} else {
|
|
191
|
-
offset = this._ringOffsets.get(key);
|
|
192
|
-
}
|
|
193
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
194
|
-
}
|
|
195
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
196
|
-
this.globe.DrawRender();
|
|
197
|
-
}
|
|
198
169
|
|
|
199
170
|
|
|
200
|
-
/**
|
|
201
|
-
* @typedef centerIDringID
|
|
202
|
-
* @property {String} centerID
|
|
203
|
-
* @property {String} ringID
|
|
204
|
-
* @param {Array<centerIDringID>} centerIDringIDs
|
|
205
|
-
* @returns
|
|
206
|
-
*/
|
|
207
|
-
removeRings(centerIDringIDs) {
|
|
208
|
-
const { gl, buffer } = this;
|
|
209
|
-
const zero = new Float32Array([0]);
|
|
210
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
211
|
-
for (let { centerID, ringID } of centerIDringIDs) {
|
|
212
|
-
if (!this._centerMap.has(centerID)) {
|
|
213
|
-
console.warn("Center is not registered yet");
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const key = this._ringKey(centerID, ringID);
|
|
217
|
-
if (!this._ringOffsets.has(key)) {
|
|
218
|
-
console.warn("Ring is not registered yet");
|
|
219
|
-
return;
|
|
220
|
-
}
|
|
221
|
-
const offset = this._ringOffsets.get(key);
|
|
222
|
-
this._removedRingsOffsetStack.push(offset);
|
|
223
|
-
this._ringOffsets.delete(key);
|
|
224
|
-
// set range to 0, 3rd index of float32array
|
|
225
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, offset + 8, zero);
|
|
226
|
-
this._centerMap.get(centerID).get("rings").splice(this._centerMap.get(centerID).get("rings").indexOf(key), 1);
|
|
227
|
-
this._ringCounter--;
|
|
228
|
-
}
|
|
229
|
-
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
230
|
-
this.globe.DrawRender();
|
|
231
|
-
}
|
|
232
|
-
|
|
233
171
|
/**
|
|
234
172
|
* @param {Array<string>} centerIDs
|
|
235
173
|
* */
|
|
@@ -239,8 +177,9 @@ export default class {
|
|
|
239
177
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
240
178
|
for (let centerID of centerIDs) {
|
|
241
179
|
if (!this._centerMap.has(centerID)) {
|
|
242
|
-
console.warn("Center is not registered yet");
|
|
243
|
-
return;
|
|
180
|
+
// console.warn("Center is not registered yet");
|
|
181
|
+
// return;
|
|
182
|
+
continue;
|
|
244
183
|
}
|
|
245
184
|
const center = this._centerMap.get(centerID);
|
|
246
185
|
const rings = center.get("rings");
|
|
@@ -260,10 +199,10 @@ export default class {
|
|
|
260
199
|
|
|
261
200
|
|
|
262
201
|
/**
|
|
263
|
-
*
|
|
202
|
+
*
|
|
264
203
|
* @property {String} centerID
|
|
265
|
-
* @property {Number} x
|
|
266
|
-
* @property {Number} y
|
|
204
|
+
* @property {Number} x radians x
|
|
205
|
+
* @property {Number} y radians y
|
|
267
206
|
* @param {*} centerIDxyList
|
|
268
207
|
*/
|
|
269
208
|
updateCentersXY(centerIDxyList) {
|
|
@@ -282,10 +221,23 @@ export default class {
|
|
|
282
221
|
}
|
|
283
222
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
284
223
|
this.globe.DrawRender();
|
|
285
|
-
|
|
286
224
|
}
|
|
287
225
|
|
|
288
226
|
|
|
227
|
+
updateCentersHide(data) {
|
|
228
|
+
const { gl, buffer } = this;
|
|
229
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
230
|
+
for (let { centerID, hide } of data) {
|
|
231
|
+
const rings = this._centerMap.get(centerID).get("rings");
|
|
232
|
+
for (let i = 0; i < rings.length; i++) {
|
|
233
|
+
const offset = this._ringOffsets.get(rings[i]);
|
|
234
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + 32, new Float32Array([hide]));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
238
|
+
this.globe.DrawRender();
|
|
239
|
+
}
|
|
240
|
+
|
|
289
241
|
/**
|
|
290
242
|
*
|
|
291
243
|
* @typedef centerData
|
|
@@ -312,10 +264,19 @@ export default class {
|
|
|
312
264
|
this.globe.DrawRender();
|
|
313
265
|
}
|
|
314
266
|
|
|
315
|
-
|
|
316
|
-
|
|
317
267
|
insertBulk(rangeRingDatas) {
|
|
318
268
|
const { gl, buffer } = this;
|
|
269
|
+
|
|
270
|
+
{// remove existring centers
|
|
271
|
+
const existingCenterIDs = [];
|
|
272
|
+
for (let { centerID } of rangeRingDatas) {
|
|
273
|
+
if (this._centerMap.has(centerID)) {
|
|
274
|
+
existingCenterIDs.push(centerID);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
this.removeCenters(existingCenterIDs);
|
|
278
|
+
}
|
|
279
|
+
|
|
319
280
|
{ // capacity check
|
|
320
281
|
let incomingRingSize = 0;
|
|
321
282
|
for (let { rings } of rangeRingDatas) {
|
|
@@ -325,19 +286,19 @@ export default class {
|
|
|
325
286
|
}
|
|
326
287
|
this._implicitExtendBufferInNeed(incomingRingSize);
|
|
327
288
|
}
|
|
328
|
-
|
|
329
289
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
330
290
|
for (let { centerID, x, y, rings } of rangeRingDatas) {
|
|
331
|
-
if (!this._centerMap.has(centerID)) {
|
|
332
|
-
|
|
333
|
-
} else {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
291
|
+
// if (!this._centerMap.has(centerID)) {
|
|
292
|
+
this.registerCenter(centerID, { x, y })
|
|
293
|
+
// } else {
|
|
294
|
+
// const rings = this._centerMap.get(centerID).get("rings");
|
|
295
|
+
// const xy = new Float32Array([x, y]);
|
|
296
|
+
// const emptyBlock =
|
|
297
|
+
// for (let i = 0; i < rings.length; i++) {
|
|
298
|
+
// const offset = this._ringOffsets.get(rings[i]);
|
|
299
|
+
// gl.bufferSubData(gl.ARRAY_BUFFER, offset, );
|
|
300
|
+
// }
|
|
301
|
+
// }
|
|
341
302
|
for (let { ringID, radius, padding, rgba, hide = false } of rings) {
|
|
342
303
|
const key = this._ringKey(centerID, ringID);
|
|
343
304
|
const bufferData = new Float32Array([x, y, radius, padding, ...rgba, hide ? 1 : 0]);
|
|
@@ -350,10 +311,8 @@ export default class {
|
|
|
350
311
|
} else {
|
|
351
312
|
const offset = this._ringOffsets.get(key);
|
|
352
313
|
gl.bufferSubData(gl.ARRAY_BUFFER, offset, bufferData);
|
|
353
|
-
|
|
354
314
|
}
|
|
355
315
|
}
|
|
356
|
-
|
|
357
316
|
}
|
|
358
317
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
359
318
|
this.globe.DrawRender();
|
|
@@ -388,7 +347,7 @@ export default class {
|
|
|
388
347
|
*
|
|
389
348
|
* @param {Array<{centerID, rgba}} centersColors
|
|
390
349
|
*/
|
|
391
|
-
|
|
350
|
+
updateCentersColor(centersColors) {
|
|
392
351
|
const { gl, buffer } = this;
|
|
393
352
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
394
353
|
for (let { centerID, rgba } of centersColors) {
|
|
@@ -461,7 +420,6 @@ export default class {
|
|
|
461
420
|
|
|
462
421
|
|
|
463
422
|
_implicitExtendBufferInNeed(incomingRingSize) {
|
|
464
|
-
console.log("implicitExtendBufferInNeed", { incomingRingSize, "capacity left": this.capacityLeft(), "capacity": this._capacity, "ring counter": this._ringCounter });
|
|
465
423
|
const overCapacity = incomingRingSize - this.capacityLeft();
|
|
466
424
|
if (overCapacity <= 0) return;
|
|
467
425
|
const newCapacity = Math.ceil((this._capacity + overCapacity) * this.implicitExtentionRate);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import CircleFlatProgram from './circleflatprogram';
|
|
2
2
|
import PaddyFlatProgram from './paddyflatprogram';
|
|
3
3
|
import CirclePaddySharedBuffer from './circlepaddysharedbuffer';
|
|
4
|
-
|
|
5
|
-
export
|
|
4
|
+
import { PaddingFreeAngleCache } from './circlepaddingfreeangleprogram';
|
|
5
|
+
export { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer, PaddingFreeAngleCache };
|
|
@@ -28,8 +28,11 @@ out vec4 v_color;
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
void main() {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
|
|
32
|
+
float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
|
|
33
|
+
if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
|
|
34
|
+
v_color = vec4(color.rgb, alpha_padding);
|
|
35
|
+
|
|
33
36
|
gl_PointSize = 2.0;
|
|
34
37
|
|
|
35
38
|
float odd = mod(float(gl_VertexID), 2.0);
|
package/rangerings/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import RangeRings from './rangerings';
|
|
1
|
+
import RangeRings, { ENUM_HIDE } from './rangerings';
|
|
2
2
|
|
|
3
|
-
export { RangeRings };
|
|
3
|
+
export { RangeRings, ENUM_HIDE };
|
package/rangerings/rangerings.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { rings } from "../programs";
|
|
2
2
|
|
|
3
|
+
import { PaddingFreeAngleCache } from "../programs/rings/distancering";
|
|
3
4
|
const { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer } = rings;
|
|
4
5
|
|
|
5
6
|
|
|
@@ -16,27 +17,31 @@ const { CircleFlatProgram, PaddyFlatProgram, CirclePaddySharedBuffer } = rings;
|
|
|
16
17
|
*
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
* Boylelikle bir pluginin iki bufferManageri yonetmesi gerekmez.
|
|
23
|
-
*/
|
|
20
|
+
|
|
21
|
+
export const ENUM_HIDE = Object.freeze({ SHOW: 0, HIDE: 1, HIDE_1_DEGREE_PADDINGS: 2 });
|
|
22
|
+
|
|
24
23
|
|
|
25
24
|
export default class {
|
|
26
25
|
|
|
27
|
-
constructor(id,
|
|
26
|
+
constructor(id, paddingOn = true, compass = 1, circleEdgeCount = 360) {
|
|
28
27
|
this.id = id;
|
|
29
28
|
this.compass = compass;
|
|
30
|
-
this.padCount = padCount;
|
|
31
29
|
this.circleEdgeCount = circleEdgeCount;
|
|
30
|
+
this._paddingOn = paddingOn;
|
|
32
31
|
this.bufferManager = null;
|
|
33
32
|
}
|
|
34
33
|
|
|
34
|
+
setPaddingOn(paddingOn) {
|
|
35
|
+
this._paddingOn = paddingOn;
|
|
36
|
+
}
|
|
37
|
+
|
|
35
38
|
init(globe, gl) {
|
|
36
39
|
this.gl = gl;
|
|
37
40
|
this.globe = globe;
|
|
38
41
|
this.circleFlatProgram = new CircleFlatProgram(globe, gl);
|
|
39
42
|
this.paddyFlatProgram = new PaddyFlatProgram(globe, gl);
|
|
43
|
+
|
|
44
|
+
this.paddingFreeAngleProgram = PaddingFreeAngleCache.getProgram(globe);
|
|
40
45
|
}
|
|
41
46
|
|
|
42
47
|
free() {
|
|
@@ -49,14 +54,16 @@ export default class {
|
|
|
49
54
|
|
|
50
55
|
|
|
51
56
|
draw3D() {
|
|
52
|
-
const { circleFlatProgram, paddyFlatProgram, padCount, bufferManager, compass, gl, circleEdgeCount } = this;
|
|
57
|
+
const { circleFlatProgram, paddyFlatProgram, padCount, paddingFreeAngleProgram, bufferManager, compass, gl, circleEdgeCount, paddingBufferManager } = this;
|
|
53
58
|
// if (globe.api_GetCurrentGeometry() === 0) return; // do not draw in 3D mode
|
|
54
59
|
if (this.bufferManager !== null && bufferManager.length > 0) {
|
|
55
60
|
gl.disable(gl.DEPTH_TEST);
|
|
56
61
|
// gl.enable(gl.BLEND);
|
|
57
62
|
// gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
|
|
58
63
|
circleFlatProgram.draw(bufferManager, compass, circleEdgeCount);
|
|
59
|
-
paddyFlatProgram.draw(bufferManager,
|
|
64
|
+
if (this._paddingOn) paddyFlatProgram.draw(bufferManager, 360, compass);
|
|
65
|
+
paddingFreeAngleProgram.draw(paddingBufferManager, compass);
|
|
66
|
+
|
|
60
67
|
gl.enable(gl.DEPTH_TEST);
|
|
61
68
|
}
|
|
62
69
|
}
|
|
@@ -77,12 +84,84 @@ export default class {
|
|
|
77
84
|
initilizeBufferManager(initialRingCapacity, bufferDrawType) {
|
|
78
85
|
const { gl, globe } = this
|
|
79
86
|
this.bufferDrawType = bufferDrawType;
|
|
80
|
-
this.bufferManager = new CirclePaddySharedBuffer(gl, globe, { bufferType:
|
|
81
|
-
|
|
87
|
+
this.bufferManager = new CirclePaddySharedBuffer(gl, globe, { bufferType: bufferDrawType, initialRingCapacity: initialRingCapacity });
|
|
88
|
+
this.paddingBufferManager = this.paddingFreeAngleProgram.initilizeBufferManager({ bufferType: bufferDrawType, initialRingCapacity });
|
|
82
89
|
}
|
|
83
90
|
|
|
84
|
-
getBufferManager() {
|
|
85
|
-
|
|
91
|
+
// getBufferManager() {
|
|
92
|
+
// return this.bufferManager;
|
|
93
|
+
// }
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @typedef {Array<{ringID, radius, paddingRange}>} rings
|
|
99
|
+
* @param {Array<centerID:string, x:number, y:number, paddingAngles:Array<number>, rgba:[4number], rings:rings} items
|
|
100
|
+
*/
|
|
101
|
+
insertBulk(items) {
|
|
102
|
+
const insertData = ringItemsToCircleBufferInsertDataAdaptor(items);
|
|
103
|
+
|
|
104
|
+
this.bufferManager.insertBulk(insertData);
|
|
105
|
+
this.paddingBufferManager.insertBulk(items);
|
|
106
|
+
this.globe.DrawRender();
|
|
86
107
|
}
|
|
87
108
|
|
|
88
|
-
|
|
109
|
+
|
|
110
|
+
updateCentersXY(items) {
|
|
111
|
+
this.bufferManager.updateCentersXY(items);
|
|
112
|
+
this.paddingBufferManager.updateCentersXY(items);
|
|
113
|
+
this.globe.DrawRender();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
updateCentersColor(centerColors) {
|
|
118
|
+
this.bufferManager.updateCentersColor(centerColors);
|
|
119
|
+
this.paddingBufferManager.updateCentersColor(centerColors);
|
|
120
|
+
this.globe.DrawRender();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
// TODO: test
|
|
125
|
+
removeCenters(centerIds) {
|
|
126
|
+
|
|
127
|
+
this.bufferManager.removeCenters(centerIds);
|
|
128
|
+
this.paddingBufferManager.removeCenters(centerIds);
|
|
129
|
+
// this.bufferManager.defrag();
|
|
130
|
+
// this.paddingBufferManager.defrag();
|
|
131
|
+
this.globe.DrawRender();
|
|
132
|
+
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
//TODO: test
|
|
136
|
+
updateCentersHide(centerHides) {
|
|
137
|
+
this.bufferManager.updateCentersHide(centerHides);
|
|
138
|
+
this.paddingBufferManager.updateCentersHide(centerHides);
|
|
139
|
+
this.globe.DrawRender();
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
const ringItemsToCircleBufferInsertDataAdaptor = (ringItems) => {
|
|
145
|
+
|
|
146
|
+
const result = [];
|
|
147
|
+
for (const { centerID, x, y, paddingAngles, rgba, rings, hide = 0 } of ringItems) {
|
|
148
|
+
const resultRings = [];
|
|
149
|
+
for (const { ringID, radius, padding } of rings) {
|
|
150
|
+
resultRings.push({
|
|
151
|
+
ringID,
|
|
152
|
+
radius,
|
|
153
|
+
padding: padding / 7,
|
|
154
|
+
rgba,
|
|
155
|
+
hide
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
result.push({
|
|
160
|
+
centerID,
|
|
161
|
+
x,
|
|
162
|
+
y,
|
|
163
|
+
rings: resultRings
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
return result;
|
|
167
|
+
};
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
*/
|
|
20
20
|
|
|
21
21
|
export default class {
|
|
22
|
-
constructor(itemSize, { capacity = 10 }) {
|
|
22
|
+
constructor(itemSize, { capacity = 10, bufferType = "STATIC_DRAW" } = {}) {
|
|
23
23
|
this.itemSize = itemSize;
|
|
24
|
-
|
|
24
|
+
this.bufferType = bufferType;
|
|
25
25
|
this.offSetMap = new Map();
|
|
26
26
|
this.tombstoneOffSet = [];
|
|
27
27
|
this._capacity = capacity;
|
|
@@ -46,8 +46,9 @@ export default class {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
nextOffset() {
|
|
49
|
-
if (this.tombstoneOffSet.
|
|
50
|
-
|
|
49
|
+
if (this.tombstoneOffSet.length > 0) {
|
|
50
|
+
const offset = this.tombstoneOffSet.pop();
|
|
51
|
+
return offset;
|
|
51
52
|
}
|
|
52
53
|
if (this._length < this._capacity) {
|
|
53
54
|
return this._length++ * this.itemSize * 4;
|
|
@@ -55,8 +56,12 @@ export default class {
|
|
|
55
56
|
return false;
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
spaceLeft() {
|
|
59
|
-
return this._capacity - this._length;
|
|
59
|
+
get spaceLeft() {
|
|
60
|
+
return this._capacity - (this._length - this.tombstoneOffSet.length);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get itemCount() {
|
|
64
|
+
return this._length - this.tombstoneOffSet.length;
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
deleteFromAccount(key) {
|
|
@@ -76,43 +81,47 @@ export default class {
|
|
|
76
81
|
return this.offSetMap.entries();
|
|
77
82
|
}
|
|
78
83
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
84
|
+
// TODO: this is broken
|
|
85
|
+
defrag(newCapacity = null) {
|
|
86
|
+
const { gl, buffer, bufferType } = this;
|
|
87
|
+
if (gl === undefined || buffer === undefined || bufferType === undefined) {
|
|
88
|
+
throw new Error("gl, buffer, bufferType are required");
|
|
89
|
+
}
|
|
82
90
|
const itemSize = this.itemSize;
|
|
83
|
-
const itemCount = this.
|
|
91
|
+
const itemCount = this.itemCount;
|
|
84
92
|
const capacity = (newCapacity && newCapacity > itemCount) ? newCapacity : itemCount;
|
|
85
93
|
|
|
86
|
-
const bufferData = this._getBufferData();
|
|
87
94
|
|
|
88
95
|
const newArray = new Float32Array(itemCount * itemSize);
|
|
89
96
|
|
|
97
|
+
const bufferData = this._getBufferData();
|
|
90
98
|
let newOffSet = 0;
|
|
99
|
+
const newOffSetMap = new Map();
|
|
91
100
|
for (const [key, offSet] of this.offSetMap) {
|
|
92
101
|
const itemOffSet = offSet / 4;
|
|
93
102
|
newArray.set(bufferData.slice(itemOffSet, itemOffSet + itemSize), newOffSet);
|
|
94
|
-
this.offSetMap.set(key, newOffSet * 4);
|
|
103
|
+
// this.offSetMap.set(key, newOffSet * 4);
|
|
104
|
+
newOffSetMap.set(key, newOffSet * 4);
|
|
95
105
|
newOffSet += itemSize;
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
gl.
|
|
108
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
99
109
|
gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
|
|
100
110
|
gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
|
|
101
111
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
102
112
|
|
|
103
113
|
this._capacity = capacity;
|
|
104
114
|
this.tombstoneOffSet = [];
|
|
115
|
+
this.offSetMap = newOffSetMap;
|
|
105
116
|
}
|
|
106
117
|
|
|
107
118
|
|
|
108
119
|
extendBuffer(gl, buffer, bufferType, newCapacity) {
|
|
109
120
|
const itemSize = this.itemSize;
|
|
110
121
|
const bufferData = this._getBufferData();
|
|
111
|
-
const newArray = new Float32Array(newCapacity * itemSize);
|
|
112
|
-
newArray.set(bufferData);
|
|
113
122
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
114
123
|
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
|
|
115
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, 0,
|
|
124
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
116
125
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
117
126
|
this._capacity = newCapacity;
|
|
118
127
|
}
|
|
@@ -151,13 +160,15 @@ export default class {
|
|
|
151
160
|
|
|
152
161
|
|
|
153
162
|
|
|
154
|
-
|
|
163
|
+
_removeFromBuffer(keys) {
|
|
164
|
+
const { gl, buffer } = this;
|
|
165
|
+
const emptyBlock = new Float32Array(this.itemSize).fill(0)
|
|
155
166
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
156
167
|
for (let key of keys) {
|
|
157
168
|
let offset = this.getOffset(key);
|
|
158
169
|
if (offset !== undefined) {
|
|
159
170
|
this.deleteFromAccount(key);
|
|
160
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, offset,
|
|
171
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, emptyBlock);
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|