@pirireis/webglobeplugins 0.8.5 → 0.8.7

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 (61) hide show
  1. package/bearing-line/plugin.js +51 -43
  2. package/circle-line-chain/plugin.js +52 -44
  3. package/compass-rose/compass-rose-padding-flat.js +3 -0
  4. package/compassrose/compassrose.js +1 -8
  5. package/heatwave/isobar/plugin.js +4 -1
  6. package/heatwave/isobar/quadtreecontours.js +0 -2
  7. package/heatwave/plugins/heatwaveglobeshell.js +2 -0
  8. package/package.json +1 -1
  9. package/partialrings/goals.md +2 -0
  10. package/partialrings/plugin.js +2 -1
  11. package/point-glow-line-to-earth/draw-subset-obj.js +27 -0
  12. package/point-glow-line-to-earth/keymethod.js +0 -0
  13. package/point-glow-line-to-earth/plugin.js +439 -0
  14. package/point-glow-line-to-earth/types.js +26 -0
  15. package/point-heat-map/index.js +0 -3
  16. package/point-heat-map/plugin-webworker.js +4 -9
  17. package/point-heat-map/point-to-heat-map-flow.js +0 -6
  18. package/point-tracks/plugin.js +42 -17
  19. package/programs/arrowfield/logic.js +6 -4
  20. package/programs/arrowfield/object.js +1 -1
  21. package/programs/float2legendwithratio/object.js +5 -4
  22. package/programs/globe-util/is-globe-moved.js +27 -0
  23. package/programs/globeshell/wiggle/logic.js +3 -7
  24. package/programs/globeshell/wiggle/object.js +1 -2
  25. package/programs/line-on-globe/circle-accurate-3d.js +16 -23
  26. package/programs/line-on-globe/circle-accurate-flat.js +21 -21
  27. package/programs/line-on-globe/lines-color-instanced-flat.js +6 -7
  28. package/programs/line-on-globe/naive-accurate-flexible.js +239 -0
  29. package/programs/line-on-globe/to-the-surface.js +129 -0
  30. package/programs/picking/pickable-renderer.js +216 -0
  31. package/programs/point-on-globe/element-globe-surface-glow.js +168 -0
  32. package/programs/point-on-globe/element-point-glow.js +184 -0
  33. package/programs/point-on-globe/square-pixel-point.js +8 -7
  34. package/programs/programcache.js +9 -0
  35. package/programs/rings/partial-ring/piece-of-pie.js +1 -1
  36. package/programs/totems/camerauniformblock.js +23 -2
  37. package/rangerings/plugin.js +9 -6
  38. package/shaders/fragment-toy/firework.js +55 -0
  39. package/shaders/fragment-toy/singularity.js +59 -0
  40. package/types.js +16 -0
  41. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -6
  42. package/util/account/util.js +17 -7
  43. package/util/check/typecheck.js +11 -0
  44. package/util/gl-util/buffer/integrate-buffer.js +74 -0
  45. package/util/gl-util/draw-options/client.js +59 -0
  46. package/util/gl-util/draw-options/methods.js +46 -0
  47. package/util/gl-util/draw-options/types.js +18 -0
  48. package/util/gl-util/uniform-block/manager.js +176 -0
  49. package/util/gl-util/uniform-block/roadmap.md +70 -0
  50. package/util/gl-util/uniform-block/shader.js +0 -0
  51. package/util/gl-util/uniform-block/types.js +7 -0
  52. package/util/jshelpers/equality.js +17 -0
  53. package/util/picking/picker-displayer.js +1 -1
  54. package/util/programs/shapesonglobe.js +17 -19
  55. package/util/shaderfunctions/geometrytransformations.js +27 -63
  56. package/bearing-line/roadmap.md +0 -15
  57. package/point-heat-map/plugin.js +0 -132
  58. package/programs/line-on-globe/naive-accurate.js +0 -221
  59. package/programs/line-on-globe/to-the-origin.js +0 -164
  60. package/util/jshelpers/timemethods.js +0 -19
  61. /package/{programs/point-on-globe/element-draw-glow.js → point-glow-line-to-earth/adaptors.js} +0 -0
