@pirireis/webglobeplugins 0.12.0-alpha → 0.13.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.
@@ -1,164 +1,166 @@
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
+ "use strict";
2
+ // TODO: Delete this file if it is not needed anymore.
3
+ // import { createProgram } from "../../util/webglobjectbuilders";
4
+ // import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/camerauniformblock";
5
+ // import { noRegisterGlobeProgramCache } from "../programcache";
6
+ // import { vaoAttributeLoader } from "../../util/account/util";
7
+ // import {
8
+ // longLatRadToMercator, longLatRadToCartesian3D, cartesian3DToGLPosition, mercatorXYToGLPosition, realDistanceOnSphereR1,
9
+ // circleLimpFromLongLatRadCenterCartesian3D,
10
+ // circleLimpFromLongLatRadCenterMercatorCompass,
11
+ // circleLimpFromLongLatRadCenterMercatorRealDistance,
12
+ // POLE
13
+ // } from "../../util/shaderfunctions/geometrytransformations";
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
+ // const vertexShaderSource = `#version 300 es
24
+ // precision highp float;
25
+ // ${CameraUniformBlockString}
26
+ // ${longLatRadToMercator}
27
+ // ${longLatRadToCartesian3D}
28
+ // ${cartesian3DToGLPosition}
29
+ // ${mercatorXYToGLPosition}
30
+ // ${realDistanceOnSphereR1}
31
+ // ${circleLimpFromLongLatRadCenterCartesian3D}
32
+ // ${circleLimpFromLongLatRadCenterMercatorCompass}
33
+ // ${circleLimpFromLongLatRadCenterMercatorRealDistance}
34
+ // uniform float edge_count;
35
+ // in vec2 center_position;
36
+ // in float radius;
37
+ // in vec4 color;
38
+ // in float dash_ratio;
39
+ // in float dash_opacity;
40
+ // out float interpolation;
41
+ // out vec4 v_color;
42
+ // out float v_dash_ratio;
43
+ // out float v_dash_opacity;
44
+ // out vec2 v_limp;
45
+ // void main() {
46
+ // interpolation = float( gl_VertexID ) / ${EDGE_COUNT_ON_SPHERE}.0;
47
+ // float angle = PI * 2.0 * interpolation;
48
+ // if ( is3D ) {
49
+ // vec3 position = circleLimpFromLongLatRadCenterCartesian3D( center_position, radius, angle);
50
+ // gl_Position = cartesian3DToGLPosition(position);
51
+ // v_limp = vec2(0.0, 0.0);
52
+ // } else {
53
+ // vec2 position;
54
+ // if (radius < 1400.0) {
55
+ // position = circleLimpFromLongLatRadCenterMercatorCompass( center_position, radius/ cos(center_position.y), angle);
56
+ // } else {
57
+ // position = circleLimpFromLongLatRadCenterMercatorRealDistance( center_position, radius, angle);
58
+ // }
59
+ // v_limp = position;
60
+ // gl_Position = mercatorXYToGLPosition( position);
61
+ // }
62
+ // v_dash_ratio = dash_ratio;
63
+ // v_dash_opacity = dash_opacity;
64
+ // v_color = color;
65
+ // }`
66
+ // const fragmentShaderSource = `#version 300 es
67
+ // ${POLE}
68
+ // precision highp float;
69
+ // uniform float opacity;
70
+ // in vec4 v_color;
71
+ // in float v_dash_ratio;
72
+ // in float v_dash_opacity;
73
+ // in float interpolation;
74
+ // in vec2 v_limp;
75
+ // out vec4 color;
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 = v_color;
79
+ // color.a *= opacity;
80
+ // if ( v_dash_ratio == 1.0 || v_dash_ratio == 0.0 ) return;
81
+ // if (fract(interpolation / (2.0 * v_dash_ratio)) < 0.5 ) {
82
+ // color.a *= v_dash_opacity;
83
+ // }
84
+ // }
85
+ // `;
86
+ // class Logic {
87
+ // constructor(globe) {
88
+ // this.globe = globe;
89
+ // this.gl = globe.gl;
90
+ // this._lastOpacity = 1.0;
91
+ // this.program = createProgram(this.gl, vertexShaderSource, fragmentShaderSource);
92
+ // const { gl, program } = this;
93
+ // this.program.uniforms = {
94
+ // opacity: gl.getUniformLocation(program, "opacity")
95
+ // };
96
+ // { // initial uniform values
97
+ // const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
98
+ // gl.useProgram(program);
99
+ // gl.uniform1f(program.uniforms.opacity, 1.0);
100
+ // gl.useProgram(currentProgram);
101
+ // }
102
+ // { // assign attribute locations
103
+ // gl.bindAttribLocation(program, 0, "center_position");
104
+ // gl.bindAttribLocation(program, 1, "radius");
105
+ // gl.bindAttribLocation(program, 2, "color");
106
+ // gl.bindAttribLocation(program, 3, "dash_ratio");
107
+ // gl.bindAttribLocation(program, 4, "dash_opacity");
108
+ // }
109
+ // this.cameraBindingPoint = 0;
110
+ // this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
111
+ // const cameraBlockLocation = gl.getUniformBlockIndex(program, "CameraUniformBlock");
112
+ // gl.uniformBlockBinding(program, cameraBlockLocation, this.cameraBindingPoint);
113
+ // }
114
+ // createVAO(centerObj, radiusObj, colorObj, dashRatioObj, dashOpacityObj) {
115
+ // const { gl } = this;
116
+ // const vao = gl.createVertexArray();
117
+ // const divisor = 1;
118
+ // gl.bindVertexArray(vao);
119
+ // { // make this a function end import from account module.
120
+ // const { buffer, stride = 0, offset = 0 } = centerObj;
121
+ // vaoAttributeLoader(gl, buffer, 0, 2, stride, offset, divisor);
122
+ // }
123
+ // {
124
+ // const { buffer, stride = 0, offset = 0 } = radiusObj;
125
+ // vaoAttributeLoader(gl, buffer, 1, 1, stride, offset, divisor);
126
+ // }
127
+ // {
128
+ // const { buffer, stride = 0, offset = 0 } = colorObj;
129
+ // vaoAttributeLoader(gl, buffer, 2, 4, stride, offset, divisor);
130
+ // }
131
+ // {
132
+ // const { buffer, stride = 0, offset = 0 } = dashRatioObj;
133
+ // vaoAttributeLoader(gl, buffer, 3, 1, stride, offset, divisor);
134
+ // }
135
+ // {
136
+ // const { buffer, stride = 0, offset = 0 } = dashOpacityObj;
137
+ // vaoAttributeLoader(gl, buffer, 4, 1, stride, offset, divisor);
138
+ // }
139
+ // gl.bindVertexArray(null);
140
+ // gl.bindVertexArray(null);
141
+ // return vao;
142
+ // }
143
+ // draw(vao, length, opacity) {
144
+ // const { gl, program, cameraBlockTotem, cameraBindingPoint } = this;
145
+ // gl.useProgram(program);
146
+ // if (this._lastOpacity !== opacity) {
147
+ // gl.uniform1f(program.uniforms.opacity, opacity);
148
+ // this._lastOpacity = opacity;
149
+ // }
150
+ // gl.bindVertexArray(vao);
151
+ // cameraBlockTotem.bind(cameraBindingPoint);
152
+ // gl.drawArraysInstanced(gl.LINE_STRIP, 0, EDGE_COUNT_ON_SPHERE + 1, length);
153
+ // cameraBlockTotem.unbind(cameraBindingPoint);
154
+ // gl.bindVertexArray(null);
155
+ // }
156
+ // free() {
157
+ // if (this.isFreed) return;
158
+ // CameraUniformBlockTotemCache.release(this.globe);
159
+ // this.gl.deleteProgram(this.program);
160
+ // this.isFreed = true;
161
+ // }
162
+ // }
163
+ // export const CircleCache = Object.freeze({
164
+ // get: (globe) => noRegisterGlobeProgramCache.getProgram(globe, Logic),
165
+ // release: (globe) => noRegisterGlobeProgramCache.releaseProgram(globe, Logic)
166
+ // });
@@ -0,0 +1,4 @@
1
+ export function createLineStripData(program, globe, gl, DrawStyleOptions) {
2
+ // @ts-ignore
3
+ return;
4
+ }
@@ -1,23 +1,23 @@
1
- import { createProgram } from "../../util/webglobjectbuilders";
2
- import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../totems/index";
3
- import { cartesian3DToGLPosition, mercatorXYToGLPosition, } from "../../util/shaderfunctions/geometrytransformations";
4
- import { noRegisterGlobeProgramCache } from "../programcache";
5
- import { attributeLoader } from "../../util/gl-util/buffer/attribute-loader";
6
- import "../../util/gl-util/buffer/attribute-loader";
7
- import { UniformBlockManager } from "../../util/gl-util/uniform-block/manager";
8
- import "../../util/gl-util/uniform-block/types";
9
- import { drawArrays } from "../../util/gl-util/draw-options/methods";
10
- import "../../util/gl-util/draw-options/types";
1
+ import { createProgram } from "../../../util/webglobjectbuilders";
2
+ import { CameraUniformBlockString, CameraUniformBlockTotemCache } from "../../totems/index";
3
+ import { cartesian3DToGLPosition, mercatorXYToGLPosition, } from "../../../util/shaderfunctions/geometrytransformations";
4
+ import { noRegisterGlobeProgramCache } from "../../programcache";
5
+ import { attributeLoader } from "../../../util/gl-util/buffer/attribute-loader";
6
+ import "../../../util/gl-util/buffer/attribute-loader";
7
+ import { UniformBlockManager } from "../../../util/gl-util/uniform-block/manager";
8
+ import "../../../util/gl-util/uniform-block/types";
9
+ import { drawArrays } from "../../../util/gl-util/draw-options/methods";
10
+ import "../../../util/gl-util/draw-options/types";
11
11
  const ESCAPE_VALUE = -1;
