@pirireis/webglobeplugins 0.2.0 → 0.3.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.
@@ -9,7 +9,7 @@ const vertexShader = `#version 300 es ` +
9
9
  shaderfunctions.R +
10
10
  shaderfunctions.POLE +
11
11
  CameraUniformBlockString +
12
- shaderfunctions.mercatorXYTo2DPoint +
12
+ shaderfunctions.mercatorXYToGLPosition +
13
13
  shaderfunctions.longLatRadToMercator +
14
14
  shaderfunctions.longLatRadToCartesian3D +
15
15
  shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
@@ -56,7 +56,7 @@ void main() {
56
56
  limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
57
57
  }
58
58
  v_limp = limp;
59
- gl_Position = mercatorXYTo2DPoint(limp);
59
+ gl_Position = mercatorXYToGLPosition(limp);
60
60
  }`;
61
61
 
62
62
  const fragmentShader = `#version 300 es
@@ -7,7 +7,7 @@ const vertexShader = `#version 300 es ` +
7
7
  shaderfunctions.R +
8
8
  shaderfunctions.POLE +
9
9
  CameraUniformBlockString +
10
- shaderfunctions.mercatorXYTo2DPoint +
10
+ shaderfunctions.mercatorXYToGLPosition +
11
11
  shaderfunctions.longLatRadToMercator +
12
12
  shaderfunctions.longLatRadToCartesian3D +
13
13
  shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
@@ -58,7 +58,7 @@ void main() {
58
58
  limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
59
59
  }
60
60
  v_limp = limp;
61
- gl_Position = mercatorXYTo2DPoint(limp);
61
+ gl_Position = mercatorXYToGLPosition(limp);
62
62
  }`;
63
63
 
64
64
  const fragmentShader = `#version 300 es
