@pirireis/webglobeplugins 0.8.6 → 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.
- package/bearing-line/plugin.js +51 -43
- package/circle-line-chain/plugin.js +52 -44
- package/compass-rose/compass-rose-padding-flat.js +3 -0
- package/compassrose/compassrose.js +1 -8
- package/heatwave/isobar/plugin.js +4 -1
- package/heatwave/isobar/quadtreecontours.js +0 -2
- package/heatwave/plugins/heatwaveglobeshell.js +2 -0
- package/package.json +1 -1
- package/partialrings/goals.md +2 -0
- package/partialrings/plugin.js +2 -1
- package/point-glow-line-to-earth/draw-subset-obj.js +27 -0
- package/point-glow-line-to-earth/keymethod.js +0 -0
- package/point-glow-line-to-earth/plugin.js +439 -0
- package/point-glow-line-to-earth/types.js +26 -0
- package/point-heat-map/index.js +0 -3
- package/point-heat-map/plugin-webworker.js +4 -9
- package/point-heat-map/point-to-heat-map-flow.js +0 -6
- package/point-tracks/plugin.js +4 -4
- package/programs/arrowfield/logic.js +6 -4
- package/programs/arrowfield/object.js +1 -1
- package/programs/float2legendwithratio/object.js +5 -4
- package/programs/globe-util/is-globe-moved.js +27 -0
- package/programs/globeshell/wiggle/logic.js +3 -7
- package/programs/globeshell/wiggle/object.js +1 -2
- package/programs/line-on-globe/circle-accurate-3d.js +16 -23
- package/programs/line-on-globe/circle-accurate-flat.js +21 -21
- package/programs/line-on-globe/lines-color-instanced-flat.js +6 -7
- package/programs/line-on-globe/naive-accurate-flexible.js +239 -0
- package/programs/line-on-globe/to-the-surface.js +129 -0
- package/programs/picking/pickable-renderer.js +216 -0
- package/programs/point-on-globe/element-globe-surface-glow.js +168 -0
- package/programs/point-on-globe/element-point-glow.js +184 -0
- package/programs/point-on-globe/square-pixel-point.js +2 -4
- package/programs/programcache.js +9 -0
- package/programs/rings/partial-ring/piece-of-pie.js +1 -1
- package/programs/totems/camerauniformblock.js +23 -2
- package/rangerings/plugin.js +9 -6
- package/shaders/fragment-toy/firework.js +55 -0
- package/shaders/fragment-toy/singularity.js +59 -0
- package/types.js +16 -0
- package/util/account/single-attribute-buffer-management/buffer-manager.js +1 -5
- package/util/account/util.js +17 -7
- package/util/check/typecheck.js +11 -0
- package/util/gl-util/buffer/integrate-buffer.js +74 -0
- package/util/gl-util/draw-options/client.js +59 -0
- package/util/gl-util/draw-options/methods.js +46 -0
- package/util/gl-util/draw-options/types.js +18 -0
- package/util/gl-util/uniform-block/manager.js +176 -0
- package/util/gl-util/uniform-block/roadmap.md +70 -0
- package/util/gl-util/uniform-block/shader.js +0 -0
- package/util/gl-util/uniform-block/types.js +7 -0
- package/util/jshelpers/equality.js +17 -0
- package/util/picking/picker-displayer.js +1 -1
- package/util/programs/shapesonglobe.js +17 -19
- package/util/shaderfunctions/geometrytransformations.js +27 -63
- package/bearing-line/roadmap.md +0 -15
- package/point-heat-map/plugin.js +0 -132
- package/programs/line-on-globe/naive-accurate.js +0 -221
- package/programs/line-on-globe/to-the-origin.js +0 -164
- package/util/jshelpers/timemethods.js +0 -19
- /package/{programs/point-on-globe/element-draw-glow.js → point-glow-line-to-earth/adaptors.js} +0 -0
|
@@ -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
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
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 ){
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
+
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { createProgram } from './util'
|
|
2
|
+
|
|
3
|
+
import { CameraUniformBlockTotemCache, CameraUniformBlockString } from '../totems';
|
|
4
|
+
import { cartesian3DToGLPosition, R_3D } from '../../util/shaderfunctions/geometrytransformations';
|
|
5
|
+
import { noRegisterGlobeProgramCache } from '../programcache';
|
|
6
|
+
import { attributeLoader } from '../../util/gl-util/buffer/integrate-buffer';
|
|
7
|
+
import '../draw-options/types';
|
|
8
|
+
import { drawInstanced } from '../draw-options/methods';
|
|
9
|
+
|
|
10
|
+
const vs = `#version 300 es
|
|
11
|
+
${R_3D}
|
|
12
|
+
${CameraUniformBlockString}
|
|
13
|
+
${cartesian3DToGLPosition}
|
|
14
|
+
in vec3 pos3D
|
|
15
|
+
in vec4 color;
|
|
16
|
+
out float ratio;
|
|
17
|
+
out flat vec4 vColor;
|
|
18
|
+
void main(){
|
|
19
|
+
if ( gl_VertexID == 0) {
|
|
20
|
+
gl_Position = cartesian3DToGLPosition(pos3D);
|
|
21
|
+
ratio =0.0;
|
|
22
|
+
} else {
|
|
23
|
+
vec3 sea_level_pos3D = norm(pos3D) * R_3D;
|
|
24
|
+
gl_Position = cartesian3DToGLPosition(pos3D);
|
|
25
|
+
ratio = 1.0;
|
|
26
|
+
}
|
|
27
|
+
vColor = color;
|
|
28
|
+
}`;
|
|
29
|
+
|
|
30
|
+
const fs = `#version 300 es
|
|
31
|
+
uniform float opacity;
|
|
32
|
+
uniform float phase;
|
|
33
|
+
uniform float fadeOpacity;
|
|
34
|
+
in flat vec4 vColor;
|
|
35
|
+
in float ratio;
|
|
36
|
+
out vec4 fragColor;
|
|
37
|
+
void main(){
|
|
38
|
+
fragColor = vec4( vColor.rgb, vColor.a * opacity);
|
|
39
|
+
if (fadeOpacity < 1.0) {
|
|
40
|
+
float alpha= mix( fadeOpacity, vColor.a, fract( ratio + phase ));
|
|
41
|
+
fragColor.a *= alpha;
|
|
42
|
+
}
|
|
43
|
+
}`;
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class Logic {
|
|
49
|
+
constructor(globe) {
|
|
50
|
+
this.globe = globe;
|
|
51
|
+
this.gl = globe.gl;
|
|
52
|
+
|
|
53
|
+
this.program = createProgram(this.gl, vs, fs);
|
|
54
|
+
const { gl, program } = this;
|
|
55
|
+
|
|
56
|
+
this._opacity = {
|
|
57
|
+
lastValue: 1.0,
|
|
58
|
+
location: gl.getUniformLocation(program, 'opacity')
|
|
59
|
+
}
|
|
60
|
+
this._phase = {
|
|
61
|
+
lastValue: 1.0,
|
|
62
|
+
location: gl.getUniformLocation(program, 'phase')
|
|
63
|
+
}
|
|
64
|
+
this._fadeOpacity = {
|
|
65
|
+
lastValue: 1.0,
|
|
66
|
+
location: gl.getUniformBlockLocation(program, 'fadeOpacity')
|
|
67
|
+
}
|
|
68
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
69
|
+
gl.useProgram(program);
|
|
70
|
+
[this._opacity, this._phase, this._fadeOpacity].forEach((wrapper) => gl.uniform1f(wrapper.location, wrapper.lastValue))
|
|
71
|
+
gl.useProgram(currentProgram)
|
|
72
|
+
gl.useProgram(program);
|
|
73
|
+
gl.bindAttribLocation(program, 0, 'pos3D');
|
|
74
|
+
gl.bindAttribLocation(program, 1, 'color');
|
|
75
|
+
|
|
76
|
+
this.cameraUniformBlockTotem = new CameraUniformBlockTotemCache.get(globe);
|
|
77
|
+
this.cameraBlockBindingPoint = 0;
|
|
78
|
+
const cameraBlockIndex = gl.getUniformBlockLocation(program, 'CameraUniformBlock');
|
|
79
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
createVao(pos3DObj, colorObj) {
|
|
83
|
+
const { gl } = this;
|
|
84
|
+
const vao = gl.createVertexArray();
|
|
85
|
+
const divisor = 1;
|
|
86
|
+
gl.bindVertexArray(vao);
|
|
87
|
+
|
|
88
|
+
attributeLoader(gl, pos3DObj, 0, 3, { divisor });
|
|
89
|
+
attributeLoader(gl, colorObj, 1, 4, { divisor, escapeValue: [-1, -1, -1, -1] });
|
|
90
|
+
|
|
91
|
+
gl.bindVertexArray(null);
|
|
92
|
+
this._vaoCache.push(vao);
|
|
93
|
+
return vao;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
*
|
|
99
|
+
* @param {WebGL2RenderingContext.vertexArrayObject} vao
|
|
100
|
+
* @param {Render} drawOptions
|
|
101
|
+
*/
|
|
102
|
+
draw(vao, drawOptions, { opacity = 1.0, fadeOpacity = 1.0, }) {
|
|
103
|
+
|
|
104
|
+
const { globe, gl, program, _opacity, _fadeOpacity } = this;
|
|
105
|
+
gl.useProgram(program);
|
|
106
|
+
gl.bindVertexArray(vao);
|
|
107
|
+
|
|
108
|
+
if (fadeOpacity < 1.0) {
|
|
109
|
+
this._updatePhase();
|
|
110
|
+
globe.drawRender();
|
|
111
|
+
}
|
|
112
|
+
if (fadeOpacity !== _fadeOpacity.lastValue) {
|
|
113
|
+
_fadeOpacity.lastValue = fadeOpacity;
|
|
114
|
+
gl.uniform1f(_fadeOpacity.location, fadeOpacity);
|
|
115
|
+
}
|
|
116
|
+
if (opacity !== _opacity.lastValue) {
|
|
117
|
+
_opacity.lastValue = opacity;
|
|
118
|
+
gl.uniform1f(_opacity.location, opacity);
|
|
119
|
+
}
|
|
120
|
+
drawInstanced(gl, gl.TRIANGLE_FAN, drawOptions)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
_updatePhase() {
|
|
125
|
+
this._phase.lastValue = (Date.now() / 3.0) % 1000;
|
|
126
|
+
gl.uniform1f(_phase.location, _phase.lastValue);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|