@pirireis/webglobeplugins 0.12.0-alpha → 0.14.0-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/Math/arc-cdf-points.js +20 -0
  2. package/Math/arc-generate-points copy.js +1 -0
  3. package/Math/arc.js +21 -8
  4. package/Math/circle-cdf-points.js +0 -2
  5. package/Math/circle.js +35 -16
  6. package/Math/templete-shapes/grid-visually-equal.js +66 -0
  7. package/altitude-locator/plugin.js +3 -2
  8. package/bearing-line/plugin.js +1 -2
  9. package/circle-line-chain/plugin.js +4 -7
  10. package/compass-rose/compass-rose-padding-flat.js +12 -0
  11. package/package.json +1 -1
  12. package/programs/line-on-globe/degree-padding-around-circle-3d.js +1 -1
  13. package/programs/line-on-globe/linestrip/data.js +4 -0
  14. package/programs/line-on-globe/{linestrip.js → linestrip/linestrip.js} +37 -35
  15. package/programs/line-on-globe/naive-accurate-flexible.js +23 -16
  16. package/programs/picking/pickable-renderer.js +1 -2
  17. package/programs/rings/distancering/circleflatprogram.js +116 -120
  18. package/programs/rings/distancering/circlepaddingfreeangleprogram.js +1 -1
  19. package/programs/rings/distancering/circlepaddysharedbuffer.js +368 -354
  20. package/programs/rings/distancering/index.js +6 -5
  21. package/programs/rings/distancering/paddyflatprogram.js +127 -136
  22. package/programs/rings/distancering/paddyflatprogram2d.js +129 -138
  23. package/programs/rings/distancering/paddyflatprogram3d.js +128 -136
  24. package/programs/rings/partial-ring/piece-of-pie copy.js +286 -0
  25. package/programs/rings/partial-ring/piece-of-pie.js +26 -13
  26. package/programs/totems/camerauniformblock.js +1 -1
  27. package/programs/totems/index.js +1 -1
  28. package/programs/vectorfields/logics/pixelbased.js +5 -21
  29. package/range-tools-on-terrain/bearing-line/adapters.js +111 -0
  30. package/range-tools-on-terrain/bearing-line/plugin.js +360 -0
  31. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  32. package/range-tools-on-terrain/circle-line-chain/adapters.js +83 -0
  33. package/range-tools-on-terrain/circle-line-chain/chain-list-map.js +351 -0
  34. package/range-tools-on-terrain/circle-line-chain/plugin.js +389 -0
  35. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  36. package/range-tools-on-terrain/range-ring/adapters.js +25 -0
  37. package/range-tools-on-terrain/range-ring/plugin.js +31 -0
  38. package/range-tools-on-terrain/range-ring/types.js +1 -0
  39. package/rangerings/plugin.js +7 -11
  40. package/semiplugins/lightweight/line-plugin.js +195 -0
  41. package/semiplugins/lightweight/piece-of-pie-plugin.js +175 -0
  42. package/semiplugins/shape-on-terrain/arc-plugin.js +368 -0
  43. package/{shape-on-terrain/circle/plugin.js → semiplugins/shape-on-terrain/circle-plugin.js} +129 -68
  44. package/semiplugins/shape-on-terrain/derived/padding-plugin.js +96 -0
  45. package/semiplugins/type.js +1 -0
  46. package/types.js +0 -11
  47. package/util/account/create-buffermap-orchastration.js +39 -0
  48. package/util/account/index.js +2 -2
  49. package/util/account/single-attribute-buffer-management/buffer-manager.js +2 -3
  50. package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +14 -3
  51. package/util/build-strategy/static-dynamic.js +1 -1
  52. package/util/check/typecheck.js +15 -1
  53. package/util/geometry/index.js +3 -2
  54. package/util/gl-util/buffer/attribute-loader.js +2 -5
  55. package/util/gl-util/draw-options/methods.js +4 -5
  56. package/util/webglobjectbuilders.js +4 -9
  57. package/write-text/context-text3.js +17 -0
  58. package/write-text/context-text3old.js +152 -0
  59. package/programs/line-on-globe/circle-accurate.js +0 -175
  60. package/programs/line-on-globe/circle.js +0 -164
  61. package/programs/line-on-globe/to-the-surface.js +0 -109
  62. package/programs/rings/distancering/shader.js +0 -1
  63. package/programs/totems/canvas-webglobe-info1.js +0 -106
  64. package/shape-on-terrain/arc/naive/plugin.js +0 -205
  65. package/util/check/get.js +0 -14
  66. package/util/gl-util/buffer/types.js +0 -1
  67. package/util/gl-util/draw-options/types.js +0 -15
  68. package/util/webglobjectbuilders1.js +0 -219