@@ -145,8 +145,8 @@ export default class ArrowFieldLogic {
145
145
 
146
146
  const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraBlock");
147
147
  gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
148
- const buffer = this.cameraUniformBlockTotem.getUBO();
149
- gl.bindBufferBase(gl.UNIFORM_BUFFER, this.cameraBlockBindingPoint, buffer);
148
+
149
+
150
150
 
151
151
  const arrowBlockIndex = gl.getUniformBlockIndex(program, "ArrowBlock");
152
152
  gl.uniformBlockBinding(program, arrowBlockIndex, this.arrayBlockBindingPoint);
@@ -169,12 +169,14 @@ export default class ArrowFieldLogic {
169
169
  }
170
170
 
171
171
  draw(arrowBlockManager, textureManager, instanceCount) {
172
- const { gl } = this;
172
+ const { gl, cameraBlockBindingPoint, cameraUniformBlockTotem } = this;
173
173
  gl.useProgram(this.program);
174
174
  arrowBlockManager.bind();
175
175
  textureManager.activate();
176
+ cameraUniformBlockTotem.bind(cameraBlockBindingPoint);
176
177
  gl.drawArraysInstanced(gl.LINES, 0, 6, instanceCount);
177
178
  // gl.drawArraysInstanced(gl.POINTS, 0, 4, instanceCount);
179
+ cameraUniformBlockTotem.unbind(cameraBlockBindingPoint);
178
180
  arrowBlockManager.unbind();
179
181
  }
180
182
 
@@ -194,7 +196,7 @@ class ArrowBlockBufferManager {
194
196
  gl.bindBuffer(gl.UNIFORM_BUFFER, this.ubo);
195
197
  // 4 + 2+ 2 + 2 + 1 +1 +1 +1+1= 15 ~= 16
196
198
  gl.bufferData(gl.UNIFORM_BUFFER, 56, gl.DYNAMIC_DRAW);
197
-
199
+ gl.bindBuffer(gl.UNIFORM_BUFFER, null);
198
200
  }
199
201
 
200
202
  update({
@@ -22,7 +22,7 @@ export default class ArrowField {
22
22
  tailLengthRatio = 1,
23
23
  wingLengthRatio = 0.5,
24
24
  noDataValue = null,
25
- maxMagnitude = null
25
+ // maxMagnitude = null
26
26
  } = {}) {
27
27
  this.gl = gl;
28
28
  this.globe = globe;
@@ -3,7 +3,7 @@ import { glProgramCache } from '../programcache';
3
3
 
4
4
  // Uniform Buffer Objects use this
5
5
 
6
- export default class {
6
+ export default class DataObject {
7
7
  constructor(gl, {
8
8
  width = 1,
9
9
  height = 1,
@@ -126,10 +126,11 @@ export default class {
126
126
  this.programlogic.draw(this.texture0, this.texture1, this.colorRampTexture, this.heatParametersBlockManager);
127
127
  }
128
128
 
129
-
130
-
131
129
  free() {
132
- // TODO: What else to free. Does textures and buffers need to be freed?
130
+ const { gl, texture0, texture1, colorRampTexture } = this;
131
+ gl.deleteTexture(texture0);
132
+ gl.deleteTexture(texture1);
133
+ gl.deleteTexture(colorRampTexture);
133
134
  glProgramCache.releaseProgram(this.gl, Float2LegentWithRatioProgram);
134
135
  this.heatParametersBlockManager.free();
135
136
 
@@ -0,0 +1,27 @@
1
+ import { noRegisterGlobeProgramCache } from "../programcache";
2
+
3
+ class IsGlobeMoved {
4
+ constructor(globe) {
5
+ this.globe = globe;
6
+
7
+ this._lastLOD = globe.api_GetCurrentLODWithDecimal();
8
+ }
9
+
10
+ isMoved() {
11
+ const globe = this.globe;
12
+ if (globe.api_IsScreenMoving() || this._lastLOD != globe.api_GetCurrentLODWithDecimal()) {
13
+ this._lastLOD = globe.api_GetCurrentLODWithDecimal();
14
+ return true;
15
+ }
16
+ return false;
17
+ }
18
+
19
+
20
+ }
21
+
22
+
23
+
24
+ const IsGlobeMovedCache = Object.freeze({
25
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, IsGlobeMoved),
26
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, IsGlobeMoved)
27
+ });
@@ -2,7 +2,7 @@ import { createProgram } from '../../../util';
2
2
 
3
3
 
4
4
 
5
- export default class {
5
+ export default class Logic {
6
6
  constructor() {
7
7
  this.id = "GlobeShellProgram";
8
8
  this.description = "This program implements flyweight pattern for globe." +
@@ -41,21 +41,17 @@ export default class {
41
41
  float u_opacity;
42
42
  };
43
43
 
44
-
45
44
  uniform mat4 u_model_view_matrix;
46
45
  uniform mat4 u_projection_matrix;
47
46
  uniform vec3 u_translate;
48
47
 
49
-
50
48
  uniform vec2 u_mapWH;
51
49
  uniform vec2 u_scrWH;
52
50
 
53
-
54
- uniform bool u_is3D; // TODO: Calculate 2 position from resolution, u_grid_size_rad and u_grid_offset_rad
51
+ uniform bool u_is3D;
55
52
 
56
53
  out float v_opacity;
57
54
  out vec2 v_texture_coordinate;
58
-
59
55
 
60
56
  vec2 f_texCoord(){
61
57
 
@@ -225,7 +221,7 @@ export default class {
225
221
 
226
222
  draw(texture, shellBlockDataManager, drawLines = false) {
227
223
  const { gl, programWrapper, _vao, _drawCount } = this;
228
- const { program, u_texture, u_time } = programWrapper;
224
+ const { program, u_texture } = programWrapper;
229
225
  gl.useProgram(program);
230
226
  gl.bindVertexArray(_vao);
231
227
  gl.activeTexture(gl.TEXTURE0);
@@ -13,7 +13,7 @@ export default class GlobeShell {
13
13
  u_opacity = 1,
14
14
  wiggleInKM = 0,
15
15
  wiggleSpeed = 0,
16
- eastWestTied,
16
+ // eastWestTied, Not implemented yet
17
17
  } = {}) {
18
18
  this.gl = gl;
19
19
  this.globe = globe;
@@ -86,7 +86,6 @@ export default class GlobeShell {
86
86
 
87
87
 
88
88
  free() {
89
- // TODO: What else to free. Does textures and buffers need to be freed?
90
89
  globeProgramCache.releaseProgram(this.globe, GlobeShellProgram);
91
90
  this.shellBlockManager.free();
92
91
  }
@@ -1,7 +1,8 @@
1
1
  import { createProgram } from "../../util/webglobjectbuilders";
2
2
  import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
3
3
  import { noRegisterGlobeProgramCache } from "../programcache";
4
- import { vaoAttributeLoader } from "../../util/account/util";
4
+ // import { vaoAttributeLoader } from "../../util/account/util";
5
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
5
6
  import {
6
7
  longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
7
8
  circleLimpFromLongLatRadCenterCartesian3D_accurate,
@@ -40,6 +41,7 @@ in float radius;
40
41
  in vec4 color;
41
42
  in float dash_ratio;
42
43
  in float dash_opacity;
44
+ in float initial_angle;
43
45
 
44
46
  out float interpolation;
45
47
  out vec4 v_color;
@@ -49,7 +51,7 @@ void main() {
49
51
  interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
50
52
  if ( is3D ) {
51
53
  float angle = PI * 2.0 * interpolation;
52
- vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle);
54
+ vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle + initial_angle);
53
55
  gl_Position = cartesian3DToGLPosition(position);
54
56
  } else {
55
57
  return;
@@ -109,6 +111,7 @@ class Logic {
109
111
  gl.bindAttribLocation(program, 2, "color");
110
112
  gl.bindAttribLocation(program, 3, "dash_ratio");
111
113
  gl.bindAttribLocation(program, 4, "dash_opacity");
114
+ gl.bindAttribLocation(program, 5, "initial_angle");
112
115
  }
113
116
 
114
117
  this.cameraBindingPoint = 0;
@@ -117,31 +120,21 @@ class Logic {
117
120
  gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
118
121
  }
119
122
 
120
- createVAO(center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
123
+ createVAO(center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj, initialAngleObj) {
121
124
  const { gl } = this;
122
125
  const vao = gl.createVertexArray();
123
126
  const divisor = 1;
127
+
124
128
  gl.bindVertexArray(vao);
125
- { // make this a function end import from account module.
126
- const { buffer, stride = 0, offset = 0 } = center3dObj;
127
- vaoAttributeLoader(gl, buffer, 0, 3, stride, offset, divisor);
128
- }
129
- {
130
- const { buffer, stride = 0, offset = 0 } = radiusObj;
131
- vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
132
- }
133
- {
134
- const { buffer, stride = 0, offset = 0 } = colorObj;
135
- vaoAttributeLoader(gl, buffer, 2, 4, stride, offset, divisor);
136
- }
137
- {
138
- const { buffer, stride = 0, offset = 0 } = dashRatioObj;
139
- vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, divisor);
140
- }
141
- {
142
- const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
143
- vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
144
- }
129
+
130
+ attributeLoader(gl, center3dObj, 0, 3, { divisor });
131
+ attributeLoader(gl, radiusObj, 1, 1, { divisor });
132
+ attributeLoader(gl, colorObj, 2, 4, { divisor });
133
+ attributeLoader(gl, dashRatioObj, 3, 1, { divisor });
134
+ attributeLoader(gl, dashOpacityObj, 4, 1, { divisor });
135
+ attributeLoader(gl, initialAngleObj, 5, 1, { divisor, escapeValues: [0] });
136
+
137
+
145
138
  gl.bindVertexArray(null);
146
139
  gl.bindVertexArray(null);
147
140
  return vao;
@@ -69,7 +69,11 @@ in float interpolation;
69
69
  in vec2 v_limp;
70
70
  out vec4 color;
71
71
  void main() {
72
- if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ color = vec4(0.0,0.0,0.0,0.0); return; }
72
+ if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){
73
+ discard;
74
+ // color = vec4(0.0,0.0,0.0,0.0);
75
+ // return;
76
+ }
73
77
  color = v_color;
74
78
  color.a *= opacity;
75
79
  if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
@@ -98,23 +102,19 @@ class Logic {
98
102
  mercator_calculation_mode: gl.getUniformLocation(program, "mercator_calculation_mode")
99
103
  };
100
104
 
101
- { // initial uniform values
102
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
103
- gl.useProgram(program);
104
- gl.uniform1f(program.uniforms.opacity, 1.0);
105
- gl.uniform1i(program.uniforms.edgeCount, EDGE_COUNT);
106
- gl.uniform1i(program.uniforms.mercator_calculation_mode, 0);
107
- gl.useProgram(currentProgram);
108
-
109
-
110
- }
105
+ // initial uniform values
106
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
107
+ gl.useProgram(program);
108
+ gl.uniform1f(program.uniforms.opacity, 1.0);
109
+ gl.uniform1i(program.uniforms.edgeCount, EDGE_COUNT);
110
+ gl.uniform1i(program.uniforms.mercator_calculation_mode, 0);
111
+ gl.useProgram(currentProgram);
111
112
 
112
- { // assign attribute locations
113
- gl.bindAttribLocation(program, 0, "position2d");
114
- gl.bindAttribLocation(program, 1, "color");
115
- gl.bindAttribLocation(program, 2, "dash_ratio");
116
- gl.bindAttribLocation(program, 3, "dash_opacity");
117
- }
113
+ // assign attribute locations
114
+ gl.bindAttribLocation(program, 0, "position2d");
115
+ gl.bindAttribLocation(program, 1, "color");
116
+ gl.bindAttribLocation(program, 2, "dash_ratio");
117
+ gl.bindAttribLocation(program, 3, "dash_opacity");
118
118
 
119
119
  this.cameraBindingPoint = 0;
120
120
  this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
@@ -128,20 +128,20 @@ class Logic {
128
128
  const vao = gl.createVertexArray();
129
129
  gl.bindVertexArray(vao);
130
130
  { // make this a function end import from account module.
131
- const { buffer, stride = 0, offset = 0, divisor = 1 } = centerObj;
131
+ const { buffer, stride = 0, offset = 0 } = centerObj;
132
132
  vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, null);
133
133
  }
134
134
 
135
135
  {
136
- const { buffer, stride = 0, offset = 0, divisor = 1 } = colorObj;
136
+ const { buffer, stride = 0, offset = 0 } = colorObj;
137
137
  vaoAttributeLoader(gl, buffer, 1, 4, stride, offset, null);
138
138
  }
139
139
  {
140
- const { buffer, stride = 0, offset = 0, divisor = 1 } = dashRatioObj;
140
+ const { buffer, stride = 0, offset = 0 } = dashRatioObj;
141
141
  vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, null);
142
142
  }
143
143
  {
144
- const { buffer, stride = 0, offset = 0, divisor = 1 } = dashOpacityObj;
144
+ const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
145
145
  vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, null);
146
146
  }
147
147
  gl.bindVertexArray(null);
@@ -2,8 +2,8 @@ import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totem
2
2
  import { mercatorXYToGLPosition, POLE } from "../../util/shaderfunctions/geometrytransformations";
3
3
  import { noRegisterGlobeProgramCache } from "../programcache";
4
4
  import { createProgram } from "../../util";
5
- import { vaoAttributeLoader } from "../../util/account/util";
6
5
  import { Z_ALPHA_MODE } from "./util";
6
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
7
7
 
8
8
  /**
9
9
  * This program draws line between points provided from the first and second buffer.
@@ -97,17 +97,16 @@ class Logic {
97
97
  }
98
98
  gl.useProgram(currentProgram);
99
99
  }
100
- createVAO(posAObj, posBObj, colorObj) {
101
100
 
101
+
102
+ createVAO(posAObj, posBObj, colorObj) {
102
103
  const { gl } = this;
103
104
  const vao = gl.createVertexArray();
104
- const type = gl.Float;
105
105
  const divisor = 1;
106
106
  gl.bindVertexArray(vao);
107
- [posAObj, posBObj, colorObj].forEach((obj, index) => {
108
- const { buffer, size, stride, offset } = obj;
109
- vaoAttributeLoader(gl, buffer, index, size, stride, offset, divisor, type);
110
- });
107
+ attributeLoader(gl, posAObj, 0, 2, { divisor });
108
+ attributeLoader(gl, posBObj, 1, 2, { divisor });
109
+ attributeLoader(gl, colorObj, 2, 4, { divisor });
111
110
  gl.bindVertexArray(null);
112
111
  return vao;
113
112
  }
@@ -0,0 +1,239 @@
1
+ import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems";
2
+ import { slerp, POLE, R_3D, mercatorXYToGLPosition, cartesian3DToGLPosition } from "../../util/shaderfunctions/geometrytransformations";
3
+ import { createProgram } from "../../util";
4
+ import { noRegisterGlobeProgramCache } from "../programcache";
5
+ import { attributeLoader } from "../../util/gl-util/buffer/integrate-buffer";
6
+ import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
7
+
8
+ import "../../util/gl-util/draw-options/types";
9
+ import { drawInstanced } from "../../util/gl-util/draw-options/methods";
10
+
11
+ const GLOBE_MIDPOINT_COUNT = 30;
12
+
13
+ const escapeValue = -1.0;
14
+
15
+
16
+ const uniformBindingPoints = {
17
+ camera: 0,
18
+ flexible: 1
19
+ }
20
+
21
+
22
+ const uniformBlockManager = new UniformBlockManager(
23
+ 'FlexibleAttibutes',
24
+ [
25
+ { name: 'u_color', type: 'vec4' },
26
+ { name: 'u_dash_ratio', type: 'float' },
27
+ { name: 'u_dash_opacity', type: 'float' }
28
+ ],
29
+ uniformBindingPoints.flexible
30
+ )
31
+
32
+ const vertexShader = `#version 300 es
33
+ precision highp float;
34
+
35
+ ${R_3D}
36
+ ${CameraUniformBlockString}
37
+ ${slerp}
38
+ ${mercatorXYToGLPosition}
39
+ ${cartesian3DToGLPosition}
40
+
41
+ ${uniformBlockManager.glslCode()}
42
+
43
+ in vec2 start_position;
44
+ in vec3 start_position3d;
45
+ in vec2 end_position;
46
+ in vec3 end_position3d;
47
+
48
+ in float dash_ratio;
49
+ in float dash_opacity;
50
+ in vec4 color;
51
+
52
+ out float v_dash_ratio;
53
+ out float v_dash_opacity;
54
+ out vec4 v_color;
55
+
56
+ out vec2 v_limp;
57
+ out float interpolation;
58
+
59
+ void main() {
60
+ vec2 longLat;
61
+
62
+ v_color = (color.r == -1.0) ? u_color: color;
63
+ v_dash_ratio = (dash_ratio == -1.0) ? u_dash_ratio : dash_ratio;
64
+ v_dash_opacity = (dash_opacity == -1.0) ? u_dash_opacity : dash_opacity;
65
+
66
+ if (is3D) {
67
+ interpolation = float(gl_VertexID) / ${GLOBE_MIDPOINT_COUNT - 1}.0;
68
+ vec3 cartesian = slerp(start_position3d, end_position3d, interpolation);
69
+ gl_Position = cartesian3DToGLPosition(cartesian);
70
+ v_limp = vec2(0.0, 0.0);
71
+ } else {
72
+ if ( distance( start_position, end_position) > 30000000.0) { return; }
73
+ interpolation = float(gl_VertexID);
74
+ if (gl_VertexID % 2 == 0) {
75
+ longLat = start_position;
76
+ } else {
77
+ longLat = end_position;
78
+ }
79
+ v_limp = longLat;
80
+ gl_Position = mercatorXYToGLPosition(longLat);
81
+ }
82
+ }
83
+ `;
84
+
85
+ const fragmentShader = `#version 300 es
86
+ ${POLE}
87
+ precision highp float;
88
+
89
+ uniform float opacity;
90
+
91
+ in float interpolation;
92
+ in vec2 v_limp;
93
+ in vec4 v_color;
94
+ in float v_dash_ratio;
95
+ in float v_dash_opacity;
96
+
97
+ out vec4 color;
98
+
99
+ void main() {
100
+ if (v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE) { discard; }
101
+ color = v_color;
102
+ color.a *= opacity;
103
+ if ( v_dash_ratio >= 1.0 ) { return; }
104
+ if (interpolation > 0.95) { return; }
105
+ if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5) { color.a *= v_dash_opacity; }
106
+
107
+ }
108
+ `;
109
+
110
+
111
+ class Logic {
112
+ vaosPublished = [];
113
+ isFreed = false;
114
+ constructor(globe) {
115
+ this.globe = globe;
116
+ this.gl = globe.gl;
117
+ this.program = createProgram(this.gl, vertexShader, fragmentShader);
118
+ this._lastOpacity = 1.0;
119
+ const { gl, program } = this;
120
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
121
+ gl.useProgram(program);
122
+
123
+ // assign attribute locations
124
+ gl.bindAttribLocation(program, 0, "start_position");
125
+ gl.bindAttribLocation(program, 1, "start_position3d");
126
+ gl.bindAttribLocation(program, 2, "end_position");
127
+ gl.bindAttribLocation(program, 3, "end_position3d");
128
+ gl.bindAttribLocation(program, 4, "dash_ratio");
129
+ gl.bindAttribLocation(program, 5, "dash_opacity");
130
+ gl.bindAttribLocation(program, 6, "color");
131
+ this._opacityLocation = gl.getUniformLocation(program, "opacity");
132
+
133
+ gl.uniform1f(this._opacityLocation, this._lastOpacity);
134
+
135
+ gl.useProgram(currentProgram);
136
+
137
+
138
+
139
+ this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
140
+ this.cameraBlockTotem.assignBindingPoint(program, uniformBindingPoints.camera);
141
+
142
+
143
+ this._ubosPublished = [];
144
+ uniformBlockManager.assignBindingPoint(this.gl, this.program);
145
+ this._defaultFlexibleUBO = this.createUBO();
146
+ }
147
+
148
+
149
+ /**
150
+ *
151
+ * @param {*} vao
152
+ * @param {DrawRangeIndexParams} drawOptions
153
+ * @param {number} opacity
154
+ * @param {Object} flexibleOptions
155
+ * @param {Array<number, number, number, number>} flexibleOptions.color // 0-1
156
+ * @param {number} flexibleOptions.dash_opacity
157
+ * @param {number} flexibleOptions.dash_ratio
158
+ */
159
+ draw(vao, drawOptions, opacity, flexibleUBO = null) {
160
+ const { gl, program, globe, cameraBlockTotem, _defaultFlexibleUBO } = this;
161
+ gl.useProgram(program);
162
+ cameraBlockTotem.bind(uniformBindingPoints.camera);
163
+ gl.bindVertexArray(vao);
164
+ if (opacity !== this._lastOpacity) {
165
+ gl.uniform1f(this._opacityLocation, opacity);
166
+ this._lastOpacity = opacity;
167
+ }
168
+ // this._setFlexibleUniforms(flexibleOptions);
169
+ const vertexCount = globe.api_GetCurrentGeometry() === 0 ? GLOBE_MIDPOINT_COUNT : 2;
170
+ const ubo = flexibleUBO || _defaultFlexibleUBO;
171
+ ubo.bind();
172
+ drawInstanced(gl, gl.LINE_STRIP, drawOptions, vertexCount);
173
+ ubo.unbind();
174
+ gl.bindVertexArray(null);
175
+ cameraBlockTotem.unbind(uniformBindingPoints.camera);
176
+ }
177
+
178
+
179
+ createUBO(bufferReadType = "STATIC_DRAW") {
180
+ const ubo = uniformBlockManager.createUBO(this.gl, bufferReadType);
181
+ this._ubosPublished.push(ubo);
182
+ ubo.update(
183
+ new Map([
184
+ ["u_color", [1, 1, 1, 1]],
185
+ ["u_dash_ratio", [1]],
186
+ ["u_dash_opacity", [1]]
187
+ ])
188
+ );
189
+ return ubo;
190
+ }
191
+
192
+
193
+
194
+
195
+ createVAO(
196
+ startPotisionBufferObj, startPotision3DBufferObj,
197
+ endPositionBufferObj, endPosition3DBufferObj,
198
+ dashRatioBufferObj,
199
+ dashOpacityBufferObj,
200
+ colorBufferObj) {
201
+
202
+ const { gl } = this;
203
+ const vao = gl.createVertexArray();
204
+ gl.bindVertexArray(vao);
205
+
206
+ const divisor = 1;
207
+
208
+ attributeLoader(gl, startPotisionBufferObj, 0, 2, { divisor });
209
+ attributeLoader(gl, startPotision3DBufferObj, 1, 3, { divisor });
210
+ attributeLoader(gl, endPositionBufferObj, 2, 2, { divisor });
211
+ attributeLoader(gl, endPosition3DBufferObj, 3, 3, { divisor });
212
+ attributeLoader(gl, dashRatioBufferObj, 4, 1, { divisor, escapeValues: [escapeValue] });
213
+ attributeLoader(gl, dashOpacityBufferObj, 5, 1, { divisor, escapeValues: [escapeValue] });
214
+ attributeLoader(gl, colorBufferObj, 6, 4, { divisor, escapeValues: [escapeValue, escapeValue, escapeValue, escapeValue] });
215
+
216
+ gl.bindVertexArray(null);
217
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
218
+ this.vaosPublished.push(vao);
219
+ return vao;
220
+ }
221
+
222
+
223
+ free() {
224
+ if (this.isFreed) return;
225
+ CameraUniformBlockTotemCache.release(this.globe);
226
+ this.gl.deleteProgram(this.program);
227
+ this.vaosPublished.forEach(vao => this.gl.deleteVertexArray(vao));
228
+ this._ubosPublished.forEach(ubo => ubo.free());
229
+ this.isFreed = true;
230
+ }
231
+ }
232
+
233
+
234
+
235
+ export const LineOnGlobeCache = Object.freeze({
236
+ get: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
237
+ release: (globe) => { return noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
238
+ });
239
+