12
12
  const uniformBindingPoints = {
13
13
  camera: 0,
14
14
  flexible: 1,
15
15
  };
16
- const one = new Float32Array([1]);
16
+ // const one = new Float32Array([1]);
17
17
  const flexibleBlockManager = new UniformBlockManager('FlexibleAttributes', [
18
18
  { name: "u_color", type: "vec4", value: new Float32Array([0.12, 1, 0.1, 1]) },
19
- { name: "u_dash_opacity", type: "float", value: one },
20
- { name: "u_dash_length", type: "float", value: one },
19
+ // { name: "u_dash_opacity", type: "float", value: one },
20
+ // { name: "u_dash_length", type: "float", value: one },
21
21
  ], uniformBindingPoints.flexible);
22
22
  const vertexShaderSource = `#version 300 es
23
23
  precision highp float;
@@ -31,11 +31,11 @@ ${flexibleBlockManager.glslCode()}
31
31
  in vec3 position3d;
32
32
  in vec2 position2d;
33
33
  in vec4 color;
34
- in float dash_length;
35
- in float dash_opacity;
34
+ // in float dash_length;
35
+ // in float dash_opacity;
36
36
 
37
- out float v_dash_length;
38
- out float v_dash_opacity;
37
+ // out float v_dash_length;
38
+ // out float v_dash_opacity;
39
39
  out vec4 v_color;
40
40
 
41
41
  flat out vec3 v_flat_position;
@@ -44,8 +44,8 @@ out vec3 v_position;
44
44
  void main() {
45
45
 
46
46
  v_color = ( color.r == -1.0 ) ? u_color : color;
47
- v_dash_length = ( dash_length == -1.0 ) ? u_dash_length : dash_length;
48
- v_dash_opacity = ( dash_opacity == -1.0 ) ? u_dash_opacity : dash_opacity;
47
+ // v_dash_length = ( dash_length == -1.0 ) ? u_dash_length : dash_length;
48
+ // v_dash_opacity = ( dash_opacity == -1.0 ) ? u_dash_opacity : dash_opacity;
49
49
 
50
50
  if ( is3D ) {
51
51
  gl_Position = cartesian3DToGLPosition( position3d );
@@ -70,22 +70,21 @@ in float v_dash_opacity;
70
70
  flat in vec3 v_flat_position;
71
71
  in vec3 v_position;
72
72
 
73
-
74
73
  out vec4 outColor;
75
74
 
76
75
  void main() {
77
76
  outColor = v_color;
78
77
  return;
79
- float dash_length = v_dash_length;
80
- float dash_opacity = v_dash_opacity;
78
+ // float dash_length = v_dash_length;
79
+ // float dash_opacity = v_dash_opacity;
81
80
 
82
- if ( dash_length == 0.0 ) {
83
- outColor = vec4( v_color.rgb, v_color.a * v_dash_opacity );
84
- } else {
85
- float dist = distance( v_flat_position, v_position );
86
- // float alpha = mod( dist , v_dash_length * 2.0 ) / v_dash_length < 1.0 ? 1.0 : v_dash_opacity;
87
- outColor = vec4( v_color.rgb, v_color.a * opacity );
88
- }
81
+ // if ( dash_length == 0.0 ) {
82
+ outColor = vec4( v_color.rgb, v_color.a );
83
+ // } else {
84
+ // float dist = distance( v_flat_position, v_position );
85
+ // // float alpha = mod( dist , v_dash_length * 2.0 ) / v_dash_length < 1.0 ? 1.0 : v_dash_opacity;
86
+ // outColor = vec4( 1.0, 1.0, 1.0, v_color.a * opacity *alpha);
87
+ // }
89
88
  }`;
