@pirireis/webglobeplugins 0.1.10 → 0.3.0
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 +319 -0
- package/bearing-line/roadmap.md +15 -0
- package/package.json +1 -1
- package/partialrings/buffer-manager.js +89 -0
- package/partialrings/index.js +1 -1
- package/partialrings/plugin.js +22 -28
- package/partialrings/program.js +115 -36
- 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/{program.js → naive.js} +135 -39
- package/programs/rings/distancering/circleflatprogram.js +2 -2
- package/programs/rings/distancering/circlepaddingfreeangleprogram.js +3 -3
- 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 +3 -2
- package/util/account/bufferoffsetmanager.js +17 -5
- 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 +107 -6
- package/wind/plugin.js +7 -4
- package/write-text/context-text.js +86 -0
- package/write-text/index.js +1 -0
package/partialrings/program.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createProgram, shaderfunctions } from "../util";
|
|
2
2
|
import { CameraUniformBlockTotem, CameraUniformBlockString, noRegisterGlobeProgramCache, globeProgramCache } from "../programs";
|
|
3
|
-
|
|
3
|
+
import BufferManager from "./buffer-manager";
|
|
4
4
|
import {
|
|
5
5
|
POLE,
|
|
6
6
|
PI,
|
|
7
7
|
longLatRadToMercator,
|
|
8
|
-
|
|
8
|
+
mercatorXYToGLPosition,
|
|
9
9
|
longLatRadToCartesian3D,
|
|
10
10
|
circleLimpFromLongLatRadCenterCartesian3D,
|
|
11
|
-
|
|
11
|
+
circleLimpFromLongLatRadCenterMercatorRealDistance,
|
|
12
12
|
cartesian3DToGLPosition
|
|
13
13
|
|
|
14
14
|
|
|
@@ -28,54 +28,57 @@ const drawModeMap = Object.freeze({
|
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
const vertexShaderSource = `#version 300 es
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
const vertexShaderSource = `#version 300 es
|
|
32
|
+
|
|
33
|
+
${CameraUniformBlockString}
|
|
34
|
+
${PI}
|
|
35
|
+
${longLatRadToMercator}
|
|
36
|
+
${mercatorXYToGLPosition}
|
|
37
|
+
${longLatRadToCartesian3D}
|
|
38
|
+
${circleLimpFromLongLatRadCenterCartesian3D}
|
|
39
|
+
${circleLimpFromLongLatRadCenterMercatorRealDistance}
|
|
40
|
+
${cartesian3DToGLPosition}
|
|
40
41
|
|
|
41
42
|
uniform float edge_count;
|
|
42
43
|
uniform int draw_mode; // %2 => 0: LINE_STRIP, 1: TRIANGLE_FAN
|
|
43
44
|
uniform float plugin_alpha_multiplier;
|
|
44
|
-
|
|
45
|
+
//, lat, startAngle, tailAngle, ...rgba, radius, rgbaMode
|
|
45
46
|
in vec2 center; // long, lat in radian
|
|
46
47
|
in float start_angle; // the start of partial circle from bearing point
|
|
47
48
|
in float tail_angle; // the rotation of the partial circle
|
|
48
49
|
in vec4 color;
|
|
49
50
|
in float radius; // in meter
|
|
50
51
|
in float color_mode; // 0.0: constant, 1.0: fading, 2.0: hide
|
|
51
|
-
|
|
52
|
+
flat out int vid;
|
|
53
|
+
out float v_phase;
|
|
52
54
|
out vec2 v_pos;
|
|
53
55
|
out vec4 v_color;
|
|
54
|
-
|
|
56
|
+
flat out float v_angle;
|
|
55
57
|
|
|
56
58
|
void main() {
|
|
59
|
+
vid = gl_VertexID;
|
|
57
60
|
if (color_mode == 2.0 || radius == 0.0) { return; }
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
float color_mode_ = color_mode;
|
|
62
|
+
if ( draw_mode == 0 && color_mode == 1.0) {color_mode_ = 0.0;}
|
|
63
|
+
float vertexID = float(gl_VertexID);
|
|
60
64
|
float radius_ = radius;
|
|
61
65
|
float alpha = plugin_alpha_multiplier;
|
|
62
66
|
if (draw_mode == 1) { // TRIANGLE_FAN
|
|
63
|
-
vertexID = float(gl_VertexID - 1);
|
|
64
67
|
if (gl_VertexID == 0) {
|
|
65
|
-
radius_ = 0.0;
|
|
68
|
+
radius_ = 0.0;
|
|
66
69
|
if ( color_mode == 1.0 ) { alpha = 0.0; }
|
|
67
70
|
}
|
|
68
|
-
|
|
69
|
-
vertexID = float(gl_VertexID);
|
|
71
|
+
vertexID -= 1.0;
|
|
70
72
|
}
|
|
73
|
+
float phase = ( vertexID / (edge_count - 1.0) );
|
|
74
|
+
v_angle = tail_angle;
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if ( color_mode == 1.0 ) {
|
|
76
|
+
|
|
77
|
+
if ( color_mode_ == 1.0 ) {
|
|
75
78
|
if ( tail_angle < 0.0 ) {
|
|
76
79
|
v_color = vec4( color.rgb , color.a * ( 1.0 - phase ) * alpha );
|
|
77
80
|
} else {
|
|
78
|
-
v_color = vec4( color.rgb , color.a *
|
|
81
|
+
v_color = vec4( color.rgb , color.a * phase * alpha );
|
|
79
82
|
}
|
|
80
83
|
} else {
|
|
81
84
|
v_color = vec4( color.rgb , color.a * alpha );
|
|
@@ -94,24 +97,28 @@ void main() {
|
|
|
94
97
|
gl_Position = cartesian3DToGLPosition(pos);
|
|
95
98
|
}
|
|
96
99
|
else {
|
|
97
|
-
|
|
100
|
+
|
|
101
|
+
vec2 pos = circleLimpFromLongLatRadCenterMercatorRealDistance(center, radius_, angle);
|
|
98
102
|
v_pos = pos;
|
|
99
|
-
gl_Position =
|
|
103
|
+
gl_Position = mercatorXYToGLPosition(pos);
|
|
100
104
|
}
|
|
101
105
|
|
|
102
|
-
|
|
103
|
-
gl_PointSize = 2.0;
|
|
106
|
+
gl_PointSize = 10.0;
|
|
104
107
|
}`;
|
|
105
108
|
|
|
106
109
|
|
|
107
|
-
const fragmentShaderSource = `#version 300 es` + POLE + `
|
|
110
|
+
const fragmentShaderSource = `#version 300 es` + POLE + PI + `
|
|
108
111
|
precision highp float;
|
|
109
|
-
|
|
112
|
+
flat in int vid;
|
|
110
113
|
in vec4 v_color;
|
|
111
114
|
in vec2 v_pos;
|
|
115
|
+
flat in float v_phase;
|
|
116
|
+
in float v_angle;
|
|
112
117
|
out vec4 outColor;
|
|
113
|
-
|
|
114
118
|
void main() {
|
|
119
|
+
// if( vid % 2 == 0 ) { discard; }
|
|
120
|
+
// if ( mod(v_angle, PI / 36.0 ) < (PI / 72.0)) { discard; }
|
|
121
|
+
// if ( mod(v_angle * v_phase, PI / 90.0 ) < (PI / 180.0)) { discard; }
|
|
115
122
|
if ( v_pos.x < -POLE || v_pos.x > POLE || v_pos.y < -POLE || v_pos.y > POLE ) { discard; }
|
|
116
123
|
outColor = v_color;
|
|
117
124
|
}`;
|
|
@@ -162,10 +169,10 @@ export class Logic {
|
|
|
162
169
|
|
|
163
170
|
|
|
164
171
|
|
|
165
|
-
draw(
|
|
172
|
+
draw(length, vao, edgeCount, alphaMultiplier, drawMode) {
|
|
166
173
|
const { gl, program, cameraBlockTotem, cameraBlockBindingPoint } = this
|
|
167
174
|
|
|
168
|
-
gl.disable(gl.DEPTH_TEST);
|
|
175
|
+
// gl.disable(gl.DEPTH_TEST);
|
|
169
176
|
gl.useProgram(program);
|
|
170
177
|
if (drawMode !== this._lastMode) {
|
|
171
178
|
gl.uniform1i(this._draw_modeLocation, drawModeMap[drawMode]);
|
|
@@ -182,10 +189,10 @@ export class Logic {
|
|
|
182
189
|
const overdraw = drawModeMap[drawMode];
|
|
183
190
|
cameraBlockTotem.bind(cameraBlockBindingPoint);
|
|
184
191
|
gl.bindVertexArray(vao);
|
|
185
|
-
gl.drawArraysInstanced(gl[drawMode], 0, edgeCount + overdraw,
|
|
192
|
+
gl.drawArraysInstanced(gl[drawMode], 0, edgeCount + overdraw, length);
|
|
186
193
|
cameraBlockTotem.unbind(cameraBlockBindingPoint);
|
|
187
194
|
gl.bindVertexArray(null);
|
|
188
|
-
gl.enable(gl.DEPTH_TEST);
|
|
195
|
+
// gl.enable(gl.DEPTH_TEST);
|
|
189
196
|
}
|
|
190
197
|
|
|
191
198
|
|
|
@@ -237,6 +244,78 @@ export class Logic {
|
|
|
237
244
|
buffer,
|
|
238
245
|
}
|
|
239
246
|
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* in vec2 center; // long, lat in radian
|
|
250
|
+
in float start_angle; // the start of partial circle from bearing point
|
|
251
|
+
in float tail_angle; // the rotation of the partial circle
|
|
252
|
+
in vec4 color;
|
|
253
|
+
in float radius; // in meter
|
|
254
|
+
in float color_mode; // 0.0: constant, 1.0: fading, 2.0: hide
|
|
255
|
+
*/
|
|
256
|
+
|
|
257
|
+
createVAO(centerObj, startAngleObj, tailAngleObj, colorObj, radiusObj, colorModeObj) {
|
|
258
|
+
|
|
259
|
+
const { gl } = this;
|
|
260
|
+
const vao = gl.createVertexArray();
|
|
261
|
+
gl.bindVertexArray(vao);
|
|
262
|
+
|
|
263
|
+
{
|
|
264
|
+
const { buffer, stride, offset } = centerObj;
|
|
265
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
266
|
+
gl.enableVertexAttribArray(0);
|
|
267
|
+
gl.vertexAttribPointer(0, 2, gl.FLOAT, false, stride, offset);
|
|
268
|
+
gl.vertexAttribDivisor(0, 1);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
{
|
|
272
|
+
const { buffer, stride, offset } = startAngleObj;
|
|
273
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
274
|
+
gl.enableVertexAttribArray(1);
|
|
275
|
+
gl.vertexAttribPointer(1, 1, gl.FLOAT, false, stride, offset);
|
|
276
|
+
gl.vertexAttribDivisor(1, 1);
|
|
277
|
+
}
|
|
278
|
+
{
|
|
279
|
+
const { buffer, stride, offset } = tailAngleObj;
|
|
280
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
281
|
+
gl.enableVertexAttribArray(2);
|
|
282
|
+
gl.vertexAttribPointer(2, 1, gl.FLOAT, false, stride, offset);
|
|
283
|
+
gl.vertexAttribDivisor(2, 1);
|
|
284
|
+
}
|
|
285
|
+
{
|
|
286
|
+
const { buffer, stride, offset } = colorObj;
|
|
287
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
288
|
+
gl.enableVertexAttribArray(3);
|
|
289
|
+
gl.vertexAttribPointer(3, 4, gl.FLOAT, false, stride, offset);
|
|
290
|
+
gl.vertexAttribDivisor(3, 1);
|
|
291
|
+
}
|
|
292
|
+
{
|
|
293
|
+
const { buffer, stride, offset } = radiusObj;
|
|
294
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
295
|
+
gl.enableVertexAttribArray(4);
|
|
296
|
+
gl.vertexAttribPointer(4, 1, gl.FLOAT, false, stride, offset);
|
|
297
|
+
gl.vertexAttribDivisor(4, 1);
|
|
298
|
+
}
|
|
299
|
+
{
|
|
300
|
+
const { buffer, stride, offset } = colorModeObj;
|
|
301
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
302
|
+
gl.enableVertexAttribArray(5);
|
|
303
|
+
gl.vertexAttribPointer(5, 1, gl.FLOAT, false, stride, offset);
|
|
304
|
+
gl.vertexAttribDivisor(5, 1);
|
|
305
|
+
}
|
|
306
|
+
gl.bindVertexArray(null);
|
|
307
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
308
|
+
return vao;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
getBufferManagerAndVao({ capacity = 10, bufferType = "DYNAMIC_DRAW" } = {}) {
|
|
313
|
+
const { vao, buffer } = this.getVaoBuffer();
|
|
314
|
+
return {
|
|
315
|
+
bufferManager: new BufferManager(this.globe, this.gl, buffer, { capacity, bufferType }),
|
|
316
|
+
vao
|
|
317
|
+
};
|
|
318
|
+
}
|
|
240
319
|
}
|
|
241
320
|
|
|
242
321
|
export const programCache = Object.freeze({
|
|
@@ -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';
|