@@ -1,3 +1,6 @@
1
+ import { globeProgramCache } from "../programcache";
2
+
3
+
1
4
  export const CameraUniformBlockString = `
2
5
  layout(std140) uniform CameraUniformBlock {
3
6
  mat4 view; // 64 bytes 0
@@ -126,3 +129,9 @@ export default class
126
129
  }
127
130
  }
128
131
  }
132
+
133
+
134
+ export const CameraUniformBlockTotemCache = Object.freeze({
135
+ get: (globe) => { return globeProgramCache.getProgram(globe, CameraUniformBlockTotem) },
136
+ release: (globe) => { return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem) }
137
+ });
@@ -1,2 +1,2 @@
1
- import CameraUniformBlockTotem, { CameraUniformBlockString } from "./camerauniformblock";
2
- export { CameraUniformBlockTotem, CameraUniformBlockString };
1
+ import CameraUniformBlockTotem, { CameraUniformBlockString, CameraUniformBlockTotemCache } from "./camerauniformblock";
2
+ export { CameraUniformBlockTotem, CameraUniformBlockString, CameraUniformBlockTotemCache };
@@ -87,8 +87,6 @@ export default class {
87
87
  const { circleFlatProgram, paddyFlatProgram, paddingFreeAngleProgram, bufferManager, compass, gl, circleEdgeCount, paddingBufferManager, _opacity } = this;
88
88
  if (this.bufferManager !== null && bufferManager.length > 0) {
89
89
  gl.disable(gl.DEPTH_TEST);
90
- // gl.enable(gl.BLEND);
91
- // gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
92
90
  console.log("the opacity", _opacity);
93
91
  circleFlatProgram.draw(bufferManager, compass, circleEdgeCount, _opacity);
94
92
  if (this._onedegreepaddingOn) paddyFlatProgram.draw(bufferManager, 360, compass, _opacity);
@@ -89,7 +89,6 @@ export default class {
89
89
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
90
90
  }
91
91
 
92
-
93
92
  offsetMapIterator() { // can be used for defraging the real buffer.
94
93
  return this.offSetMap.entries();
95
94
  }
@@ -1,3 +1,7 @@
1
1
  import BufferOffsetManager from './bufferoffsetmanager.js';
2
2
 
3
- export { BufferOffsetManager };
3
+ export { BufferOffsetManager };
4
+
5
+
6
+
7
+ export * from './single-attribute-buffer-management';
@@ -0,0 +1,119 @@
1
+ /**
2
+ * BufferOffsetManager
3
+ * Purpose: To manage the offset of the buffer. Plus extend and defrag the buffer.
4
+ * ------------------------------------------------------------------------------------------------------------------------------------------- * Functions:
5
+ * 1. getOffet(key) : return the offset of the key if not found return false.
6
+ * 2. setOffset(key, offset) : set the offset of the key.
7
+ * 3. nextOffset() : return the next available offset if not return false.
8
+ * 4. delete(key) : delete the key and return true if not found return false.
9
+ * 5. defragBuffer(gl, buffer, bufferType, newCapacity = null) : defrag the buffer. if newCapacity is not provided the buffer is vacumed.
10
+ * 6. extendBuffer(gl, buffer, bufferType, newCapacity) : extend the buffer.
11
+ * -------------------------------------------------------------------------------------------------------------------------------------------
12
+ * What this class does NOT do:
13
+ * ADD, DELETE, READ
14
+ * ADD, inputs needs to be turn into a block and put into buffer. Bulk will be more performant.
15
+ * DELETE, might be a set to single byte to indicate the tombstone.
16
+ * READ, most of the time is not needed to be read, unless for defraging.
17
+ * This unpredicatable behavior is not handled by this class.
18
+ */
19
+
20
+ export class BufferManager {
21
+ constructor(gl, itemSize, { bufferType = "STATIC_DRAW", buffer = null, initialCapacity = null } = {}) {
22
+ this.gl = gl;
23
+ this.itemSize = itemSize;
24
+ this.bufferType = bufferType;
25
+ this.buffer = buffer === null ? gl.createBuffer() : buffer;
26
+ if (initialCapacity !== null) this.resetWithCapacity(initialCapacity);
27
+ }
28
+
29
+ resetWithCapacity(capacity) {
30
+ const { gl, buffer, bufferType, itemSize } = this;
31
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
32
+ gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
33
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
34
+ }
35
+
36
+ deleteBulk(offsets) {
37
+ const { gl, buffer, itemSize } = this;
38
+ const emptyBlock = new Float32Array(this.itemSize).fill(0)
39
+ const offsetMultiplier = itemSize * 4;
40
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
41
+ for (let offset of offsets) {
42
+ if (offset !== undefined) {
43
+
44
+ gl.bufferSubData(gl.ARRAY_BUFFER, offset * offsetMultiplier, emptyBlock);
45
+ }
46
+ }
47
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
48
+ }
49
+
50
+
51
+ insertBulk(blocks, offsets) {
52
+ const { gl, buffer, itemSize } = this;
53
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
54
+ const offsetMultiplier = itemSize * 4;
55
+ for (let i = 0; i < blocks.length; i++) {
56
+ const block = blocks[i];
57
+ const offset = offsets[i] * offsetMultiplier;
58
+ if (offset !== undefined) gl.bufferSubData(gl.ARRAY_BUFFER, offset, block);
59
+ }
60
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
61
+ }
62
+
63
+
64
+ // TODO: this is broken
65
+ defrag(offsetValues, occupiedCapacity, newCapacity) {
66
+ const { gl, buffer, bufferType, itemSize } = this;
67
+
68
+ const newArray = new Float32Array(newCapacity * itemSize);
69
+ const bufferData = this._getBufferData(occupiedCapacity);
70
+ console.log("bufferData", bufferData);
71
+ let newOffset = 0;
72
+ for (const offset of offsetValues) {
73
+ const itemOffset = offset * itemSize;
74
+ newArray.set(bufferData.slice(itemOffset, itemOffset + itemSize), newOffset);
75
+ console.log("oldOffset", itemOffset, "newOffset", newOffset);
76
+ newOffset += itemSize;
77
+ }
78
+
79
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
80
+ gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
81
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
82
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
83
+
84
+ }
85
+
86
+ extendBuffer(occupiedCapacity, newCapacity) {
87
+ const { gl, buffer, bufferType } = this;
88
+ const itemSize = this.itemSize;
89
+ const bufferData = this._getBufferData(occupiedCapacity);
90
+ console.log("extending buffer from", occupiedCapacity, "to", newCapacity, 'item size', itemSize);
91
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
92
+ gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
93
+ gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
94
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
95
+ }
96
+
97
+ _getBufferData(occupiedCapacity) {
98
+ const { gl, buffer } = this;
99
+ console.log(occupiedCapacity, this.itemSize)
100
+ const size = occupiedCapacity * this.itemSize;
101
+ console.log("size", size);
102
+ const bufferData = new Float32Array(size);
103
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
104
+ gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
105
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
106
+ return bufferData;
107
+ }
108
+
109
+ free() {
110
+ if (this.isFreed) return;
111
+ this.gl.deleteBuffer(this.buffer);
112
+ this.buffer = null;
113
+ this.gl = null;
114
+ this.isFreed = true;
115
+ }
116
+ }
117
+
118
+
119
+
@@ -0,0 +1,256 @@
1
+
2
+
3
+ /**
4
+ * OffsetManager
5
+ * 1) Capacity
6
+ * 2) Offset account
7
+ * 3) Command Buffers in its regisration list.
8
+ *
9
+ * How insertBulk works:
10
+ * 0) autoExtendBuffers..
11
+ * 1) assign offset to all keys if not already assigned.
12
+ * 2) send item list to each buffer manager and let them do their job.
13
+ * This cannot work. BufferManager does not know the which data to insert.
14
+ * Solutions:
15
+ * 1) selectMethod: insertBulk(items, offsets, selectMethod)
16
+ * selectMethod(item) => itemToBlock(item)
17
+ * 2) att1manager.insertBulk(items.map(item => this.att1ItemToBlock(item)), offsets)
18
+ * Idea about future:
19
+ * insert first tombstone.length items one by one.
20
+ * insert the rest in a big float32array. IT CAN BE DONE
21
+ * 3) DrawRender
22
+ *
23
+ * How autoExtendBuffers works:
24
+ * 1) if incoming items length is greater then space left in buffer, calculate new capacity and extend all buffers.
25
+ *
26
+ *
27
+
28
+ */
29
+
30
+
31
+
32
+ /**
33
+ * Scratchpad
34
+ *
35
+ * plugin insertBulk(items){
36
+ * this.offsetManager.autoExtendBuffers(items.length);
37
+ * this.offsetManager.assignOffsets(items); // read item.keys and assign offsets to them.
38
+ * this.attrib1BufferManager.insertBulk(items.map(item => this.attrib1Block(item)), );
39
+ * this.attrib2BufferManager.insertBulk();
40
+ * if (this.attrib3isInNeed) this.attrib3BufferManager.insertBulk(items);
41
+ * this.globe.DrawRender();
42
+ * }
43
+ *
44
+ * useTheCaseThatRequiresAttrib3(){
45
+ * // generate items from other buffers if possible.
46
+ * }
47
+ *
48
+ *
49
+ * assignOffsets(items){
50
+ * for (const item of items){
51
+ * const offset = this.offsetManager.getOffset(item.key) || this.offsetManager.nextOffset();
52
+ * item.__offset__ = offset;
53
+ *
54
+ * allBuffers = [attrib1BufferManager, attrib2BufferManager, attrib3BufferManager]
55
+ * // // not single responsibility ..
56
+ * defrag(allBuffers){
57
+ * for (const bufferManager of allBuffers){
58
+ * bufferManager.defrag(this.offsetManager.offsetMap);
59
+ * }
60
+ * this.offsetManager._defrag();
61
+ * }
62
+ *
63
+ */
64
+
65
+
66
+ /**
67
+ *
68
+ * attrib1BufferManager.insertBulk( items) {
69
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
70
+ * for (const item of items) {
71
+ * const block = this.itemToBlock(item); // this changes based on inserted data structure and expected block structure.
72
+ * gl.bufferSubData(gl.ARRAY_BUFFER, item.__offset__, block);
73
+ * }
74
+ * gl.bindBuffer(gl.ARRAY_BUFFER, null);
75
+ * }
76
+ *
77
+ * deleteBulk(offsets){
78
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
79
+ * for (const offset of offsets) {
80
+ * gl.bufferSubData(gl.ARRAY_BUFFER, offset, emptyBlock);
81
+ * }
82
+ * gl.bindBuffer(gl.ARRAY_BUFFER, null);
83
+ * }
84
+ *
85
+ *
86
+ * //
87
+ * defrag(offsetMap){
88
+ * const newArray = new Float32Array(itemCount * itemSize);
89
+ * const bufferData = this._getBufferData();
90
+ * let newOffSet = 0;
91
+ * for (const [key, offSet] of offsetMap) {
92
+ * const bufferOffset = offset;
93
+ * newArray.set(bufferData.slice(bufferOffset, bufferOffset + itemSize), newOffSet);
94
+ newOffset += itemSize * 4;
95
+ }
96
+ *
97
+ * gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
98
+ *
99
+ * }
100
+ *
101
+ * ----------------
102
+
103
+ */
104
+
105
+ export class BufferOrchestrator {
106
+
107
+ constructor({ capacity = 10 } = {}) {
108
+ this._capacity = capacity;
109
+ this.offsetMap = new Map();
110
+ this.tombstoneOffsets = [];
111
+ this._length = 0;
112
+ }
113
+
114
+
115
+ resetWithCapacity(bufferManagersMap, capacity = null) {
116
+ this._capacity = capacity !== null ? capacity : this._capacity;
117
+ for (const [key, { bufferManager }] of bufferManagersMap) {
118
+ bufferManager.resetWithCapacity(this._capacity);
119
+ }
120
+ this.offsetMap.clear();
121
+ this.tombstoneOffsets = [];
122
+ this._length = 0;
123
+ }
124
+
125
+ insertBulk(items, bufferManagersMap) {
126
+ this.autoExtendBuffers(items.length, bufferManagersMap);
127
+ const { offsetMap } = this;
128
+ const offsets = [];
129
+ for (const item of items) {
130
+ const offset = offsetMap.get(item.key) || this.nextOffset();
131
+ offsetMap.set(item.key, offset);
132
+ offsets.push(offset);
133
+ }
134
+ for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
135
+ bufferManager.insertBulk(items.map(adaptor), offsets);
136
+ }
137
+ }
138
+
139
+
140
+ // doesnot assign offset to the new items.
141
+ updateBulk(items, bufferManagersMap, bufferKeys) {
142
+ const { offsetMap } = this;
143
+ const offsets = [];
144
+ for (const item of items) {
145
+ const offset = offsetMap.get(item.key);
146
+ offsets.push(offset);
147
+ }
148
+ if (bufferKeys) {
149
+ for (const key of bufferKeys) {
150
+ const { bufferManager, adaptor } = bufferManagersMap.get(key);
151
+ bufferManager.insertBulk(items.map(adaptor), offsets);
152
+ }
153
+ } else {
154
+ for (const [key, { bufferManager, adaptor }] of bufferManagersMap) {
155
+ bufferManager.insertBulk(items.map(adaptor), offsets);
156
+ }
157
+ }
158
+
159
+ }
160
+
161
+
162
+ deleteBulk(keys, bufferManagersMap) {
163
+ const offsets = [];
164
+ for (const key of keys) {
165
+ const offset = this.getOffset(key);
166
+ if (offset !== undefined) {
167
+ offsets.push(offset);
168
+ this.offsetMap.delete(key);
169
+ this.tombstoneOffsets.push(offset);
170
+ }
171
+ }
172
+ for (const [key, { bufferManager }] of bufferManagersMap) {
173
+ bufferManager.deleteBulk(offsets);
174
+ }
175
+ console.log("deleteBulk after item size", this.offsetMap.size);
176
+ }
177
+
178
+
179
+
180
+ getOffset(key) {
181
+ return this.offsetMap.get(key);
182
+ }
183
+
184
+ nextOffset() {
185
+ if (this.tombstoneOffsets.length > 0) {
186
+ const offset = this.tombstoneOffsets.pop();
187
+ return offset;
188
+ }
189
+ if (this._length < this._capacity) {
190
+ return this._length++;
191
+ }
192
+ return false;
193
+ }
194
+
195
+
196
+ autoExtendBuffers(itemsLength, bufferManagersMap) {
197
+ if (itemsLength <= this.emptySpace) return;
198
+ const newCapacity = this.length + itemsLength;
199
+ console.log("autoExtendBuffers", "item L", itemsLength, "E space", this.emptySpace, "cap", this.capacity, "length", this.length, 'new Cap', newCapacity);
200
+ for (const [key, { bufferManager }] of bufferManagersMap) {
201
+ console.log("length", this.length, "newCapacity", newCapacity);
202
+ bufferManager.extendBuffer(this.length, newCapacity);
203
+ }
204
+ this._capacity = newCapacity;
205
+ }
206
+
207
+
208
+ defrag(bufferManagers, bufferKeys) { // TODO defrag and leave some empty space
209
+ const offsetMap = this.offsetMap;
210
+ console.log("defrag size", offsetMap.size, "cap", this.capacity, "length", this.length);
211
+ if (bufferKeys) {
212
+ for (const key of bufferKeys) {
213
+ const offset = offsetMap.get(key);
214
+ if (offset !== undefined) {
215
+ for (const [key, { bufferManager }] of bufferManagers) {
216
+ bufferManager.defrag([offset], this.length, offsetMap.size);
217
+ }
218
+ }
219
+ }
220
+ } else {
221
+ for (const [key, { bufferManager }] of bufferManagers) {
222
+ bufferManager.defrag(offsetMap.values(), this.length, offsetMap.size);
223
+ }
224
+ }
225
+ this._defrag();
226
+ this._length = this._capacity = offsetMap.size;
227
+ this.tombstoneOffsets = [];
228
+ }
229
+
230
+
231
+
232
+ _defrag() {
233
+ const newOffsetMap = new Map();
234
+ let newOffset = 0;
235
+ for (const [key, offset] of this.offsetMap) {
236
+ console.log("defrag", key, offset, newOffset);
237
+ newOffsetMap.set(key, newOffset++);
238
+ }
239
+ this.offsetMap = newOffsetMap
240
+ }
241
+
242
+ get length() {
243
+ return this._length;
244
+ }
245
+
246
+ get emptySpace() {
247
+ return this._capacity - this.offsetMap.size;
248
+ }
249
+
250
+ get capacity() {
251
+ return this._capacity;
252
+ }
253
+ }
254
+
255
+
256
+
@@ -0,0 +1,4 @@
1
+ import { BufferOrchestrator } from "./buffer-orchestrator";
2
+ import { BufferManager } from "./buffer-manager";
3
+
4
+ export { BufferOrchestrator, BufferManager };
@@ -0,0 +1,9 @@
1
+ export const vaoAttributeLoader = (gl, buffer, position, length, stride, offset, divisor = null) => {
2
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
3
+ gl.enableVertexAttribArray(position);
4
+ gl.vertexAttribPointer(position, length, gl.FLOAT, false, stride, offset);
5
+ if (divisor !== null) {
6
+ gl.vertexAttribDivisor(position, divisor);
7
+ }
8
+
9
+ }
@@ -11,7 +11,7 @@ export const POLE = `
11
11
 