@@ -1,136 +1,128 @@
1
- import { createProgram, shaderfunctions } from "../../../util";
2
- import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
3
- import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
4
- const vertexShader = `#version 300 es ` +
5
- shaderfunctions.PI +
6
- shaderfunctions.R +
7
- shaderfunctions.POLE +
8
- CameraUniformBlockString +
9
- shaderfunctions.mercatorXYToGLPosition +
10
- shaderfunctions.longLatRadToMercator +
11
- shaderfunctions.longLatRadToCartesian3D +
12
- shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
13
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
14
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
15
- shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
16
-
17
- in vec2 center;
18
- in float radius;
19
- in float pad_range;
20
- in vec4 color;
21
- in float flag;
22
-
23
- uniform int compass;
24
- uniform float pad_count;
25
-
26
- uniform float opacity;
27
-
28
-
29
- out vec2 v_limp;
30
- out vec4 v_color;
31
-
32
-
33
- void main() {
34
-
35
- float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
36
- if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
37
- v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
38
-
39
- gl_PointSize = 2.0;
40
-
41
- float odd = mod(float(gl_VertexID), 2.0);
42
- float index = (float(gl_VertexID)- odd ) / 2.0;
43
- float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
44
- float radius_ = radius - (pad_range * odd);
45
-
46
- if ( is3D){
47
- gl_Position = projection * view * vec4(
48
- circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
49
- v_limp = vec2(0.0, 0.0);
50
- return;
51
- }
52
- vec2 limp;
53
- if ( compass == 1 ){
54
- limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
55
- } else {
56
- // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
57
- limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
58
- }
59
- v_limp = limp;
60
- gl_Position = mercatorXYToGLPosition(limp);
61
- }`;
62
- const fragmentShader = `#version 300 es
63
- precision highp float; ` +
64
- shaderfunctions.POLE + `
65
- in vec4 v_color;
66
- in vec2 v_limp;
67
- out vec4 outColor;
68
- void main() {
69
- if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
70
- outColor = v_color;
71
- }`;
72
- class Logic {
73
- constructor(globe) {
74
- this.globe = globe;
75
- this.gl = globe.gl;
76
- this.program = createProgram(this.gl, vertexShader, fragmentShader);
77
- { // bind positions so bufferManager can use them
78
- this.gl.bindAttribLocation(this.program, 0, "center");
79
- this.gl.bindAttribLocation(this.program, 1, "radius");
80
- this.gl.bindAttribLocation(this.program, 2, "pad_range");
81
- this.gl.bindAttribLocation(this.program, 3, "color");
82
- this.gl.bindAttribLocation(this.program, 4, "flag");
83
- }
84
- this.cameraBlockBindingPoint = 0;
85
- const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
86
- this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
87
- this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
88
- this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
89
- this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
90
- this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
91
- this._compassMode = 1;
92
- this._opacity = 1.0;
93
- this._padCount = 360;
94
- {
95
- const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
96
- this.gl.useProgram(this.program);
97
- this.gl.uniform1i(this._compassLocation, 1);
98
- this.gl.uniform1f(this._opacityLocation, 1.0);
99
- this.gl.uniform1f(this._padCountLocation, 360);
100
- this.gl.useProgram(currentProgram);
101
- }
102
- }
103
- draw(attrBufferManager, padCount, compass, opacity) {
104
- const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
105
- gl.useProgram(program);
106
- attrBufferManager.bindPaddingVAO();
107
- cameraBlockTotem.bind(cameraBlockBindingPoint);
108
- // draw instanced
109
- if (padCount !== this._padCount) {
110
- this._padCount = padCount;
111
- // console.log("padCount", padCount);
112
- gl.uniform1f(_padCountLocation, padCount);
113
- }
114
- if (compass !== this._compassMode) {
115
- // console.log("compass", compass);
116
- gl.uniform1i(_compassLocation, compass);
117
- this._compassMode = compass;
118
- }
119
- if (opacity !== this._opacity) {
120
- // console.log("opacity", opacity);
121
- this._opacity = opacity;
122
- gl.uniform1f(this._opacityLocation, opacity);
123
- }
124
- gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
125
- gl.bindVertexArray(null);
126
- cameraBlockTotem.unbind(cameraBlockBindingPoint);
127
- }
128
- free() {
129
- this.gl.deleteProgram(this.program);
130
- globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
131
- }
132
- }
133
- export const PaddingProgramCache = Object.freeze({
134
- getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic); },
135
- releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic); }
136
- });
1
+ "use strict";
2
+ // TODO: Delete this file if it is not needed anymore.
3
+ // import { createProgram, shaderfunctions } from "../../../util";
4
+ // import CameraUniformBlockTotem, { CameraUniformBlockString } from "../../totems/camerauniformblock";
5
+ // import { globeProgramCache, noRegisterGlobeProgramCache } from "../../programcache";
6
+ // const vertexShader = `#version 300 es ` +
7
+ // shaderfunctions.PI +
8
+ // shaderfunctions.R +
9
+ // shaderfunctions.POLE +
10
+ // CameraUniformBlockString +
11
+ // shaderfunctions.mercatorXYToGLPosition +
12
+ // shaderfunctions.longLatRadToMercator +
13
+ // shaderfunctions.longLatRadToCartesian3D +
14
+ // shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
15
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorCompass +
16
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistancePadding +
17
+ // shaderfunctions.circleLimpFromLongLatRadCenterMercatorRealDistance + `
18
+ // in vec2 center;
19
+ // in float radius;
20
+ // in float pad_range;
21
+ // in vec4 color;
22
+ // in float flag;
23
+ // uniform int compass;
24
+ // uniform float pad_count;
25
+ // uniform float opacity;
26
+ // out vec2 v_limp;
27
+ // out vec4 v_color;
28
+ // void main() {
29
+ // float alpha_padding = z_level * z_level / (pad_range/ 100.0 );
30
+ // if( flag == 2.0 || flag == 1.0 || radius == 0.0 || alpha_padding < 0.1 || z_level < 3.0 ) return; // 1.0 is hide
31
+ // v_color = vec4(color.rgb, color.a * alpha_padding * opacity);
32
+ // gl_PointSize = 2.0;
33
+ // float odd = mod(float(gl_VertexID), 2.0);
34
+ // float index = (float(gl_VertexID)- odd ) / 2.0;
35
+ // float angle = 3.1415926535897932384626433832795 * 2.0 * (index / pad_count );
36
+ // float radius_ = radius - (pad_range * odd);
37
+ // if ( is3D){
38
+ // gl_Position = projection * view * vec4(
39
+ // circleLimpFromLongLatRadCenterCartesian3D( center, radius_, angle) - translate, 1.0);
40
+ // v_limp = vec2(0.0, 0.0);
41
+ // return;
42
+ // }
43
+ // vec2 limp;
44
+ // if ( compass == 1 ){
45
+ // limp = circleLimpFromLongLatRadCenterMercatorCompass(center , radius_, angle);
46
+ // } else {
47
+ // // limp = circleLimpFromLongLatRadCenterMercatorRealDistancePadding(center, radius_, angle);
48
+ // limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
49
+ // }
50
+ // v_limp = limp;
51
+ // gl_Position = mercatorXYToGLPosition(limp);
52
+ // }`;
53
+ // const fragmentShader = `#version 300 es
54
+ // precision highp float; `+
55
+ // shaderfunctions.POLE + `
56
+ // in vec4 v_color;
57
+ // in vec2 v_limp;
58
+ // out vec4 outColor;
59
+ // void main() {
60
+ // if ( v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE ){ discard; }
61
+ // outColor = v_color;
62
+ // }`;
63
+ // class Logic {
64
+ // constructor(globe) {
65
+ // this.globe = globe;
66
+ // this.gl = globe.gl;
67
+ // this.program = createProgram(this.gl, vertexShader, fragmentShader);
68
+ // { // bind positions so bufferManager can use them
69
+ // this.gl.bindAttribLocation(this.program, 0, "center");
70
+ // this.gl.bindAttribLocation(this.program, 1, "radius");
71
+ // this.gl.bindAttribLocation(this.program, 2, "pad_range");
72
+ // this.gl.bindAttribLocation(this.program, 3, "color");
73
+ // this.gl.bindAttribLocation(this.program, 4, "flag");
74
+ // }
75
+ // this.cameraBlockBindingPoint = 0;
76
+ // const cameraBlockIndex = this.gl.getUniformBlockIndex(this.program, "CameraUniformBlock");
77
+ // this.gl.uniformBlockBinding(this.program, cameraBlockIndex, this.cameraBlockBindingPoint);
78
+ // this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
79
+ // this._padCountLocation = this.gl.getUniformLocation(this.program, "pad_count");
80
+ // this._opacityLocation = this.gl.getUniformLocation(this.program, "opacity");
81
+ // this._compassLocation = this.gl.getUniformLocation(this.program, "compass");
82
+ // this._compassMode = 1;
83
+ // this._opacity = 1.0;
84
+ // this._padCount = 360;
85
+ // {
86
+ // const currentProgram = this.gl.getParameter(this.gl.CURRENT_PROGRAM);
87
+ // this.gl.useProgram(this.program);
88
+ // this.gl.uniform1i(this._compassLocation, 1);
89
+ // this.gl.uniform1f(this._opacityLocation, 1.0);
90
+ // this.gl.uniform1f(this._padCountLocation, 360)
91
+ // this.gl.useProgram(currentProgram);
92
+ // }
93
+ // }
94
+ // draw(attrBufferManager, padCount, compass, opacity) {
95
+ // const { gl, program, _padCountLocation, cameraBlockBindingPoint, cameraBlockTotem, _compassLocation } = this;
96
+ // gl.useProgram(program);
97
+ // attrBufferManager.bindPaddingVAO();
98
+ // cameraBlockTotem.bind(cameraBlockBindingPoint);
99
+ // // draw instanced
100
+ // if (padCount !== this._padCount) {
101
+ // this._padCount = padCount;
102
+ // // console.log("padCount", padCount);
103
+ // gl.uniform1f(_padCountLocation, padCount);
104
+ // }
105
+ // if (compass !== this._compassMode) {
106
+ // // console.log("compass", compass);
107
+ // gl.uniform1i(_compassLocation, compass);
108
+ // this._compassMode = compass;
109
+ // }
110
+ // if (opacity !== this._opacity) {
111
+ // // console.log("opacity", opacity);
112
+ // this._opacity = opacity;
113
+ // gl.uniform1f(this._opacityLocation, opacity);
114
+ // }
115
+ // gl.drawArraysInstanced(gl.LINES, 0, padCount * 2, attrBufferManager.length);
116
+ // gl.bindVertexArray(null);
117
+ // cameraBlockTotem.unbind(cameraBlockBindingPoint);
118
+ // }
119
+ // free() {
120
+ // this.gl.deleteProgram(this.program);
121
+ // globeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
122
+ // }
123
+ // }
124
+ // //
125
+ // export const PaddingProgramCache = Object.freeze({
126
+ // getProgram: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
127
+ // releaseProgram: (globe) => { noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
128
+ // })
@@ -0,0 +1,286 @@
1
+ import { createProgram } from "../../../util/webglobjectbuilders";
2
+ import { CameraUniformBlockTotem, CameraUniformBlockString } from "../../totems/index";
3
+ import { noRegisterGlobeProgramCache, globeProgramCache } from "../../programcache";
4
+ import { POLE, PI, longLatRadToMercator, mercatorXYToGLPosition, longLatRadToCartesian3D, circleLimpFromLongLatRadCenterCartesian3D_accurate, circleLimpFromLongLatRadCenterMercatorCompass_accurate,
5
+ //circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate,
6
+ cartesian3DToGLPosition } from "../../../util/shaderfunctions/geometrytransformations";
7
+ /**
8
+ * TODO:
9
+ * 1. Triangle face looks at screen. if rotation angle is positive the last vertex must be the faintest.
10
+ *
11
+ */
12
+ const drawModeMap = Object.freeze({
13
+ LINE_STRIP: 0,
14
+ TRIANGLE_FAN: 1,
15
+ });
16
+ //${ circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate }
17
+ const vertexShaderSource = `#version 300 es
18
+
19
+ ${CameraUniformBlockString}
20
+ ${PI}
21
+ ${longLatRadToMercator}
22
+ ${mercatorXYToGLPosition}
23
+ ${longLatRadToCartesian3D}
24
+ ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
25
+ ${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
26
+ ${cartesian3DToGLPosition}
27
+
28
+ uniform float edge_count;
29
+ 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
33
+ in vec2 center2d;
34
+ in vec3 center3d;
35
+ in float start_angle2d;
36
+ in float tail_angle2d;
37
+
38
+ in float start_angle3d;
39
+ in float tail_angle3d;
40
+
41
+ in vec4 color;
42
+ in float radius; // in meter
43
+ in float filling_mode; // 0.0: constant, 1.0: fading, 2.0: hide
44
+ // flat out int vid;
45
+ // flat out float v_phase;
46
+ out vec2 v_pos;
47
+ out vec4 v_color;
48
+ // flat out float v_angle;
49
+
50
+ void main() {
51
+ // vid = gl_VertexID;
52
+ if (filling_mode == 2.0 || radius == 0.0) { return; }
53
+ float start_angle, tail_angle;
54
+ if (is3D) {
55
+ start_angle = start_angle3d;
56
+ tail_angle = tail_angle3d;
57
+ } else {
58
+ start_angle = start_angle2d;
59
+ tail_angle = tail_angle2d;
60
+ }
61
+ float filling_mode_ = filling_mode;
62
+ if ( draw_mode == 0 && filling_mode == 1.0) {filling_mode_ = 0.0;}
63
+ float vertexID = float(gl_VertexID);
64
+ float radius_ = radius;
65
+ float alpha = plugin_alpha_multiplier;
66
+ if (draw_mode == 1) { // TRIANGLE_FAN
67
+ if (gl_VertexID == 0) {
68
+ radius_ = 0.0;
69
+ if ( filling_mode == 1.0 ) { alpha = 0.0; }
70
+ }
71
+ vertexID -= 1.0;
72
+ }
73
+ float phase = ( vertexID / (edge_count - 1.0) );
74
+ // v_angle = tail_angle;
75
+
76
+ if ( filling_mode_ == 1.0 ) {
77
+ if ( tail_angle < 0.0 ) {
78
+ v_color = vec4( color.rgb , color.a * ( 1.0 - phase ) * alpha );
79
+ } else {
80
+ v_color = vec4( color.rgb , color.a * phase * alpha );
81
+ }
82
+ } else {
83
+ v_color = vec4( color.rgb , color.a * alpha );
84
+ }
85
+ if ( filling_mode == 0.0 && draw_mode == 1 ) {
86
+ v_color.a /= 2.0;
87
+ }
88
+ float angle;
89
+ if ( tail_angle > 0.0 ) {
90
+ angle = tail_angle * (-phase + 1.0) + start_angle;
91
+ } else {
92
+ angle = tail_angle * phase + start_angle;
93
+ }
94
+ if (is3D) {
95
+ vec3 pos = circleLimpFromLongLatRadCenterCartesian3D_accurate(center3d, radius_, angle);
96
+ v_pos = vec2(0.0, 0.0);
97
+ gl_Position = cartesian3DToGLPosition(pos);
98
+ }
99
+ else {
100
+ vec2 pos2 = circleLimpFromLongLatRadCenterMercatorCompass_accurate(center2d, radius_, angle);
101
+ v_pos = pos2;
102
+ gl_Position = mercatorXYToGLPosition(pos2);
103
+ }
104
+
105
+ gl_PointSize = 10.0;
106
+ }`;
107
+ const fragmentShaderSource = `#version 300 es` + POLE + PI + `
108
+ precision highp float;
109
+ // flat in int vid;
110
+ in vec4 v_color;
111
+ in vec2 v_pos;
112
+ // flat in float v_phase;
113
+ // in float v_angle;
114
+ out vec4 outColor;
115
+ 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; }
119
+ if ( v_pos.x < -POLE || v_pos.x > POLE || v_pos.y < -POLE || v_pos.y > POLE ) { discard; }
120
+ outColor = v_color;
121
+ }`;
122
+ export const ITEM_SIZE = 10;
123
+ export class Logic {
124
+ globe;
125
+ gl;
126
+ _lastMode;
127
+ _lastEdgeCount;
128
+ _lastAlphaMultiplier;
129
+ program;
130
+ _edgeCountLocation;
131
+ _draw_modeLocation;
132
+ _plugin_alpha_multiplierLocation;
133
+ cameraBlockBindingPoint;
134
+ cameraBlockTotem; // Type this based on your CameraUniformBlockTotem implementation
135
+ constructor(globe) {
136
+ this.globe = globe;
137
+ this.gl = globe.gl;
138
+ this._lastMode = 0;
139
+ this._lastEdgeCount = 64;
140
+ this._lastAlphaMultiplier = 1.0;
141
+ this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
142
+ const { gl, program } = this;
143
+ { // set attributes locations
144
+ gl.bindAttribLocation(program, 0, 'center2d');
145
+ gl.bindAttribLocation(program, 1, 'center3d');
146
+ gl.bindAttribLocation(program, 2, 'start_angle2d');
147
+ gl.bindAttribLocation(program, 3, 'tail_angle2d');
148
+ gl.bindAttribLocation(program, 4, 'start_angle3d');
149
+ gl.bindAttribLocation(program, 5, 'tail_angle3d');
150
+ gl.bindAttribLocation(program, 6, 'color');
151
+ gl.bindAttribLocation(program, 7, 'radius');
152
+ gl.bindAttribLocation(program, 8, 'filling_mode');
153
+ // vao
154
+ // instanced draw read 1
155
+ }
156
+ { // Uniforms
157
+ this._edgeCountLocation = gl.getUniformLocation(program, 'edge_count');
158
+ this._draw_modeLocation = gl.getUniformLocation(program, 'draw_mode');
159
+ this._plugin_alpha_multiplierLocation = gl.getUniformLocation(program, 'plugin_alpha_multiplier');
160
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
161
+ gl.useProgram(program);
162
+ gl.uniform1i(this._draw_modeLocation, this._lastMode);
163
+ gl.uniform1f(this._edgeCountLocation, this._lastEdgeCount);
164
+ gl.uniform1f(this._plugin_alpha_multiplierLocation, 1.0);
165
+ this.cameraBlockBindingPoint = 0;
166
+ this.cameraBlockTotem = globeProgramCache.getProgram(globe, CameraUniformBlockTotem);
167
+ const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
168
+ gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
169
+ gl.useProgram(currentProgram);
170
+ }
171
+ }
172
+ draw(length, vao, edgeCount, alphaMultiplier, drawMode) {
173
+ const { gl, program, cameraBlockTotem, cameraBlockBindingPoint } = this;
174
+ // gl.disable(gl.DEPTH_TEST);
175
+ gl.useProgram(program);
176
+ if (drawModeMap[drawMode] !== this._lastMode) {
177
+ gl.uniform1i(this._draw_modeLocation, drawModeMap[drawMode]);
178
+ this._lastMode = drawModeMap[drawMode];
179
+ }
180
+ if (edgeCount !== this._lastEdgeCount) {
181
+ gl.uniform1f(this._edgeCountLocation, edgeCount);
182
+ this._lastEdgeCount = edgeCount;
183
+ }
184
+ if (alphaMultiplier !== this._lastAlphaMultiplier) {
185
+ gl.uniform1f(this._plugin_alpha_multiplierLocation, alphaMultiplier);
186
+ this._lastAlphaMultiplier = alphaMultiplier;
187
+ }
188
+ const overdraw = drawModeMap[drawMode];
189
+ cameraBlockTotem.bind(cameraBlockBindingPoint);
190
+ gl.bindVertexArray(vao);
191
+ gl.drawArraysInstanced(gl[drawMode], 0, edgeCount + overdraw, length);
192
+ cameraBlockTotem.unbind(cameraBlockBindingPoint);
193
+ gl.bindVertexArray(null);
194
+ // gl.enable(gl.DEPTH_TEST);
195
+ }
196
+ free() {
197
+ noRegisterGlobeProgramCache.releaseProgram(this.globe, CameraUniformBlockTotem);
198
+ this.gl.deleteProgram(this.program);
199
+ this.program = null;
200
+ }
201
+ /**
202
+ * in vec2 center; // long, lat in radian
203
+ in float start_angle; // the start of partial circle from bearing point
204
+ in float tail_angle; // the rotation of the partial circle
205
+ in vec4 color;
206
+ in float radius; // in meter
207
+ in float filling_mode; // 0.0: constant, 1.0: fading, 2.0: hide
208
+ */
209
+ createVAO(center2dObj, center3dObj, startAngle2DObj, tailAngle2DObj, startAngle3DObj, tailAngle3DObj, colorObj, radiusObj, colorModeObj) {
210
+ const { gl } = this;
211
+ const vao = gl.createVertexArray();
212
+ 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
+ }
276
+ gl.bindVertexArray(null);
277
+ gl.bindBuffer(gl.ARRAY_BUFFER, null);
278
+ return vao;
279
+ }
280
+ createUBO() {
281
+ }
282
+ }
283
+ export const PieceOfPieProgramCache = Object.freeze({
284
+ get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
285
+ release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
286
+ });