@pirireis/webglobeplugins 0.15.1-alpha → 0.15.2-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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pirireis/webglobeplugins",
3
- "version": "0.15.1-alpha",
3
+ "version": "0.15.2-alpha",
4
4
  "main": "index.js",
5
5
  "author": "Toprak Nihat Deniz Ozturk",
6
6
  "license": "MIT",
@@ -14,8 +14,6 @@ const uniformBindingPoints = {
14
14
  // const one = new Float32Array([1]);
15
15
  const flexibleBlockManager = new UniformBlockManager('FlexibleAttributes', [
16
16
  { name: "u_color", type: "vec4", value: new Float32Array([0.12, 1, 0.1, 1]) },
17
- // { name: "u_dash_opacity", type: "float", value: one },
18
- // { name: "u_dash_length", type: "float", value: one },
19
17
  ], uniformBindingPoints.flexible);
20
18
  const vertexShaderSource = `#version 300 es
21
19
  precision highp float;
@@ -1,6 +1,8 @@
1
1
  import { createProgram } from "../../../util/webglobjectbuilders";
2
2
  import { CameraUniformBlockTotem, CameraUniformBlockString } from "../../totems/index";
3
3
  import { noRegisterGlobeProgramCache, globeProgramCache } from "../../programcache";
4
+ import { attributeLoader } from "../../../util/gl-util/buffer/attribute-loader";
5
+ import { UniformBlockManager } from "../../../util/gl-util/uniform-block/manager";
4
6
  import { POLE, PI, longLatRadToMercator, mercatorXYToGLPosition, longLatRadToCartesian3D, circleLimpFromLongLatRadCenterCartesian3D_accurate, circleLimpFromLongLatRadCenterMercatorCompass_accurate,
5
7
  //circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
6
8
  cartesian3DToGLPosition } from "../../../util/shaderfunctions/geometrytransformations";
@@ -9,6 +11,14 @@ cartesian3DToGLPosition } from "../../../util/shaderfunctions/geometrytransforma
9
11
  * 1. Triangle face looks at screen. if rotation angle is positive the last vertex must be the faintest.
10
12
  *
11
13
  */
14
+ const uniformBindingPoints = {
15
+ camera: 0,
16
+ flexible: 1,
17
+ };
18
+ const flexibleBlockManager = new UniformBlockManager('FlexibleAttributes', [
19
+ { name: "u_color", type: "vec4", value: new Float32Array([0.12, 1, 0.1, 1]) },
20
+ { name: "u_opacity", type: "float", value: new Float32Array([1]) },
21
+ ], uniformBindingPoints.flexible);
12
22
  const drawModeMap = Object.freeze({
13
23
  LINE_STRIP: 0,
14
24
  TRIANGLE_FAN: 1,
@@ -25,11 +35,12 @@ ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
25
35
  ${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
26
36
  ${cartesian3DToGLPosition}
27
37
 
38
+ ${flexibleBlockManager.glslCode()}
39
+
40
+
28
41
  uniform float edge_count;
29
42
  uniform int draw_mode; // %2 => 0: LINE_STRIP, 1: TRIANGLE_FAN
30
- uniform float plugin_alpha_multiplier;
31
- //, lat, startAngle, tailAngle, ...rgba, radius, rgbaMode
32
- // in vec2 center; // long, lat in radian
43
+
33
44
  in vec2 center2d;
34
45
  in vec3 center3d;
35
46
  in float start_angle2d;
@@ -41,14 +52,15 @@ in float tail_angle3d;
41
52
  in vec4 color;
42
53
  in float radius; // in meter
43
54
  in float filling_mode; // 0.0: constant, 1.0: fading, 2.0: hide
44
- // flat out int vid;
45
- // flat out float v_phase;
55
+
46
56
  out vec2 v_pos;
47
57
  out vec4 v_color;
48
- // flat out float v_angle;
58
+
49
59
 
50
60
  void main() {
51
61
  // vid = gl_VertexID;
62
+ vec4 _color = (color.r == -1.0) ? u_color : color;
63
+
52
64
  if (filling_mode == 2.0 || radius == 0.0) { return; }
53
65
  float start_angle, tail_angle;
54
66
  if (is3D) {
@@ -62,7 +74,7 @@ void main() {
62
74
  if ( draw_mode == 0 && filling_mode == 1.0) {filling_mode_ = 0.0;}
63
75
  float vertexID = float(gl_VertexID);
64
76
  float radius_ = radius;
65
- float alpha = plugin_alpha_multiplier;
77
+ float alpha = u_opacity;
66
78
  if (draw_mode == 1) { // TRIANGLE_FAN
67
79
  if (gl_VertexID == 0) {
68
80
  radius_ = 0.0;
@@ -71,16 +83,15 @@ void main() {
71
83
  vertexID -= 1.0;
72
84
  }
73
85
  float phase = ( vertexID / (edge_count - 1.0) );
74
- // v_angle = tail_angle;
75
86
 
76
87
  if ( filling_mode_ == 1.0 ) {
77
88
  if ( tail_angle < 0.0 ) {
78
- v_color = vec4( color.rgb , color.a * ( 1.0 - phase ) * alpha );
89
+ v_color = vec4( _color.rgb , _color.a * ( 1.0 - phase ) * alpha );
79
90
  } else {
80
- v_color = vec4( color.rgb , color.a * phase * alpha );
91
+ v_color = vec4( _color.rgb , _color.a * phase * alpha );
81
92
  }
82
93
  } else {
83
- v_color = vec4( color.rgb , color.a * alpha );
94
+ v_color = vec4( _color.rgb , _color.a * alpha );
84
95
  }
85
96
  if ( filling_mode == 0.0 && draw_mode == 1 ) {
86
97
  v_color.a /= 2.0;
@@ -106,16 +117,11 @@ void main() {
106
117
  }`;
107
118
  const fragmentShaderSource = `#version 300 es` + POLE + PI + `
108
119
  precision highp float;
109
- // flat in int vid;
110
120
  in vec4 v_color;
111
121
  in vec2 v_pos;
112
- // flat in float v_phase;
113
- // in float v_angle;
114
122
  out vec4 outColor;
115
123
  void main() {
116
- // if( vid % 2 == 0 ) { discard; }
117
- // if ( mod(v_angle, PI / 36.0 ) < (PI / 72.0)) { discard; }
118
- // if ( mod(v_angle * v_phase, PI / 90.0 ) < (PI / 180.0)) { discard; }
124
+
119
125
  if ( v_pos.x < -POLE || v_pos.x > POLE || v_pos.y < -POLE || v_pos.y > POLE ) { discard; }
120
126
  outColor = v_color;
121
127
  }`;
@@ -129,9 +135,10 @@ export class Logic {
129
135
  program;
130
136
  _edgeCountLocation;
131
137
  _draw_modeLocation;
132
- _plugin_alpha_multiplierLocation;
133
138
  cameraBlockBindingPoint;
134
139
  cameraBlockTotem; // Type this based on your CameraUniformBlockTotem implementation
140
+ _ubosPublished = [];
141
+ _defaultFlexibleUBO;
135
142
  constructor(globe) {
136
143
  this.globe = globe;
137
144
  this.gl = globe.gl;
@@ -156,22 +163,21 @@ export class Logic {
156
163
  { // Uniforms
157
164
  this._edgeCountLocation = gl.getUniformLocation(program, 'edge_count');
158
165
  this._draw_modeLocation = gl.getUniformLocation(program, 'draw_mode');
159
- this._plugin_alpha_multiplierLocation = gl.getUniformLocation(program, 'plugin_alpha_multiplier');
160
166
  const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
161
167
  gl.useProgram(program);
162
168
  gl.uniform1i(this._draw_modeLocation, this._lastMode);
163
169
  gl.uniform1f(this._edgeCountLocation, this._lastEdgeCount);
164
- gl.uniform1f(this._plugin_alpha_multiplierLocation, 1.0);
165
170
  this.cameraBlockBindingPoint = 0;
166
171
  this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
167
172
  const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
168
173
  gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
174
+ flexibleBlockManager.assignBindingPoint(gl, program);
175
+ this._defaultFlexibleUBO = flexibleBlockManager.createUBO(gl);
169
176
  gl.useProgram(currentProgram);
170
177
  }
171
178
  }
172
- draw(length, vao, edgeCount, alphaMultiplier, drawMode) {
179
+ draw(length, vao, edgeCount, drawMode, ubo = null) {
173
180
  const { gl, program, cameraBlockTotem, cameraBlockBindingPoint } = this;
174
- // gl.disable(gl.DEPTH_TEST);
175
181
  gl.useProgram(program);
176
182
  if (drawModeMap[drawMode] !== this._lastMode) {
177
183
  gl.uniform1i(this._draw_modeLocation, drawModeMap[drawMode]);
@@ -181,9 +187,11 @@ export class Logic {
181
187
  gl.uniform1f(this._edgeCountLocation, edgeCount);
182
188
  this._lastEdgeCount = edgeCount;
183
189
  }
184
- if (alphaMultiplier !== this._lastAlphaMultiplier) {
185
- gl.uniform1f(this._plugin_alpha_multiplierLocation, alphaMultiplier);
186
- this._lastAlphaMultiplier = alphaMultiplier;
190
+ if (ubo) {
191
+ ubo.bind();
192
+ }
193
+ else {
194
+ this._defaultFlexibleUBO.bind();
187
195
  }
188
196
  const overdraw = drawModeMap[drawMode];
189
197
  cameraBlockTotem.bind(cameraBlockBindingPoint);
@@ -191,11 +199,18 @@ export class Logic {
191
199
  gl.drawArraysInstanced(gl[drawMode], 0, edgeCount + overdraw, length);
192
200
  cameraBlockTotem.unbind(cameraBlockBindingPoint);
193
201
  gl.bindVertexArray(null);
194
- // gl.enable(gl.DEPTH_TEST);
202
+ if (ubo) {
203
+ ubo.unbind();
204
+ }
205
+ else {
206
+ this._defaultFlexibleUBO.unbind();
207
+ }
195
208
  }
196
209
  free() {
197
210
  noRegisterGlobeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
198
211
  this.gl.deleteProgram(this.program);
212
+ this._defaultFlexibleUBO.free();
213
+ this._ubosPublished.forEach(ubo => ubo.free()); // TODO: can be called 2 times. is it a problem?
199
214
  this.program = null;
200
215
  }
201
216
  /**
@@ -210,74 +225,25 @@ export class Logic {
210
225
  const { gl } = this;
211
226
  const vao = gl.createVertexArray();
212
227
  gl.bindVertexArray(vao);
213
- {
214
- const { buffer, stride, offset } = center2dObj;
215
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
216
- gl.enableVertexAttribArray(0);
217
- gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
218
- gl.vertexAttribDivisor(0, 1);
219
- }
220
- {
221
- const { buffer, stride, offset } = center3dObj;
222
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
223
- gl.enableVertexAttribArray(1);
224
- gl.vertexAttribPointer(1, 3, gl.FLOAT, false, stride, offset);
225
- gl.vertexAttribDivisor(1, 1);
226
- }
227
- {
228
- const { buffer, stride, offset } = startAngle2DObj;
229
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
230
- gl.enableVertexAttribArray(2);
231
- gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
232
- gl.vertexAttribDivisor(2, 1);
233
- }
234
- {
235
- const { buffer, stride, offset } = tailAngle2DObj;
236
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
237
- gl.enableVertexAttribArray(3);
238
- gl.vertexAttribPointer(3, 1, gl.FLOAT, false, stride, offset);
239
- gl.vertexAttribDivisor(3, 1);
240
- }
241
- {
242
- const { buffer, stride, offset } = startAngle3DObj;
243
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
244
- gl.enableVertexAttribArray(4);
245
- gl.vertexAttribPointer(4, 1, gl.FLOAT, false, stride, offset);
246
- gl.vertexAttribDivisor(4, 1);
247
- }
248
- {
249
- const { buffer, stride, offset } = tailAngle3DObj;
250
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
251
- gl.enableVertexAttribArray(5);
252
- gl.vertexAttribPointer(5, 1, gl.FLOAT, false, stride, offset);
253
- gl.vertexAttribDivisor(5, 1);
254
- }
255
- {
256
- const { buffer, stride, offset } = colorObj;
257
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
258
- gl.enableVertexAttribArray(6);
259
- gl.vertexAttribPointer(6, 4, gl.FLOAT, false, stride, offset);
260
- gl.vertexAttribDivisor(6, 1);
261
- }
262
- {
263
- const { buffer, stride, offset } = radiusObj;
264
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
265
- gl.enableVertexAttribArray(7);
266
- gl.vertexAttribPointer(7, 1, gl.FLOAT, false, stride, offset);
267
- gl.vertexAttribDivisor(7, 1);
268
- }
269
- {
270
- const { buffer, stride, offset } = colorModeObj;
271
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
272
- gl.enableVertexAttribArray(8);
273
- gl.vertexAttribPointer(8, 1, gl.FLOAT, false, stride, offset);
274
- gl.vertexAttribDivisor(8, 1);
275
- }
228
+ attributeLoader(gl, center2dObj, 0, 2, { divisor: 1 });
229
+ attributeLoader(gl, center3dObj, 1, 3, { divisor: 1 });
230
+ attributeLoader(gl, startAngle2DObj, 2, 1, { divisor: 1 });
231
+ attributeLoader(gl, tailAngle2DObj, 3, 1, { divisor: 1 });
232
+ attributeLoader(gl, startAngle3DObj, 4, 1, { divisor: 1 });
233
+ attributeLoader(gl, tailAngle3DObj, 5, 1, { divisor: 1 });
234
+ attributeLoader(gl, colorObj, 6, 4, { divisor: 1, escapeValues: [-1.0, -1.0, -1.0, -1.0] });
235
+ attributeLoader(gl, radiusObj, 7, 1, { divisor: 1, escapeValues: [-1.0] });
236
+ attributeLoader(gl, colorModeObj, 8, 1, { divisor: 1, escapeValues: [-1.0] });
276
237
  gl.bindVertexArray(null);
277
238
  gl.bindBuffer(gl.ARRAY_BUFFER, null);
278
239
  return vao;
279
240
  }
280
241
  createUBO() {
242
+ const { gl } = this;
243
+ const bufferReadType = gl.DYNAMIC_DRAW;
244
+ const ubo = flexibleBlockManager.createUBO(gl, "STATIC_DRAW");
245
+ this._ubosPublished.push(ubo);
246
+ return ubo;
281
247
  }
282
248
  }
283
249
  export const PieceOfPieProgramCache = Object.freeze({
@@ -32,6 +32,28 @@ export class BearingLinePlugin {
32
32
  flatStraightLineOn: true // This is a new option to control flat straight line drawing
33
33
  };
34
34
  _memory = new Map();
35
+ _semiPluginsOptions = {
36
+ circleOnTerrainOptions: {
37
+ defaultColor: [0.1, 0.1, 1, 0.5],
38
+ defaultHeightFromGroundIn3D: 30.0,
39
+ variativeColorsOn: false,
40
+ },
41
+ arcOnTerrainOptions: {
42
+ defaultHeightFromGroundIn3D: 30.0,
43
+ variativeColorsOn: false,
44
+ },
45
+ lineOptions: {
46
+ flatViewOn: true,
47
+ globeViewOn: true,
48
+ variativeColorsOn: false,
49
+ defaultColor: [1, 1, 1, 0.5],
50
+ },
51
+ pieceOfPieOptions: {
52
+ defaultColor: [1, 1, 1, 0.5],
53
+ defaultHeightFromGroundIn3D: 30.0,
54
+ variativeColorsOn: false,
55
+ }
56
+ };
35
57
  constructor(id, { textWritersMap, textDataPreAdaptor, opacities, drawOptions, } = {}) {
36
58
  this.id = id;
37
59
  if (!(textWritersMap instanceof Map))
@@ -87,8 +87,13 @@ export class ChainListMap {
87
87
  this._chainMap.set(chainKey, newChain);
88
88
  return deleteKeys;
89
89
  }
90
- deleteChainAndReturnChainKeys(chainKey) {
90
+ deleteChainAndReturnChainKeys(chainKey, writers) {
91
91
  const keys = this.getNodeKeysOfChain(chainKey);
92
+ if (writers.size > 0) {
93
+ writers.forEach((writer) => {
94
+ writer.deleteTextBulk(keys);
95
+ });
96
+ }
92
97
  this._chainMap.delete(chainKey);
93
98
  this._chainSideProperties.delete(chainKey); // TODO: this might be this way but adding this know can cause side effects
94
99
  for (const key of keys)
@@ -164,7 +164,7 @@ export class CircleLineChainPlugin {
164
164
  return;
165
165
  }
166
166
  for (const chainKey of chainKeys) {
167
- const keys = this._chainListMap.deleteChainAndReturnChainKeys(chainKey);
167
+ const keys = this._chainListMap.deleteChainAndReturnChainKeys(chainKey, this._textWritersMap);
168
168
  if (keys.length <= 1) {
169
169
  console.warn("No chains were deleted, chainKeys might be invalid.");
170
170
  return;
@@ -15,7 +15,7 @@ export class PieceOfPiePlugin {
15
15
  bufferManagersMap = null;
16
16
  bufferOrchestrator = new BufferOrchestrator({ capacity: INITIAL_CAPACITY });
17
17
  drawMode = "BOTH";
18
- opacity = 1;
18
+ _uboHandler = null;
19
19
  _pluginOptions = {
20
20
  bufferType: "STATIC_DRAW",
21
21
  initialCapacity: INITIAL_CAPACITY,
@@ -37,7 +37,7 @@ export class PieceOfPiePlugin {
37
37
  }
38
38
  setPluginOpacity(opacity) {
39
39
  opacityCheck(opacity);
40
- this.opacity = opacity;
40
+ this._uboHandler?.updateSingle("u_opacity", new Float32Array([opacity]));
41
41
  this.globe?.DrawRender();
42
42
  }
43
43
  setDrawMode(drawMode) {
@@ -145,18 +145,17 @@ export class PieceOfPiePlugin {
145
145
  }
146
146
  draw3D() {
147
147
  if (!this.gl || !this.program || !this.vao || !this.globe) {
148
- console.warn("PieChartPlugin is not initialized properly.");
148
+ console.warn("PieChartPlugin is not initialized properly Or unregistered from globe.");
149
149
  return;
150
150
  }
151
151
  const length = this.bufferOrchestrator.length;
152
- console.log("Drawing PieChartPlugin with length:", length);
153
152
  this.gl.disable(this.gl.DEPTH_TEST);
154
153
  if (this.drawMode === "BOTH") {
155
- this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, "LINE_STRIP");
156
- this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, "TRIANGLE_FAN");
154
+ this.program?.draw(length, this.vao, EDGE_COUNT, "LINE_STRIP", this._uboHandler);
155
+ this.program?.draw(length, this.vao, EDGE_COUNT, "TRIANGLE_FAN", this._uboHandler);
157
156
  }
158
157
  else {
159
- this.program?.draw(length, this.vao, EDGE_COUNT, this.opacity, this.drawMode);
158
+ this.program?.draw(length, this.vao, EDGE_COUNT, this.drawMode, this._uboHandler);
160
159
  }
161
160
  this.gl.enable(this.gl.DEPTH_TEST);
162
161
  }