12
12
  export const R = `
13
13
  #ifndef R
14
- #define R 6378136.99911
14
+ #define R 6378137.0
15
15
  #endif
16
16
  `;
17
17
 
@@ -23,13 +23,13 @@ export const PI = `
23
23
 
24
24
  export const POLE_BY_PI = `
25
25
  #ifndef POLE_BY_PI
26
- #define POLE_BY_PI 6378136.99911
26
+ #define POLE_BY_PI 6378137.0
27
27
  #endif
28
28
  `;
29
29
 
30
30
  export const R_3D = `
31
31
  #ifndef R_3D
32
- #define R_3D 6378.137699911
32
+ #define R_3D 6378.137
33
33
  #endif
34
34
  `;
35
35
 
@@ -55,9 +55,9 @@ vec2 pixelXYToCartesian2DPoint( vec2 position, vec2 translate, vec2 mapWH, vec2
55
55
  }
56
56
  `;
57
57
 
58
-
59
- export const mercatorXYTo2DPoint = `
60
- vec4 mercatorXYTo2DPoint( vec2 position) { // projection, translate, mapWH, screenWH comes from camera uniform block
58
+ // TODO: rename it to mercatorXYToGLPosition
59
+ export const mercatorXYToGLPosition = `
60
+ vec4 mercatorXYToGLPosition( vec2 position) { // projection, translate, mapWH, screenWH comes from camera uniform block
61
61
  float x = (( position.x - translate.x ) / mapWH.x) * screenWH.x;
62
62
  float y = (1.0 - (position.y - translate.y) / mapWH.y) * screenWH.y;
63
63
  return projection * vec4(x, y, 0.0, 1.0);
@@ -220,8 +220,8 @@ float circleCircumferenceInterPolationOf2PointsRadian(vec2 center, vec2 target,
220
220
  }
221
221
  `
222
222
 
223
- export const circumferencePoints = `
224
- vec2 circumferencePoints(vec2 center, vec2 target, vec2 target2, float phase, float radius) {
223
+ const circumferencePoints = `
224
+ vec2 circumferencePoints(vec2 center, vec2 target, vec2 target2, float phase) {
225
225
  // Calculate vectors from center to target and target2
226
226
  vec2 v1 = target - center;
227
227
  vec2 v2 = target2 - center;
@@ -246,6 +246,17 @@ vec2 circumferencePoints(vec2 center, vec2 target, vec2 target2, float phase, fl
246
246
  vec2 result = vec2(cos(interpolatedAngle), sin(interpolatedAngle));
247
247
 
248
248
  // Scale back to the original circle radius and shift to center
249
- return center + radius * result;
249
+ return center + length(target - center) * result;
250
+ }
251
+ `
252
+
253
+
254
+ export const realDistanceOnSphereR1 = `
255
+ float realDistanceOnSphereR1(vec2 longLat1, vec2 longLat2) {
256
+ float dLat = longLat2.y - longLat1.y;
257
+ float dLong = longLat2.x - longLat1.x;
258
+ float a = sin(dLat / 2.0) * sin(dLat / 2.0) + cos(longLat1.y) * cos(longLat2.y) * sin(dLong / 2.0) * sin(dLong / 2.0);
259
+ float c = 2.0 * atan(sqrt(a), sqrt(1.0 - a));
260
+ return c;
250
261
  }
251
- `
262
+ `;
package/wind/plugin.js CHANGED
@@ -700,7 +700,7 @@ export default class WindPlugin {
700
700
  if (depthTest) gl.disable(gl.DEPTH_TEST);
701
701
  // if (gl.disable(gl.STENCIL_TEST); //
702
702
  this._draw();
703
- // if (depthTest) gl.enable(gl.DEPTH_TEST); // TODO: stencil
703
+ if (depthTest) gl.enable(gl.DEPTH_TEST);
704
704
 
705
705
  }
706
706
 
@@ -0,0 +1,86 @@
1
+ import { CSZMode } from "@pirireis/webglobe";
2
+
3
+ const defaultStyle = {
4
+ textFont: {
5
+ name: 'Arial',
6
+ textColor: '#FFFFFF', // beyaz
7
+ hollowColor: '#000000', // siyah
8
+ size: 12, // piksel
9
+ hollow: true,
10
+ bold: true,
11
+ italic: false,
12
+ },
13
+ opacity: 1.0,
14
+ zMode: CSZMode.Z_GROUND_PERVERTEX,
15
+ }
16
+
17
+ export class ContextTextWriter {
18
+ constructor(globe, { style = null } = {}) {
19
+ this.globe = globe;
20
+ this.itemMap = new Map();
21
+ this.style = style || defaultStyle;
22
+ }
23
+
24
+ setStyle(style) {
25
+ this.style = style;
26
+ }
27
+
28
+
29
+ draw() {
30
+ const { globe, style, itemMap } = this;
31
+ const { textFont, opacity } = style;
32
+ for (const [key, { lat, long, text }] of itemMap) {
33
+ const { x, y } = globe.api_GetScreenPointFromGeo(
34
+ {
35
+ long: long,
36
+ lat: lat,
37
+ z: 0,
38
+ },
39
+ style.zMode === CSZMode.Z_MSL,
40
+ );
41
+
42
+ globe.api_DrawContextTextMultiLine(text, textFont, opacity, { x, y });
43
+ }
44
+ }
45
+
46
+
47
+ insertText(key, lat, long, text) {
48
+ this.itemMap.set(key, { lat, long, text });
49
+ }
50
+
51
+
52
+ updateText(key, text) {
53
+ const item = this.itemMap.get(key);
54
+ item.text = text;
55
+ }
56
+
57
+ updateCoords(key, lat, long) {
58
+ const item = this.itemMap.get(key);
59
+ item.lat = lat; item.long = long;
60
+ }
61
+
62
+
63
+ insertTextBulk(items) {
64
+ for (const item of items) {
65
+ this.itemMap.set(item.key, item);
66
+ }
67
+ }
68
+
69
+ updateTextCoordsBulk(items) {
70
+ for (const { key, lat, long } of items) {
71
+ const item = this.itemMap.get(key);
72
+ item.lat = lat; item.long = long;
73
+ }
74
+ }
75
+
76
+
77
+ deleteTextBulk(keys) {
78
+ for (const key of keys) {
79
+ this.itemMap.delete(key);
80
+ }
81
+ }
82
+
83
+ clear() {
84
+ this.itemMap.clear();
85
+ }
86
+ }
@@ -0,0 +1 @@
1
+ export { ContextTextWriter } from "./context-text";