90
89
  export class LineProgram {
91
90
  _vaosPublished = [];
@@ -111,8 +110,8 @@ export class LineProgram {
111
110
  this.gl.bindAttribLocation(this.program, 0, "position3d");
112
111
  this.gl.bindAttribLocation(this.program, 1, "position2d");
113
112
  this.gl.bindAttribLocation(this.program, 2, "color");
114
- this.gl.bindAttribLocation(this.program, 3, "dash_length");
115
- this.gl.bindAttribLocation(this.program, 4, "dash_opacity");
113
+ // this.gl.bindAttribLocation(this.program, 3, "dash_length");
114
+ // this.gl.bindAttribLocation(this.program, 4, "dash_opacity");
116
115
  this.cameraBlockTotem = CameraUniformBlockTotemCache.get(globe);
117
116
  this.cameraBlockTotem.assignBindingPoint(this.program, uniformBindingPoints.camera);
118
117
  flexibleBlockManager.assignBindingPoint(this.gl, this.program);
@@ -124,15 +123,16 @@ export class LineProgram {
124
123
  this._ubosPublished.push(ubo);
125
124
  return ubo;
126
125
  }
127
- createVAO(position3D, position2D, color, dashLength, dashOpacity) {
126
+ createVAO(position3D, position2D, color //, dashLength: BufferAndReadInfo, dashOpacity: BufferAndReadInfo,
127
+ ) {
128
128
  const { gl } = this;
129
129
  const vao = gl.createVertexArray();
130
130
  gl.bindVertexArray(vao);
131
131
  attributeLoader(gl, position3D, 0, 3);
132
132
  attributeLoader(gl, position2D, 1, 2);
133
133
  attributeLoader(gl, color, 2, 4, { escapeValues: [ESCAPE_VALUE, ESCAPE_VALUE, ESCAPE_VALUE, ESCAPE_VALUE] });
134
- attributeLoader(gl, dashLength, 3, 1, { escapeValues: [ESCAPE_VALUE] });
135
- attributeLoader(gl, dashOpacity, 4, 1, { escapeValues: [ESCAPE_VALUE] });
134
+ // attributeLoader(gl, dashLength, 3, 1, { escapeValues: [ESCAPE_VALUE] });
135
+ // attributeLoader(gl, dashOpacity, 4, 1, { escapeValues: [ESCAPE_VALUE] });
136
136
  gl.bindVertexArray(null);
137
137
  return vao;
138
138
  }