@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,175 +0,0 @@
1
- import { createProgram } from "../../util/webglobjectbuilders";
2
- import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
3
- import { noRegisterGlobeProgramCache } from "../programcache";
4
- import { vaoAttributeLoader } from "../../util/account/util";
5
- import { longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1, circleLimpFromLongLatRadCenterCartesian3D_accurate, circleLimpFromLongLatRadCenterMercatorCompass_accurate, circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate, POLE } from "../../util/shaderfunctions/geometrytransformations";
6
- /**
7
- * TODO:
8
- * 1. integrate geometry functions for radius angle and center
9
- * 2. integrate attributes
10
- *
11
- * TODO:
12
- * center_position is too small or doenst loaded as expected.
13
- */
14
- const EDGE_COUNT_ON_SPHERE = 360;
15
- const vertexShaderSource = `#version 300 es
16
- precision highp float;
17
- ${CameraUniformBlockString}
18
- ${longLatRadToMercator}
19
- ${longLatRadToCartesian3D}
20
- ${cartesian3DToGLPosition}
21
- ${mercatorXYToGLPosition}
22
- ${realDistanceOnSphereR1}
23
- ${circleLimpFromLongLatRadCenterCartesian3D_accurate}
24
- ${circleLimpFromLongLatRadCenterMercatorCompass_accurate}
25
- ${circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate}
26
-
27
- uniform float edge_count;
28
-
29
- in vec2 center_position;
30
- in vec3 center_position3d;
31
- in float radius;
32
- in vec4 color;
33
- in float dash_ratio;
34
- in float dash_opacity;
35
-
36
- out float interpolation;
37
- out vec4 v_color;
38
- out float v_dash_ratio;
39
- out float v_dash_opacity;
40
- out vec2 v_limp;
41
- void main() {
42
- interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
43
- float angle = PI * 2.0 * interpolation;
44
- if ( is3D ) {
45
-
46
- vec3 position = circleLimpFromLongLatRadCenterCartesian3D_accurate(center_position3d, radius, angle);
47
-
48
- gl_Position = cartesian3DToGLPosition(position);
49
- v_limp = vec2(0.0, 0.0);
50
- } else {
51
- vec2 position;
52
- if ( radius < 0.0) {
53
- float cosine1 = cos(asin(tanh(center_position.y / 6378137.0)));
54
- position = circleLimpFromLongLatRadCenterMercatorCompass_accurate(center_position, radius / cosine1 , angle);
55
- } else {
56
- position = circleLimpFromLongLatRadCenterMercatorRealDistanceNew_accurate( center_position, radius, angle);
57
- }
58
- v_limp = position;
59
- gl_Position = mercatorXYToGLPosition( position);
60
-
61
- }
62
- v_dash_ratio = dash_ratio;
63
- v_dash_opacity = dash_opacity;
64
- v_color = color;
65
- gl_PointSize = 3.0;
66
-
67
- }`;
68
- const fragmentShaderSource = `#version 300 es
69
- ${POLE}
70
- precision highp float;
71
- uniform float opacity;
72
- in vec4 v_color;
73
- in float v_dash_ratio;
74
- in float v_dash_opacity;
75
- in float interpolation;
76
- in vec2 v_limp;
77
- out vec4 color;
78
- void main() {
79
- 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; }
80
- color = v_color;
81
- color.a *= opacity;
82
- if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
83
- if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
84
- color.a *= v_dash_opacity;
85
- }
86
- }
87
- `;
88
- class Logic {
89
- constructor(globe) {
90
- this.globe = globe;
91
- this.gl = globe.gl;
92
- this._lastOpacity = 1.0;
93
- this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
94
- const { gl, program } = this;
95
- this.program.uniforms = {
96
- opacity: gl.getUniformLocation(program, "opacity")
97
- };
98
- { // initial uniform values
99
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
100
- gl.useProgram(program);
101
- gl.uniform1f(program.uniforms.opacity, 1.0);
102
- gl.useProgram(currentProgram);
103
- }
104
- { // assign attribute locations
105
- gl.bindAttribLocation(program, 0, "center_position");
106
- gl.bindAttribLocation(program, 1, "center_position3d");
107
- gl.bindAttribLocation(program, 2, "radius");
108
- gl.bindAttribLocation(program, 3, "color");
109
- gl.bindAttribLocation(program, 4, "dash_ratio");
110
- gl.bindAttribLocation(program, 5, "dash_opacity");
111
- }
112
- this.cameraBindingPoint = 0;
113
- this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
114
- const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
115
- gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
116
- }
117
- createVAO(centerObj, center3dObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
118
- const { gl } = this;
119
- const vao = gl.createVertexArray();
120
- const divisor = 1;
121
- gl.bindVertexArray(vao);
122
- { // make this a function end import from account module.
123
- const { buffer, stride = 0, offset = 0 } = centerObj;
124
- vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
125
- }
126
- { // make this a function end import from account module.
127
- const { buffer, stride = 0, offset = 0 } = center3dObj;
128
- vaoAttributeLoader(gl, buffer, 1, 3, stride, offset, divisor);
129
- }
130
- {
131
- const { buffer, stride = 0, offset = 0 } = radiusObj;
132
- vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, divisor);
133
- }
134
- {
135
- const { buffer, stride = 0, offset = 0 } = colorObj;
136
- vaoAttributeLoader(gl, buffer, 3, 4, stride, offset, divisor);
137
- }
138
- {
139
- const { buffer, stride = 0, offset = 0 } = dashRatioObj;
140
- vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
141
- }
142
- {
143
- const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
144
- vaoAttributeLoader(gl, buffer, 5, 1, stride, offset, divisor);
145
- }
146
- gl.bindVertexArray(null);
147
- gl.bindVertexArray(null);
148
- return vao;
149
- }
150
- draw(vao, length, opacity) {
151
- const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
152
- gl.useProgram(program);
153
- if (this._lastOpacity !== opacity) {
154
- gl.uniform1f(program.uniforms.opacity, opacity);
155
- this._lastOpacity = opacity;
156
- }
157
- gl.bindVertexArray(vao);
158
- cameraBlockTotem.bind(cameraBindingPoint);
159
- gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
160
- gl.drawArraysInstanced(gl.POINTS, 0, EDGE_COUNT_ON_SPHERE + 1, length);
161
- cameraBlockTotem.unbind(cameraBindingPoint);
162
- gl.bindVertexArray(null);
163
- }
164
- free() {
165
- if (this.isFreed)
166
- return;
167
- CameraUniformBlockTotemCache.release(this.globe);
168
- this.gl.deleteProgram(this.program);
169
- this.isFreed = true;
170
- }
171
- }
172
- export const CircleCache = Object.freeze({
173
- get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
174
- release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
175
- });
@@ -1,164 +0,0 @@
1
- import { createProgram } from "../../util/webglobjectbuilders";
2
- import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
3
- import { noRegisterGlobeProgramCache } from "../programcache";
4
- import { vaoAttributeLoader } from "../../util/account/util";
5
- import { longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1, circleLimpFromLongLatRadCenterCartesian3D, circleLimpFromLongLatRadCenterMercatorCompass, circleLimpFromLongLatRadCenterMercatorRealDistance, POLE } from "../../util/shaderfunctions/geometrytransformations";
6
- /**
7
- * TODO:
8
- * 1. integrate geometry functions for radius angle and center
9
- * 2. integrate attributes
10
- *
11
- * TODO:
12
- * center_position is too small or doenst loaded as expected.
13
- */
14
- const EDGE_COUNT_ON_SPHERE = 360;
15
- const vertexShaderSource = `#version 300 es
16
- precision highp float;
17
- ${CameraUniformBlockString}
18
- ${longLatRadToMercator}
19
- ${longLatRadToCartesian3D}
20
- ${cartesian3DToGLPosition}
21
- ${mercatorXYToGLPosition}
22
- ${realDistanceOnSphereR1}
23
- ${circleLimpFromLongLatRadCenterCartesian3D}
24
- ${circleLimpFromLongLatRadCenterMercatorCompass}
25
- ${circleLimpFromLongLatRadCenterMercatorRealDistance}
26
-
27
- uniform float edge_count;
28
-
29
- in vec2 center_position;
30
- in float radius;
31
- in vec4 color;
32
- in float dash_ratio;
33
- in float dash_opacity;
34
-
35
- out float interpolation;
36
- out vec4 v_color;
37
- out float v_dash_ratio;
38
- out float v_dash_opacity;
39
- out vec2 v_limp;
40
- void main() {
41
- interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
42
- float angle = PI * 2.0 * interpolation;
43
- if ( is3D ) {
44
- vec3 position = circleLimpFromLongLatRadCenterCartesian3D( center_position, radius, angle);
45
- gl_Position = cartesian3DToGLPosition(position);
46
- v_limp = vec2(0.0, 0.0);
47
- } else {
48
- vec2 position;
49
- if (radius < 1400.0) {
50
- position = circleLimpFromLongLatRadCenterMercatorCompass( center_position, radius/ cos(center_position.y), angle);
51
- } else {
52
- position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_position, radius, angle);
53
- }
54
- v_limp = position;
55
- gl_Position = mercatorXYToGLPosition( position);
56
-
57
- }
58
- v_dash_ratio = dash_ratio;
59
- v_dash_opacity = dash_opacity;
60
- v_color = color;
61
-
62
- }`;
63
- const fragmentShaderSource = `#version 300 es
64
- ${POLE}
65
- precision highp float;
66
- uniform float opacity;
67
- in vec4 v_color;
68
- in float v_dash_ratio;
69
- in float v_dash_opacity;
70
- in float interpolation;
71
- in vec2 v_limp;
72
- out vec4 color;
73
- void main() {
74
- 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; }
75
- color = v_color;
76
- color.a *= opacity;
77
- if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
78
- if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
79
- color.a *= v_dash_opacity;
80
- }
81
- }
82
- `;
83
- class Logic {
84
- constructor(globe) {
85
- this.globe = globe;
86
- this.gl = globe.gl;
87
- this._lastOpacity = 1.0;
88
- this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
89
- const { gl, program } = this;
90
- this.program.uniforms = {
91
- opacity: gl.getUniformLocation(program, "opacity")
92
- };
93
- { // initial uniform values
94
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
95
- gl.useProgram(program);
96
- gl.uniform1f(program.uniforms.opacity, 1.0);
97
- gl.useProgram(currentProgram);
98
- }
99
- { // assign attribute locations
100
- gl.bindAttribLocation(program, 0, "center_position");
101
- gl.bindAttribLocation(program, 1, "radius");
102
- gl.bindAttribLocation(program, 2, "color");
103
- gl.bindAttribLocation(program, 3, "dash_ratio");
104
- gl.bindAttribLocation(program, 4, "dash_opacity");
105
- }
106
- this.cameraBindingPoint = 0;
107
- this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
108
- const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
109
- gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
110
- }
111
- createVAO(centerObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
112
- const { gl } = this;
113
- const vao = gl.createVertexArray();
114
- const divisor = 1;
115
- gl.bindVertexArray(vao);
116
- { // make this a function end import from account module.
117
- const { buffer, stride = 0, offset = 0 } = centerObj;
118
- vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
119
- }
120
- {
121
- const { buffer, stride = 0, offset = 0 } = radiusObj;
122
- vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
123
- }
124
- {
125
- const { buffer, stride = 0, offset = 0 } = colorObj;
126
- vaoAttributeLoader(gl, buffer, 2, 4, stride, offset, divisor);
127
- }
128
- {
129
- const { buffer, stride = 0, offset = 0 } = dashRatioObj;
130
- vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, divisor);
131
- }
132
- {
133
- const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
134
- vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
135
- }
136
- gl.bindVertexArray(null);
137
- gl.bindVertexArray(null);
138
- return vao;
139
- }
140
- draw(vao, length, opacity) {
141
- const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
142
- gl.useProgram(program);
143
- if (this._lastOpacity !== opacity) {
144
- gl.uniform1f(program.uniforms.opacity, opacity);
145
- this._lastOpacity = opacity;
146
- }
147
- gl.bindVertexArray(vao);
148
- cameraBlockTotem.bind(cameraBindingPoint);
149
- gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
150
- cameraBlockTotem.unbind(cameraBindingPoint);
151
- gl.bindVertexArray(null);
152
- }
153
- free() {
154
- if (this.isFreed)
155
- return;
156
- CameraUniformBlockTotemCache.release(this.globe);
157
- this.gl.deleteProgram(this.program);
158
- this.isFreed = true;
159
- }
160
- }
161
- export const CircleCache = Object.freeze({
162
- get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
163
- release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
164
- });
@@ -1,109 +0,0 @@
1
- import { createProgram } from './util';
2
- import { CameraUniformBlockTotemCache, CameraUniformBlockString } from '../totems';
3
- import { cartesian3DToGLPosition, R_3D } from '../../util/shaderfunctions/geometrytransformations';
4
- import { noRegisterGlobeProgramCache } from '../programcache';
5
- import { attributeLoader } from '../../util/gl-util/buffer/attribute-loader';
6
- import '../draw-options/types';
7
- import { drawInstanced } from '../draw-options/methods';
8
- const vs = `#version 300 es
9
- ${R_3D}
10
- ${CameraUniformBlockString}
11
- ${cartesian3DToGLPosition}
12
- in vec3 pos3D
13
- in vec4 color;
14
- out float ratio;
15
- out flat vec4 vColor;
16
- void main(){
17
- if ( gl_VertexID == 0) {
18
- gl_Position = cartesian3DToGLPosition(pos3D);
19
- ratio =0.0;
20
- } else {
21
- vec3 sea_level_pos3D = norm(pos3D) * R_3D;
22
- gl_Position = cartesian3DToGLPosition(pos3D);
23
- ratio = 1.0;
24
- }
25
- vColor = color;
26
- }`;
27
- const fs = `#version 300 es
28
- uniform float opacity;
29
- uniform float phase;
30
- uniform float fadeOpacity;
31
- in flat vec4 vColor;
32
- in float ratio;
33
- out vec4 fragColor;
34
- void main(){
35
- fragColor = vec4( vColor.rgb, vColor.a * opacity);
36
- if (fadeOpacity < 1.0) {
37
- float alpha= mix( fadeOpacity, vColor.a, fract( ratio + phase ));
38
- fragColor.a *= alpha;
39
- }
40
- }`;
41
- class Logic {
42
- constructor(globe) {
43
- this.globe = globe;
44
- this.gl = globe.gl;
45
- this.program = createProgram(this.gl, vs, fs);
46
- const { gl, program } = this;
47
- this._opacity = {
48
- lastValue: 1.0,
49
- location: gl.getUniformLocation(program, 'opacity')
50
- };
51
- this._phase = {
52
- lastValue: 1.0,
53
- location: gl.getUniformLocation(program, 'phase')
54
- };
55
- this._fadeOpacity = {
56
- lastValue: 1.0,
57
- location: gl.getUniformBlockLocation(program, 'fadeOpacity')
58
- };
59
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
60
- gl.useProgram(program);
61
- [this._opacity, this._phase, this._fadeOpacity].forEach((wrapper) => gl.uniform1f(wrapper.location, wrapper.lastValue));
62
- gl.useProgram(currentProgram);
63
- gl.useProgram(program);
64
- gl.bindAttribLocation(program, 0, 'pos3D');
65
- gl.bindAttribLocation(program, 1, 'color');
66
- this.cameraUniformBlockTotem = new CameraUniformBlockTotemCache.get(globe);
67
- this.cameraBlockBindingPoint = 0;
68
- const cameraBlockIndex = gl.getUniformBlockLocation(program, 'CameraUniformBlock');
69
- gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
70
- }
71
- createVao(pos3DObj, colorObj) {
72
- const { gl } = this;
73
- const vao = gl.createVertexArray();
74
- const divisor = 1;
75
- gl.bindVertexArray(vao);
76
- attributeLoader(gl, pos3DObj, 0, 3, { divisor });
77
- attributeLoader(gl, colorObj, 1, 4, { divisor, escapeValue: [-1, -1, -1, -1] });
78
- gl.bindVertexArray(null);
79
- this._vaoCache.push(vao);
80
- return vao;
81
- }
82
- /**
83
- *
84
- * @param {WebGL2RenderingContext.vertexArrayObject} vao
85
- * @param {Render} drawOptions
86
- */
87
- draw(vao, drawOptions, { opacity = 1.0, fadeOpacity = 1.0, }) {
88
- const { globe, gl, program, _opacity, _fadeOpacity } = this;
89
- gl.useProgram(program);
90
- gl.bindVertexArray(vao);
91
- if (fadeOpacity < 1.0) {
92
- this._updatePhase();
93
- globe.drawRender();
94
- }
95
- if (fadeOpacity !== _fadeOpacity.lastValue) {
96
- _fadeOpacity.lastValue = fadeOpacity;
97
- gl.uniform1f(_fadeOpacity.location, fadeOpacity);
98
- }
99
- if (opacity !== _opacity.lastValue) {
100
- _opacity.lastValue = opacity;
101
- gl.uniform1f(_opacity.location, opacity);
102
- }
103
- drawInstanced(gl, gl.TRIANGLE_FAN, drawOptions);
104
- }
105
- _updatePhase() {
106
- this._phase.lastValue = (Date.now() / 3.0) % 1000;
107
- gl.uniform1f(_phase.location, _phase.lastValue);
108
- }
109
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,106 +0,0 @@
1
- import { globeProgramCache } from "../programcache";
2
- export const WebglobeInfoUniformBlockString = `
3
- layout(std140) uniform WebglobeInfo {
4
- vec2 canvas_resolution;
5
- vec2 mouse_radian_long_lat;
6
- vec2 mouse_pixel_xy;
7
- float north_angle;
8
- float world_tilt;
9
- float earth_distance;
10
- };
11
- `;
12
- export default class CameraUniformBlockTotem {
13
- constructor() {
14
- this.id = "CameraUniformBlockTotem";
15
- this.description = `Sets a uniform block and provides buffer for it. The following is the glsl uniform block:` + CameraUniformBlockString;
16
- this.gl = null;
17
- this.globe = null;
18
- this.ubo = null;
19
- }
20
- init(globe, gl) {
21
- this.gl = gl;
22
- this.globe = globe;
23
- this.ubo = this._createUBO();
24
- this.traslateFloat32 = new Float32Array(3);
25
- this.mapWHFloat32 = new Float32Array(2);
26
- this.setGeometry();
27
- this.resize();
28
- }
29
- _createUBO() {
30
- const { gl } = this;
31
- const ubo = gl.createBuffer();
32
- gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
33
- gl.bufferData(gl.UNIFORM_BUFFER, 164, gl.STREAM_DRAW);
34
- gl.bindBufferBase(gl.UNIFORM_BUFFER, 0, ubo);
35
- gl.bindBuffer(gl.UNIFORM_BUFFER, null);
36
- return ubo;
37
- }
38
- resize() {
39
- const { gl, globe, ubo } = this;
40
- gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
41
- gl.bufferSubData(gl.UNIFORM_BUFFER, 152, new Float32Array([globe.api_ScrW(), globe.api_ScrH()]));
42
- gl.bindBuffer(gl.UNIFORM_BUFFER, null);
43
- }
44
- setGeometry() {
45
- const { gl, globe, ubo } = this;
46
- const is3D = globe.api_GetCurrentGeometry() === 0;
47
- gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
48
- gl.bufferSubData(gl.UNIFORM_BUFFER, 140, new Float32Array([is3D]));
49
- }
50
- draw3D(projection, modelView, translate) {
51
- const { gl, traslateFloat32, ubo, mapWHFloat32, globe } = this;
52
- gl.bindBuffer(gl.UNIFORM_BUFFER, ubo);
53
- { // view, projection, translate
54
- gl.bufferSubData(gl.UNIFORM_BUFFER, 0, modelView);
55
- gl.bufferSubData(gl.UNIFORM_BUFFER, 64, projection);
56
- traslateFloat32.set([translate.x, translate.y, translate.z], 0);
57
- gl.bufferSubData(gl.UNIFORM_BUFFER, 128, traslateFloat32);
58
- }
59
- {
60
- // zoom level
61
- gl.bufferSubData(gl.UNIFORM_BUFFER, 160, new Float32Array([globe.api_GetCurrentLODWithDecimal()]));
62
- }
63
- { // mapWH
64
- if (globe.api_GetCurrentGeometry() === 1) {
65
- const { width, height } = globe.api_GetCurrentWorldWH();
66
- mapWHFloat32.set([width, height]);
67
- gl.bufferSubData(gl.UNIFORM_BUFFER, 144, mapWHFloat32);
68
- }
69
- }
70
- gl.bindBuffer(gl.UNIFORM_BUFFER, null);
71
- }
72
- getUBO() {
73
- return this.ubo;
74
- }
75
- bind(bindingPoint) {
76
- const { gl, ubo } = this;
77
- gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, ubo);
78
- }
79
- unbind(bindingPoint) {
80
- const { gl } = this;
81
- gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPoint, null);
82
- }
83
- free() {
84
- const { gl, ubo } = this;
85
- gl.deleteBuffer(ubo);
86
- }
87
- readBuffer() {
88
- const result = new Float32Array(41);
89
- this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, this.ubo);
90
- this.gl.getBufferSubData(this.gl.UNIFORM_BUFFER, 0, result);
91
- this.gl.bindBuffer(this.gl.UNIFORM_BUFFER, null);
92
- return {
93
- view: result.slice(0, 16),
94
- projection: result.slice(16, 32),
95
- translate: result.slice(32, 35),
96
- is3D: result[35],
97
- mapWH: result.slice(36, 38),
98
- screenWH: result.slice(38, 40),
99
- z_level: result[40]
100
- };
101
- }
102
- }
103
- export const CameraUniformBlockTotemCache = Object.freeze({
104
- get: (globe) => { return globeProgramCache.getProgram(globe, CameraUniformBlockTotem); },
105
- release: (globe) => { return globeProgramCache.releaseProgram(globe, CameraUniformBlockTotem); }
106
- });