@pirireis/webglobeplugins 0.2.0 → 0.3.1
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/Math/angle-calculation.js +12 -0
- package/Math/index.js +0 -0
- package/bearing-line/index.js +2 -0
- package/bearing-line/plugin.js +240 -72
- package/bearing-line/roadmap.md +14 -2
- package/package.json +1 -1
- package/partialrings/program.js +98 -25
- package/programs/line-on-globe/angled-line.js +206 -0
- package/programs/line-on-globe/circle.js +193 -0
- package/programs/line-on-globe/index.js +0 -1
- package/programs/line-on-globe/naive.js +102 -23
- package/programs/rings/distancering/circleflatprogram.js +2 -2
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +2 -2
- package/programs/rings/distancering/paddyflatprogram.js +2 -2
- package/programs/totems/camerauniformblock.js +9 -0
- package/programs/totems/index.js +2 -2
- package/rangerings/rangerings.js +0 -2
- package/util/account/bufferoffsetmanager.js +0 -1
- package/util/account/index.js +5 -1
- package/util/account/single-attribute-buffer-management/buffer-manager.js +119 -0
- package/util/account/single-attribute-buffer-management/buffer-orchestrator.js +256 -0
- package/util/account/single-attribute-buffer-management/index.js +4 -0
- package/util/account/util.js +9 -0
- package/util/shaderfunctions/geometrytransformations.js +21 -10
- package/wind/plugin.js +1 -1
- package/write-text/context-text.js +86 -0
- package/write-text/index.js +1 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// angle radius, rgba, dashRatio, rgbaMode
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import { createProgram } from "../../util";
|
|
5
|
+
import { CameraUniformBlockTotemCache, CameraUniformBlockString } from "../totems";
|
|
6
|
+
import {
|
|
7
|
+
longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition,
|
|
8
|
+
circleLimpFromLongLatRadCenterCartesian3D,
|
|
9
|
+
circleLimpFromLongLatRadCenterMercatorCompass,
|
|
10
|
+
circleLimpFromLongLatRadCenterMercatorRealDistance,
|
|
11
|
+
POLE
|
|
12
|
+
} from "../../util/shaderfunctions/geometrytransformations";
|
|
13
|
+
import { noRegisterGlobeProgramCache } from "../programcache";
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
const EDGE_COUNT_ON_SPHERE = 50;
|
|
17
|
+
|
|
18
|
+
const vertexShaderSource = `#version 300 es
|
|
19
|
+
precision highp float;
|
|
20
|
+
|
|
21
|
+
${CameraUniformBlockString}
|
|
22
|
+
${longLatRadToMercator}
|
|
23
|
+
${longLatRadToCartesian3D}
|
|
24
|
+
${cartesian3DToGLPosition}
|
|
25
|
+
${mercatorXYToGLPosition}
|
|
26
|
+
${circleLimpFromLongLatRadCenterCartesian3D}
|
|
27
|
+
${circleLimpFromLongLatRadCenterMercatorCompass}
|
|
28
|
+
${circleLimpFromLongLatRadCenterMercatorRealDistance}
|
|
29
|
+
|
|
30
|
+
in vec2 center_point;
|
|
31
|
+
in float angle;
|
|
32
|
+
in float radius;
|
|
33
|
+
in vec4 rgba;
|
|
34
|
+
in float dash_ratio;
|
|
35
|
+
in float dash_opacity;
|
|
36
|
+
|
|
37
|
+
out vec4 v_color;
|
|
38
|
+
out float v_dash_ratio;
|
|
39
|
+
out float interpolation;
|
|
40
|
+
out float v_dash_opacity;
|
|
41
|
+
out vec2 v_limp;
|
|
42
|
+
// TODO: Draw World Boundaries
|
|
43
|
+
void main() {
|
|
44
|
+
if ( is3D ) {
|
|
45
|
+
interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE - 1}.0;
|
|
46
|
+
float radius_ = radius* interpolation;
|
|
47
|
+
vec3 position = circleLimpFromLongLatRadCenterCartesian3D( center_point, radius_, angle);
|
|
48
|
+
gl_Position = cartesian3DToGLPosition( position);
|
|
49
|
+
v_limp = vec2(0.0, 0.0);
|
|
50
|
+
} else {
|
|
51
|
+
interpolation = float( gl_VertexID );
|
|
52
|
+
float radius_ = radius * interpolation;
|
|
53
|
+
vec2 position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_point, radius_, angle);
|
|
54
|
+
v_limp = position;
|
|
55
|
+
gl_Position = mercatorXYToGLPosition( position);
|
|
56
|
+
}
|
|
57
|
+
v_dash_opacity = dash_opacity;
|
|
58
|
+
v_color = rgba;
|
|
59
|
+
v_dash_ratio = dash_ratio;
|
|
60
|
+
}`;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
const fragmentShaderSource = `#version 300 es
|
|
65
|
+
${POLE}
|
|
66
|
+
precision highp float;
|
|
67
|
+
|
|
68
|
+
uniform float opacity;
|
|
69
|
+
in vec4 v_color;
|
|
70
|
+
in float v_dash_ratio;
|
|
71
|
+
in float v_dash_opacity;
|
|
72
|
+
in float interpolation;
|
|
73
|
+
in vec2 v_limp;
|
|
74
|
+
out vec4 color;
|
|
75
|
+
|
|
76
|
+
void main() {
|
|
77
|
+
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; }
|
|
78
|
+
color = vec4(v_color.rgb, v_color.a * opacity);
|
|
79
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
|
|
80
|
+
color.a *= v_dash_opacity;
|
|
81
|
+
}
|
|
82
|
+
}`;
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
class Logic {
|
|
86
|
+
|
|
87
|
+
constructor(globe) {
|
|
88
|
+
|
|
89
|
+
this.globe = globe;
|
|
90
|
+
this.gl = globe.gl;
|
|
91
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
92
|
+
this._lastOpacity = 1;
|
|
93
|
+
|
|
94
|
+
const { gl, program } = this;
|
|
95
|
+
{ // assign attribute locations
|
|
96
|
+
gl.bindAttribLocation(program, 0, "center_point");
|
|
97
|
+
gl.bindAttribLocation(program, 1, "angle");
|
|
98
|
+
gl.bindAttribLocation(program, 2, "radius");
|
|
99
|
+
gl.bindAttribLocation(program, 3, "rgba");
|
|
100
|
+
gl.bindAttribLocation(program, 4, "dash_ratio");
|
|
101
|
+
gl.bindAttribLocation(program, 5, "dash_opacity");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
{
|
|
105
|
+
this._opacityLocation = gl.getUniformLocation(program, "opacity");
|
|
106
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
107
|
+
gl.useProgram(program);
|
|
108
|
+
gl.uniform1f(this._opacityLocation, this._lastOpacity);
|
|
109
|
+
gl.useProgram(currentProgram);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.cameraBlockBindingPoint = 0;
|
|
113
|
+
const cameraBlockIndex = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
114
|
+
this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
|
|
115
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this.cameraBlockBindingPoint);
|
|
116
|
+
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
draw(vao, length, opacity) {
|
|
121
|
+
const { gl, program, globe, cameraBlockTotem, cameraBlockBindingPoint } = this;
|
|
122
|
+
gl.useProgram(program);
|
|
123
|
+
if (opacity !== this._lastOpacity) {
|
|
124
|
+
gl.uniform1f(this._opacityLocation, opacity);
|
|
125
|
+
this._lastOpacity = opacity;
|
|
126
|
+
}
|
|
127
|
+
const drawCount = globe.api_GetCurrentGeometry() === 0 ? EDGE_COUNT_ON_SPHERE : 2;
|
|
128
|
+
gl.bindVertexArray(vao);
|
|
129
|
+
cameraBlockTotem.bind(cameraBlockBindingPoint)
|
|
130
|
+
// gl.disable(gl.DEPTH_TEST);
|
|
131
|
+
gl.drawArraysInstanced(gl.LINE_STRIP, 0, drawCount, length);
|
|
132
|
+
gl.bindVertexArray(null);
|
|
133
|
+
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
134
|
+
// gl.enable(gl.DEPTH_TEST);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
createVAO(centerCoords, angle, radius, rgba, dashRatio, dashOpacity) {
|
|
139
|
+
|
|
140
|
+
const { gl } = this;
|
|
141
|
+
const vao = gl.createVertexArray();
|
|
142
|
+
gl.bindVertexArray(vao);
|
|
143
|
+
{
|
|
144
|
+
const { buffer, stride = 0, offset = 0 } = centerCoords;
|
|
145
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
146
|
+
gl.enableVertexAttribArray(0);
|
|
147
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
|
|
148
|
+
gl.vertexAttribDivisor(0, 1);
|
|
149
|
+
}
|
|
150
|
+
{
|
|
151
|
+
const { buffer, stride = 0, offset = 0 } = angle;
|
|
152
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
153
|
+
gl.enableVertexAttribArray(1);
|
|
154
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, stride, offset);
|
|
155
|
+
gl.vertexAttribDivisor(1, 1);
|
|
156
|
+
}
|
|
157
|
+
{
|
|
158
|
+
const { buffer, stride = 0, offset = 0 } = radius;
|
|
159
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
160
|
+
gl.enableVertexAttribArray(2);
|
|
161
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
|
|
162
|
+
gl.vertexAttribDivisor(2, 1);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
{
|
|
166
|
+
const { buffer, stride = 0, offset = 0 } = rgba;
|
|
167
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
168
|
+
gl.enableVertexAttribArray(3);
|
|
169
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, stride, offset);
|
|
170
|
+
gl.vertexAttribDivisor(3, 1);
|
|
171
|
+
}
|
|
172
|
+
{
|
|
173
|
+
const { buffer, stride = 0, offset = 0 } = dashRatio;
|
|
174
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
175
|
+
gl.enableVertexAttribArray(4);
|
|
176
|
+
gl.vertexAttribPointer(4, 1, gl.FLOAT, false, stride, offset);
|
|
177
|
+
gl.vertexAttribDivisor(4, 1);
|
|
178
|
+
}
|
|
179
|
+
{
|
|
180
|
+
const { buffer, stride = 0, offset = 0 } = dashOpacity;
|
|
181
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
182
|
+
gl.enableVertexAttribArray(5);
|
|
183
|
+
gl.vertexAttribPointer(5, 1, gl.FLOAT, false, stride, offset);
|
|
184
|
+
gl.vertexAttribDivisor(5, 1);
|
|
185
|
+
}
|
|
186
|
+
gl.bindVertexArray(null);
|
|
187
|
+
return vao;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
free() {
|
|
192
|
+
if (this.isFreed) return;
|
|
193
|
+
CameraUniformBlockTotemCache.release(this.globe);
|
|
194
|
+
this.cameraBlockTotem = null;
|
|
195
|
+
this.gl.deleteProgram(this.program);
|
|
196
|
+
this.isFreed = true;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
export const AngledLineProgramCache = Object.freeze({
|
|
204
|
+
get: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
|
|
205
|
+
release: (globe) => { return noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
|
|
206
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
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 {
|
|
6
|
+
longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
|
|
7
|
+
circleLimpFromLongLatRadCenterCartesian3D,
|
|
8
|
+
circleLimpFromLongLatRadCenterMercatorCompass,
|
|
9
|
+
circleLimpFromLongLatRadCenterMercatorRealDistance,
|
|
10
|
+
POLE
|
|
11
|
+
} from "../../util/shaderfunctions/geometrytransformations";
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* TODO:
|
|
16
|
+
* 1. integrate geometry functions for radius angle and center
|
|
17
|
+
* 2. integrate attributes
|
|
18
|
+
*
|
|
19
|
+
* TODO:
|
|
20
|
+
* center_position is too small or doenst loaded as expected.
|
|
21
|
+
*/
|
|
22
|
+
const EDGE_COUNT_ON_SPHERE = 360;
|
|
23
|
+
|
|
24
|
+
const vertexShaderSource = `#version 300 es
|
|
25
|
+
precision highp float;
|
|
26
|
+
${CameraUniformBlockString}
|
|
27
|
+
${longLatRadToMercator}
|
|
28
|
+
${longLatRadToCartesian3D}
|
|
29
|
+
${cartesian3DToGLPosition}
|
|
30
|
+
${mercatorXYToGLPosition}
|
|
31
|
+
${realDistanceOnSphereR1}
|
|
32
|
+
${circleLimpFromLongLatRadCenterCartesian3D}
|
|
33
|
+
${circleLimpFromLongLatRadCenterMercatorCompass}
|
|
34
|
+
${circleLimpFromLongLatRadCenterMercatorRealDistance}
|
|
35
|
+
|
|
36
|
+
uniform float edge_count;
|
|
37
|
+
|
|
38
|
+
in vec2 center_position;
|
|
39
|
+
in float start_angle;
|
|
40
|
+
in float radius;
|
|
41
|
+
in vec4 color;
|
|
42
|
+
in float dash_ratio;
|
|
43
|
+
in float dash_opacity;
|
|
44
|
+
|
|
45
|
+
out float interpolation;
|
|
46
|
+
out vec4 v_color;
|
|
47
|
+
out float v_dash_ratio;
|
|
48
|
+
out float v_dash_opacity;
|
|
49
|
+
out vec2 v_limp;
|
|
50
|
+
void main() {
|
|
51
|
+
interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
|
|
52
|
+
float angle = PI * 2.0 * interpolation;
|
|
53
|
+
if ( is3D ) {
|
|
54
|
+
vec3 position = circleLimpFromLongLatRadCenterCartesian3D( center_position, radius, angle);
|
|
55
|
+
gl_Position = cartesian3DToGLPosition(position);
|
|
56
|
+
v_limp = vec2(0.0, 0.0);
|
|
57
|
+
} else {
|
|
58
|
+
vec2 position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_position, radius, angle);
|
|
59
|
+
v_limp = position;
|
|
60
|
+
gl_Position = mercatorXYToGLPosition( position);
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
v_dash_ratio = dash_ratio;
|
|
64
|
+
v_dash_opacity = dash_opacity;
|
|
65
|
+
v_color = color;
|
|
66
|
+
|
|
67
|
+
}`
|
|
68
|
+
|
|
69
|
+
const fragmentShaderSource = `#version 300 es
|
|
70
|
+
${POLE}
|
|
71
|
+
precision highp float;
|
|
72
|
+
uniform float opacity;
|
|
73
|
+
in vec4 v_color;
|
|
74
|
+
in float v_dash_ratio;
|
|
75
|
+
in float v_dash_opacity;
|
|
76
|
+
in float interpolation;
|
|
77
|
+
in vec2 v_limp;
|
|
78
|
+
out vec4 color;
|
|
79
|
+
void main() {
|
|
80
|
+
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; }
|
|
81
|
+
color = v_color;
|
|
82
|
+
color.a *= opacity;
|
|
83
|
+
if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
|
|
84
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
|
|
85
|
+
color.a *= v_dash_opacity;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
`;
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
class Logic {
|
|
93
|
+
|
|
94
|
+
constructor(globe) {
|
|
95
|
+
this.globe = globe;
|
|
96
|
+
this.gl = globe.gl;
|
|
97
|
+
this._lastOpacity = 1.0;
|
|
98
|
+
|
|
99
|
+
this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
|
|
100
|
+
|
|
101
|
+
const { gl, program } = this;
|
|
102
|
+
this.program.uniforms = {
|
|
103
|
+
opacity: gl.getUniformLocation(program, "opacity")
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
{ // initial uniform values
|
|
107
|
+
const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
|
|
108
|
+
gl.useProgram(program);
|
|
109
|
+
gl.uniform1f(program.uniforms.opacity, 1.0);
|
|
110
|
+
gl.useProgram(currentProgram);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
{ // assign attribute locations
|
|
114
|
+
gl.bindAttribLocation(program, 0, "center_position");
|
|
115
|
+
gl.bindAttribLocation(program, 1, "start_angle");
|
|
116
|
+
gl.bindAttribLocation(program, 2, "radius");
|
|
117
|
+
gl.bindAttribLocation(program, 3, "color");
|
|
118
|
+
gl.bindAttribLocation(program, 4, "dash_ratio");
|
|
119
|
+
gl.bindAttribLocation(program, 5, "dash_opacity");
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
this.cameraBindingPoint = 0;
|
|
123
|
+
this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
|
|
124
|
+
console.log("Logic constructor", this.cameraBlockTotem);
|
|
125
|
+
const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
|
|
126
|
+
gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
createVAO(centerObj, startAngleObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
|
|
130
|
+
const { gl } = this;
|
|
131
|
+
const vao = gl.createVertexArray();
|
|
132
|
+
const divisor = 1;
|
|
133
|
+
gl.bindVertexArray(vao);
|
|
134
|
+
{ // make this a function end import from account module.
|
|
135
|
+
const { buffer, stride = 0, offset = 0 } = centerObj;
|
|
136
|
+
vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
|
|
137
|
+
}
|
|
138
|
+
{
|
|
139
|
+
const { buffer, stride = 0, offset = 0 } = startAngleObj;
|
|
140
|
+
vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
|
|
141
|
+
}
|
|
142
|
+
{
|
|
143
|
+
const { buffer, stride = 0, offset = 0 } = radiusObj;
|
|
144
|
+
vaoAttributeLoader(gl, buffer, 2, 1, stride, offset, divisor);
|
|
145
|
+
}
|
|
146
|
+
{
|
|
147
|
+
const { buffer, stride = 0, offset = 0 } = colorObj;
|
|
148
|
+
vaoAttributeLoader(gl, buffer, 3, 4, stride, offset, divisor);
|
|
149
|
+
}
|
|
150
|
+
{
|
|
151
|
+
const { buffer, stride = 0, offset = 0 } = dashRatioObj;
|
|
152
|
+
vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
|
|
153
|
+
}
|
|
154
|
+
{
|
|
155
|
+
const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
|
|
156
|
+
vaoAttributeLoader(gl, buffer, 5, 1, stride, offset, divisor);
|
|
157
|
+
}
|
|
158
|
+
gl.bindVertexArray(null);
|
|
159
|
+
gl.bindVertexArray(null);
|
|
160
|
+
return vao;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
draw(vao, length, opacity) {
|
|
164
|
+
const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
|
|
165
|
+
gl.useProgram(program);
|
|
166
|
+
|
|
167
|
+
if (this._lastOpacity !== opacity) {
|
|
168
|
+
gl.uniform1f(program.uniforms.opacity, opacity);
|
|
169
|
+
this._lastOpacity = opacity;
|
|
170
|
+
}
|
|
171
|
+
gl.bindVertexArray(vao);
|
|
172
|
+
cameraBlockTotem.bind(cameraBindingPoint);
|
|
173
|
+
gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
|
|
174
|
+
cameraBlockTotem.unbind(cameraBindingPoint);
|
|
175
|
+
gl.bindVertexArray(null);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
free() {
|
|
181
|
+
if (this.isFreed) return;
|
|
182
|
+
CameraUniformBlockTotemCache.release(this.globe);
|
|
183
|
+
this.gl.deleteProgram(this.program);
|
|
184
|
+
this.isFreed = true;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
export const CircleCache = Object.freeze({
|
|
191
|
+
get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
|
|
192
|
+
release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
|
|
193
|
+
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import { LineOnGlobeCache } from './program.js';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { CameraUniformBlockString, CameraUniformBlockTotem } from "../totems";
|
|
2
|
-
import { longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition,
|
|
2
|
+
import { longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, POLE } from "../../util/shaderfunctions/geometrytransformations";
|
|
3
3
|
import { createProgram } from "../../util";
|
|
4
4
|
import { noRegisterGlobeProgramCache, globeProgramCache } from "../programcache";
|
|
5
5
|
import BufferOffsetManger from "../../util/account/bufferoffsetmanager";
|
|
6
|
+
import { programCache } from "../rings/distancering/circleflatprogram";
|
|
6
7
|
const Radian = Math.PI / 180.0;
|
|
7
8
|
const GLOBE_MIDPOINT_COUNT = 100;
|
|
8
|
-
const ITEM_SIZE =
|
|
9
|
+
const ITEM_SIZE = 9;
|
|
9
10
|
|
|
10
11
|
const vertexShader = `#version 300 es
|
|
11
12
|
precision highp float;
|
|
@@ -13,44 +14,63 @@ ${CameraUniformBlockString}
|
|
|
13
14
|
${longLatRadToMercator}
|
|
14
15
|
${longLatRadToCartesian3D}
|
|
15
16
|
${cartesian3DToGLPosition}
|
|
16
|
-
${
|
|
17
|
+
${mercatorXYToGLPosition}
|
|
18
|
+
|
|
17
19
|
|
|
18
20
|
in vec2 start_position;
|
|
19
21
|
in vec2 end_position;
|
|
22
|
+
in float dash_ratio;
|
|
20
23
|
in vec4 color;
|
|
21
24
|
out vec4 v_color;
|
|
25
|
+
out vec2 v_limp;
|
|
26
|
+
out float interpolation;
|
|
27
|
+
out float v_dash_ratio;
|
|
28
|
+
|
|
22
29
|
|
|
23
30
|
void main() {
|
|
24
|
-
|
|
25
31
|
vec2 longLat;
|
|
26
32
|
if (is3D) {
|
|
27
|
-
|
|
33
|
+
interpolation = float(gl_VertexID) / ${GLOBE_MIDPOINT_COUNT - 1}.0;
|
|
28
34
|
longLat = mix(start_position, end_position, interpolation);
|
|
29
35
|
vec3 cartesian = longLatRadToCartesian3D(longLat);
|
|
30
36
|
gl_Position = cartesian3DToGLPosition(cartesian);
|
|
37
|
+
v_limp = vec2(0.0, 0.0);
|
|
31
38
|
} else {
|
|
32
|
-
|
|
39
|
+
interpolation = float(gl_VertexID);
|
|
40
|
+
if (gl_VertexID % 2 == 0) {
|
|
33
41
|
longLat = start_position;
|
|
34
42
|
} else {
|
|
35
43
|
longLat = end_position;
|
|
36
44
|
}
|
|
37
45
|
vec2 mercator = longLatRadToMercator(longLat);
|
|
38
|
-
|
|
46
|
+
v_limp = mercator;
|
|
47
|
+
gl_Position = mercatorXYToGLPosition(mercator);
|
|
39
48
|
}
|
|
49
|
+
// if ( gl_VertexID % 2 == 0) {v_color = color;}
|
|
50
|
+
// else {v_color = vec4(0.0, 0.0, 0.0, 0.0);}
|
|
40
51
|
v_color = color;
|
|
52
|
+
v_dash_ratio = dash_ratio;
|
|
41
53
|
}
|
|
42
|
-
|
|
54
|
+
`;
|
|
43
55
|
|
|
44
56
|
const fragmentShader = `#version 300 es
|
|
57
|
+
${POLE}
|
|
45
58
|
precision highp float;
|
|
46
59
|
uniform float opacity;
|
|
47
60
|
in vec4 v_color;
|
|
48
61
|
out vec4 color;
|
|
62
|
+
in float interpolation;
|
|
63
|
+
in float v_dash_ratio;
|
|
64
|
+
in vec2 v_limp;
|
|
49
65
|
void main() {
|
|
66
|
+
if (v_limp.x < -POLE || v_limp.x > POLE || v_limp.y < -POLE || v_limp.y > POLE) { discard; }
|
|
50
67
|
color = v_color;
|
|
51
68
|
color.a *= opacity;
|
|
69
|
+
if (interpolation > 0.95) { return; }
|
|
70
|
+
if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5) { color.a /= 4.0; }
|
|
71
|
+
|
|
52
72
|
}
|
|
53
|
-
|
|
73
|
+
`;
|
|
54
74
|
|
|
55
75
|
|
|
56
76
|
class Logic {
|
|
@@ -65,7 +85,8 @@ class Logic {
|
|
|
65
85
|
// assign attribute locations
|
|
66
86
|
gl.bindAttribLocation(program, 0, "start_position");
|
|
67
87
|
gl.bindAttribLocation(program, 1, "end_position");
|
|
68
|
-
gl.bindAttribLocation(program, 2, "
|
|
88
|
+
gl.bindAttribLocation(program, 2, "dash_ratio");
|
|
89
|
+
gl.bindAttribLocation(program, 3, "color");
|
|
69
90
|
}
|
|
70
91
|
|
|
71
92
|
{
|
|
@@ -87,9 +108,8 @@ class Logic {
|
|
|
87
108
|
|
|
88
109
|
|
|
89
110
|
draw(vao, length, opacity) {
|
|
90
|
-
const { gl, program, globe } = this;
|
|
111
|
+
const { gl, program, globe, cameraBlockTotem, cameraBlockBindingPoint } = this;
|
|
91
112
|
gl.useProgram(program);
|
|
92
|
-
const { cameraBlockTotem, cameraBlockBindingPoint } = this;
|
|
93
113
|
cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
94
114
|
gl.bindVertexArray(vao);
|
|
95
115
|
if (opacity !== this._lastOpacity) {
|
|
@@ -97,23 +117,75 @@ class Logic {
|
|
|
97
117
|
this._lastOpacity = opacity;
|
|
98
118
|
}
|
|
99
119
|
const drawCount = globe.api_GetCurrentGeometry() === 0 ? GLOBE_MIDPOINT_COUNT : 2;
|
|
100
|
-
gl.disable(gl.DEPTH_TEST);
|
|
120
|
+
// gl.disable(gl.DEPTH_TEST);
|
|
101
121
|
gl.drawArraysInstanced(gl.LINE_STRIP, 0, drawCount, length);
|
|
102
122
|
gl.bindVertexArray(null);
|
|
103
123
|
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
104
|
-
gl.enable(gl.DEPTH_TEST);
|
|
124
|
+
// gl.enable(gl.DEPTH_TEST);
|
|
105
125
|
}
|
|
106
126
|
|
|
107
127
|
|
|
108
128
|
createBufferManager({ capacity = 10, bufferType = "DYNAMIC_DRAW" } = {}) {
|
|
109
129
|
return new BufferManager(this.globe, { capacity, bufferType });
|
|
110
130
|
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
//
|
|
135
|
+
createVAO(startPotisionBufferObj, endPositionBufferObj, dashRatioBufferObj, colorBufferObj) {
|
|
136
|
+
const { gl } = this;
|
|
137
|
+
const vao = gl.createVertexArray();
|
|
138
|
+
gl.bindVertexArray(vao);
|
|
139
|
+
{
|
|
140
|
+
const { buffer, stride = 0, offset = 0 } = startPotisionBufferObj;
|
|
141
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
142
|
+
gl.enableVertexAttribArray(0);
|
|
143
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
|
|
144
|
+
gl.vertexAttribDivisor(0, 1);
|
|
145
|
+
}
|
|
146
|
+
{
|
|
147
|
+
|
|
148
|
+
const { buffer, stride = 0, offset = 0 } = endPositionBufferObj;
|
|
149
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
150
|
+
gl.enableVertexAttribArray(1);
|
|
151
|
+
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, stride, offset);
|
|
152
|
+
gl.vertexAttribDivisor(1, 1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
{
|
|
156
|
+
const { buffer, stride = 0, offset = 0 } = dashRatioBufferObj;
|
|
157
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
158
|
+
gl.enableVertexAttribArray(2);
|
|
159
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
|
|
160
|
+
gl.vertexAttribDivisor(2, 1);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
{
|
|
164
|
+
const { buffer, stride = 0, offset = 0 } = colorBufferObj;
|
|
165
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
166
|
+
gl.enableVertexAttribArray(3);
|
|
167
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, stride, offset);
|
|
168
|
+
gl.vertexAttribDivisor(3, 1);
|
|
169
|
+
}
|
|
170
|
+
gl.bindVertexArray(null);
|
|
171
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
172
|
+
return vao;
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
free() {
|
|
178
|
+
if (this.isFreed) return;
|
|
179
|
+
programCache.releaseProgram(this.globe, CameraUniformBlockTotem);
|
|
180
|
+
this.gl.deleteProgram(this.program);
|
|
181
|
+
this.isFreed = true;
|
|
182
|
+
}
|
|
111
183
|
}
|
|
112
184
|
|
|
113
185
|
|
|
114
186
|
class BufferManager extends BufferOffsetManger {
|
|
115
187
|
|
|
116
|
-
constructor(globe, { capacity = 10, bufferType = "DYNAMIC_DRAW" } = {}) {
|
|
188
|
+
constructor(globe, { capacity = 10, bufferType = "DYNAMIC_DRAW", } = {}) {
|
|
117
189
|
super(ITEM_SIZE, { capacity, bufferType });
|
|
118
190
|
this.globe = globe
|
|
119
191
|
this.gl = globe.gl;
|
|
@@ -133,10 +205,13 @@ class BufferManager extends BufferOffsetManger {
|
|
|
133
205
|
gl.enableVertexAttribArray(1);
|
|
134
206
|
gl.vertexAttribPointer(1, 2, gl.FLOAT, false, ITEM_SIZE * 4, 8);
|
|
135
207
|
gl.enableVertexAttribArray(2);
|
|
136
|
-
gl.vertexAttribPointer(2,
|
|
208
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, ITEM_SIZE * 4, 16);
|
|
209
|
+
gl.enableVertexAttribArray(3);
|
|
210
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, ITEM_SIZE * 4, 20);
|
|
137
211
|
gl.vertexAttribDivisor(0, 1);
|
|
138
212
|
gl.vertexAttribDivisor(1, 1);
|
|
139
213
|
gl.vertexAttribDivisor(2, 1);
|
|
214
|
+
gl.vertexAttribDivisor(3, 1);
|
|
140
215
|
gl.bindVertexArray(null);
|
|
141
216
|
}
|
|
142
217
|
}
|
|
@@ -150,14 +225,16 @@ class BufferManager extends BufferOffsetManger {
|
|
|
150
225
|
this.autoExtendBuffer(items.length)
|
|
151
226
|
const { gl, buffer, globe } = this;
|
|
152
227
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
153
|
-
for (let { key, long, lat, endLong, endLat, rgba } of items) {
|
|
154
|
-
|
|
228
|
+
for (let { key, long, lat, endLong, endLat, rgba, dashRatio = 1 } of items) {
|
|
229
|
+
console.log(key, dashRatio, "dashRatio");
|
|
155
230
|
const payload = new Float32Array([
|
|
156
231
|
long,
|
|
157
232
|
lat,
|
|
158
233
|
endLong,
|
|
159
234
|
endLat,
|
|
235
|
+
dashRatio,
|
|
160
236
|
...rgba]);
|
|
237
|
+
|
|
161
238
|
const offset = this.getOffset(key) | this.nextOffset();
|
|
162
239
|
gl.bufferSubData(gl.ARRAY_BUFFER, offset, payload);
|
|
163
240
|
this.setOffset(key, offset);
|
|
@@ -173,12 +250,13 @@ class BufferManager extends BufferOffsetManger {
|
|
|
173
250
|
updateBulk(items) {
|
|
174
251
|
const { gl, buffer, globe } = this;
|
|
175
252
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
176
|
-
for (let { key, long, lat, endLong, endLat, rgba } of items) {
|
|
253
|
+
for (let { key, long, lat, endLong, endLat, rgba, dashRatio = 1 } of items) {
|
|
177
254
|
const payload = new Float32Array([
|
|
178
255
|
long,
|
|
179
256
|
lat,
|
|
180
257
|
endLong,
|
|
181
258
|
endLat,
|
|
259
|
+
dashRatio,
|
|
182
260
|
...rgba]);
|
|
183
261
|
const offset = this.getOffset(key);
|
|
184
262
|
if (offset !== undefined) {
|
|
@@ -198,12 +276,13 @@ class BufferManager extends BufferOffsetManger {
|
|
|
198
276
|
updateCoordinatesBulk(items) {
|
|
199
277
|
const { gl, buffer, globe } = this;
|
|
200
278
|
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
201
|
-
for (let { key, long, lat, endLong, endLat } of items) {
|
|
279
|
+
for (let { key, long, lat, endLong, endLat, dashRatio = 1 } of items) {
|
|
202
280
|
const payload = new Float32Array([
|
|
203
281
|
long,
|
|
204
282
|
lat,
|
|
205
283
|
endLong,
|
|
206
|
-
endLat
|
|
284
|
+
endLat,
|
|
285
|
+
dashRatio]);
|
|
207
286
|
const offset = this.getOffset(key);
|
|
208
287
|
if (offset !== undefined) {
|
|
209
288
|
gl.bufferSubData(gl.ARRAY_BUFFER, offset, payload);
|
|
@@ -227,7 +306,7 @@ class BufferManager extends BufferOffsetManger {
|
|
|
227
306
|
const payload = new Float32Array([...rgba]);
|
|
228
307
|
const offset = this.getOffset(key);
|
|
229
308
|
if (offset !== undefined) {
|
|
230
|
-
gl.bufferSubData(gl.ARRAY_BUFFER, offset +
|
|
309
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + 20, payload);
|
|
231
310
|
} else {
|
|
232
311
|
console.warn("key not found", key);
|
|
233
312
|
}
|
|
@@ -262,6 +341,6 @@ class BufferManager extends BufferOffsetManger {
|
|
|
262
341
|
|
|
263
342
|
export const LineOnGlobeCache = Object.freeze({
|
|
264
343
|
get: (globe) => { return noRegisterGlobeProgramCache.getProgram(globe, Logic) },
|
|
265
|
-
|
|
344
|
+
release: (globe) => { return noRegisterGlobeProgramCache.releaseProgram(globe, Logic) }
|
|
266
345
|
});
|
|
267
346
|
|
|
@@ -9,7 +9,7 @@ const vertexShader = `#version 300 es ` +
|
|
|
9
9
|
shaderfunctions.R +
|
|
10
10
|
shaderfunctions.POLE +
|
|
11
11
|
CameraUniformBlockString +
|
|
12
|
-
shaderfunctions.
|
|
12
|
+
shaderfunctions.mercatorXYToGLPosition +
|
|
13
13
|
shaderfunctions.longLatRadToMercator +
|
|
14
14
|
shaderfunctions.longLatRadToCartesian3D +
|
|
15
15
|
shaderfunctions.circleLimpFromLongLatRadCenterCartesian3D +
|
|
@@ -46,7 +46,7 @@ void main() {
|
|
|
46
46
|
limp = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius, angle);
|
|
47
47
|
}
|
|
48
48
|
v_limp = limp;
|
|
49
|
-
gl_Position =
|
|
49
|
+
gl_Position = mercatorXYToGLPosition(limp);
|
|
50
50
|
|
|
51
51
|
}`;
|
|
52
52
|
|