@pirireis/webglobeplugins 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/Math/{angle-calculation.ts → angle-calculation.js} +14 -18
  2. package/Math/{arc-cdf-points.ts → arc-cdf-points.js} +272 -329
  3. package/Math/{arc-generate-points-exponantial.ts → arc-generate-points-exponantial.js} +254 -299
  4. package/Math/{arc.ts → arc.js} +292 -421
  5. package/Math/bounds/line-bbox.js +186 -225
  6. package/Math/{circle-cdf-points.ts → circle-cdf-points.js} +78 -143
  7. package/Math/{circle.ts → circle.js} +33 -49
  8. package/Math/{constants.ts → constants.js} +4 -12
  9. package/Math/contour/{quadtreecontours.ts → quadtreecontours.js} +300 -371
  10. package/Math/contour/quadtreecontours1.js +298 -336
  11. package/Math/{finite-line-2d.ts → finite-line-2d.js} +58 -68
  12. package/Math/{haversine.ts → haversine.js} +22 -33
  13. package/Math/index.js +1 -0
  14. package/Math/juction/{arc-plane.ts → arc-plane.js} +143 -203
  15. package/Math/juction/{line-sphere.ts → line-sphere.js} +22 -32
  16. package/Math/juction/{plane-plane.ts → plane-plane.js} +53 -62
  17. package/Math/{line.ts → line.js} +52 -84
  18. package/Math/matrix4.js +1 -0
  19. package/Math/{methods.ts → methods.js} +126 -182
  20. package/Math/{plane.ts → plane.js} +56 -92
  21. package/Math/{quaternion.ts → quaternion.js} +106 -128
  22. package/Math/templete-shapes/{grid-visually-equal.ts → grid-visually-equal.js} +65 -118
  23. package/Math/tessellation/constants.js +1 -0
  24. package/Math/tessellation/{methods.ts → methods.js} +49 -79
  25. package/Math/tessellation/{nearest-value-padding.ts → nearest-value-padding.js} +112 -147
  26. package/Math/tessellation/{spherical-triangle-area.ts → spherical-triangle-area.js} +99 -127
  27. package/Math/tessellation/{tile-merger.ts → tile-merger.js} +429 -578
  28. package/Math/tessellation/{triangle-tessellation.ts → triangle-tessellation.js} +386 -533
  29. package/Math/tessellation/types.js +1 -0
  30. package/Math/types.js +1 -0
  31. package/Math/utils.js +2 -3
  32. package/Math/{vec3.ts → vec3.js} +155 -227
  33. package/Math/{xyz-tile.ts → xyz-tile.js} +18 -26
  34. package/algorithms/search-binary.js +16 -14
  35. package/altitude-locator/adaptors.js +1 -0
  36. package/altitude-locator/keymethod.js +1 -0
  37. package/altitude-locator/plugin.js +344 -445
  38. package/altitude-locator/types.js +21 -26
  39. package/compass-rose/compass-rose-padding-flat.js +230 -274
  40. package/compass-rose/{compass-text-writer.ts → compass-text-writer.js} +155 -210
  41. package/compass-rose/index.js +3 -3
  42. package/{constants.ts → constants.js} +6 -8
  43. package/heatwave/datamanager.js +149 -168
  44. package/heatwave/heatwave.js +206 -261
  45. package/heatwave/index.js +5 -5
  46. package/heatwave/isobar.js +303 -340
  47. package/heatwave/{texture-point-sampler.ts → texture-point-sampler.js} +187 -220
  48. package/investigation-tools/draw/tiles/adapters.js +67 -0
  49. package/investigation-tools/draw/tiles/{tiles.ts → tiles.js} +128 -162
  50. package/jest.config.js +7 -6
  51. package/package.json +1 -1
  52. package/pin/pin-object-array1.js +300 -381
  53. package/pin/pin-point-totem1.js +60 -77
  54. package/programs/arrowfield/arrow-field.js +60 -89
  55. package/programs/arrowfield/logic.js +141 -173
  56. package/programs/data2legend/density-to-legend.js +68 -86
  57. package/programs/data2legend/point-to-density-texture.js +67 -84
  58. package/programs/float2legendwithratio/index.js +2 -3
  59. package/programs/float2legendwithratio/logic.js +118 -144
  60. package/programs/float2legendwithratio/object.js +104 -141
  61. package/programs/helpers/blender.js +58 -73
  62. package/programs/helpers/{fadeaway.ts → fadeaway.js} +60 -73
  63. package/programs/index.js +20 -19
  64. package/programs/line-on-globe/circle-accurate-3d.js +85 -112
  65. package/programs/line-on-globe/circle-accurate-flat.js +148 -200
  66. package/programs/line-on-globe/degree-padding-around-circle-3d.js +102 -134
  67. package/programs/line-on-globe/index.js +1 -0
  68. package/programs/line-on-globe/lines-color-instanced-flat.js +80 -99
  69. package/programs/line-on-globe/linestrip/data.js +4 -0
  70. package/programs/line-on-globe/linestrip/{linestrip.ts → linestrip.js} +93 -152
  71. package/programs/line-on-globe/{naive-accurate-flexible.ts → naive-accurate-flexible.js} +126 -175
  72. package/programs/line-on-globe/util.js +5 -8
  73. package/programs/picking/pickable-polygon-renderer.js +98 -129
  74. package/programs/picking/pickable-renderer.js +98 -130
  75. package/programs/point-on-globe/element-globe-surface-glow.js +93 -122
  76. package/programs/point-on-globe/element-point-glow.js +80 -114
  77. package/programs/point-on-globe/square-pixel-point.js +121 -139
  78. package/programs/polygon-on-globe/{texture-dem-triangles.ts → texture-dem-triangles.js} +163 -207
  79. package/programs/{programcache.ts → programcache.js} +126 -134
  80. package/programs/rings/index.js +1 -1
  81. package/programs/rings/partial-ring/{piece-of-pie.ts → piece-of-pie.js} +152 -222
  82. package/programs/totems/camera-totem-attactment-interface.js +1 -0
  83. package/programs/totems/{camerauniformblock.ts → camerauniformblock.js} +225 -310
  84. package/programs/totems/{canvas-webglobe-info.ts → canvas-webglobe-info.js} +132 -147
  85. package/programs/totems/{dem-textures-manager.ts → dem-textures-manager.js} +257 -360
  86. package/programs/totems/{globe-changes.ts → globe-changes.js} +59 -79
  87. package/programs/totems/gpu-selection-uniform-block.js +99 -127
  88. package/programs/totems/{index.ts → index.js} +2 -2
  89. package/programs/two-d/pixel-padding-for-compass.js +87 -101
  90. package/programs/util.js +14 -19
  91. package/programs/vectorfields/logics/{constants.ts → constants.js} +4 -5
  92. package/programs/vectorfields/logics/{drawrectangleparticles.ts → drawrectangleparticles.js} +80 -115
  93. package/programs/vectorfields/logics/index.js +2 -4
  94. package/programs/vectorfields/logics/particle-ubo.js +16 -0
  95. package/programs/vectorfields/logics/{pixelbased.ts → pixelbased.js} +86 -115
  96. package/programs/vectorfields/logics/ubo.js +51 -57
  97. package/programs/vectorfields/{pingpongbuffermanager.ts → pingpongbuffermanager.js} +99 -113
  98. package/range-tools-on-terrain/bearing-line/{adapters.ts → adapters.js} +114 -154
  99. package/range-tools-on-terrain/bearing-line/{plugin.ts → plugin.js} +457 -569
  100. package/range-tools-on-terrain/bearing-line/types.js +1 -0
  101. package/range-tools-on-terrain/circle-line-chain/{adapters.ts → adapters.js} +85 -104
  102. package/range-tools-on-terrain/circle-line-chain/{chain-list-map.ts → chain-list-map.js} +382 -446
  103. package/range-tools-on-terrain/circle-line-chain/{plugin.ts → plugin.js} +464 -607
  104. package/range-tools-on-terrain/circle-line-chain/types.js +1 -0
  105. package/range-tools-on-terrain/range-ring/{adapters.ts → adapters.js} +93 -114
  106. package/range-tools-on-terrain/range-ring/{enum.ts → enum.js} +2 -2
  107. package/range-tools-on-terrain/range-ring/{plugin.ts → plugin.js} +377 -444
  108. package/range-tools-on-terrain/range-ring/rangeringangletext.js +331 -0
  109. package/range-tools-on-terrain/range-ring/types.js +9 -0
  110. package/semiplugins/interface.js +1 -0
  111. package/semiplugins/lightweight/{line-plugin.ts → line-plugin.js} +221 -342
  112. package/semiplugins/lightweight/{piece-of-pie-plugin.ts → piece-of-pie-plugin.js} +200 -275
  113. package/semiplugins/shape-on-terrain/{arc-plugin.ts → arc-plugin.js} +481 -616
  114. package/semiplugins/shape-on-terrain/{circle-plugin.ts → circle-plugin.js} +444 -588
  115. package/semiplugins/shape-on-terrain/{padding-1-degree.ts → padding-1-degree.js} +539 -713
  116. package/semiplugins/shape-on-terrain/terrain-polygon/{adapters.ts → adapters.js} +55 -69
  117. package/semiplugins/shape-on-terrain/terrain-polygon/data/{cache.ts → cache.js} +102 -149
  118. package/semiplugins/shape-on-terrain/terrain-polygon/data/{index-polygon-map.ts → index-polygon-map.js} +45 -58
  119. package/semiplugins/shape-on-terrain/terrain-polygon/data/{manager.ts → manager.js} +4 -4
  120. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.js +177 -196
  121. package/semiplugins/shape-on-terrain/terrain-polygon/data/{polygon-to-triangles.ts → polygon-to-triangles.js} +100 -144
  122. package/semiplugins/shape-on-terrain/terrain-polygon/data/{random.ts → random.js} +121 -165
  123. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.js +1 -0
  124. package/semiplugins/shape-on-terrain/terrain-polygon/data/{worker-contact.ts → worker-contact.js} +63 -81
  125. package/semiplugins/shape-on-terrain/terrain-polygon/data/worker.js +125 -146
  126. package/semiplugins/shape-on-terrain/terrain-polygon/{terrain-polygon.ts → terrain-polygon.js} +219 -265
  127. package/semiplugins/shape-on-terrain/terrain-polygon/types.js +8 -0
  128. package/semiplugins/shell/bbox-renderer/index.js +2 -0
  129. package/semiplugins/shell/bbox-renderer/{logic.ts → logic.js} +209 -273
  130. package/semiplugins/shell/bbox-renderer/object.js +75 -0
  131. package/semiplugins/type.js +1 -0
  132. package/semiplugins/utility/{container-plugin.ts → container-plugin.js} +94 -126
  133. package/semiplugins/utility/{object-pass-container-plugin.ts → object-pass-container-plugin.js} +80 -101
  134. package/shaders/fragment-toy/firework.js +1 -1
  135. package/shaders/fragment-toy/singularity.js +2 -5
  136. package/tracks/point-heat-map/adaptors/timetracksplugin-format-to-this.js +63 -78
  137. package/tracks/point-heat-map/index.js +1 -0
  138. package/tracks/point-heat-map/plugin-webworker.js +121 -148
  139. package/tracks/point-heat-map/point-to-heat-map-flow.js +121 -150
  140. package/tracks/point-tracks/key-methods.js +2 -3
  141. package/tracks/point-tracks/plugin.js +401 -487
  142. package/tracks/timetracks/adaptors-line-strip.js +65 -79
  143. package/tracks/timetracks/plugin-line-strip.js +240 -295
  144. package/tracks/timetracks/program-line-strip.js +411 -495
  145. package/tracks/timetracks/programpoint-line-strip.js +109 -137
  146. package/types.js +19 -0
  147. package/util/account/bufferoffsetmanager.js +176 -209
  148. package/util/account/create-buffermap-orchastration.js +39 -0
  149. package/util/account/index.js +3 -6
  150. package/util/account/single-attribute-buffer-management/{buffer-manager.ts → buffer-manager.js} +119 -151
  151. package/util/account/single-attribute-buffer-management/{buffer-orchestrator.ts → buffer-orchestrator.js} +212 -238
  152. package/util/account/single-attribute-buffer-management/{buffer-orchestrator1.ts → buffer-orchestrator1.js} +159 -184
  153. package/util/account/single-attribute-buffer-management/{index.ts → index.js} +4 -11
  154. package/util/account/single-attribute-buffer-management/{object-store.ts → object-store.js} +55 -76
  155. package/util/account/single-attribute-buffer-management/types.js +1 -0
  156. package/util/account/util.js +18 -22
  157. package/util/algorithms/index.js +1 -0
  158. package/util/algorithms/search-binary.js +25 -26
  159. package/util/build-strategy/{static-dynamic.ts → static-dynamic.js} +41 -50
  160. package/util/check/index.js +1 -0
  161. package/util/check/typecheck.js +66 -0
  162. package/util/{frame-counter-trigger.ts → frame-counter-trigger.js} +84 -99
  163. package/util/geometry/{index.ts → index.js} +121 -155
  164. package/util/gl-util/buffer/{attribute-loader.ts → attribute-loader.js} +62 -84
  165. package/util/gl-util/buffer/{index.ts → index.js} +3 -6
  166. package/util/gl-util/draw-options/{methods.ts → methods.js} +32 -47
  167. package/util/gl-util/uniform-block/{manager.ts → manager.js} +200 -232
  168. package/util/{globe-default-gl-states.ts → globe-default-gl-states.js} +4 -5
  169. package/util/{helper-methods.ts → helper-methods.js} +8 -9
  170. package/util/index.js +10 -9
  171. package/util/interpolation/index.js +1 -0
  172. package/util/interpolation/timetrack/index.js +2 -9
  173. package/util/interpolation/timetrack/timetrack-interpolator.js +79 -94
  174. package/util/interpolation/timetrack/web-worker.js +46 -51
  175. package/util/picking/{fence.ts → fence.js} +43 -47
  176. package/util/picking/{picker-displayer.ts → picker-displayer.js} +176 -226
  177. package/util/programs/draw-from-pixel-coords.js +164 -201
  178. package/util/programs/{draw-texture-on-canvas.ts → draw-texture-on-canvas.js} +69 -91
  179. package/util/programs/supersampletotextures.js +97 -130
  180. package/util/programs/texturetoglobe.js +128 -153
  181. package/util/shaderfunctions/{geometrytransformations.ts → geometrytransformations.js} +44 -106
  182. package/util/shaderfunctions/index.js +2 -2
  183. package/util/shaderfunctions/nodata.js +2 -4
  184. package/util/shaderfunctions/noisefunctions.js +7 -10
  185. package/util/{webglobjectbuilders.ts → webglobjectbuilders.js} +358 -446
  186. package/vectorfield/arrowfield/adaptor.js +11 -11
  187. package/vectorfield/arrowfield/index.js +3 -3
  188. package/vectorfield/arrowfield/plugin.js +83 -128
  189. package/vectorfield/waveparticles/adaptor.js +15 -16
  190. package/vectorfield/waveparticles/index.js +3 -3
  191. package/vectorfield/waveparticles/{plugin.ts → plugin.js} +415 -506
  192. package/vectorfield/wind/adapters/{image-to-fields.ts → image-to-fields.js} +61 -74
  193. package/vectorfield/wind/adapters/types.js +1 -0
  194. package/vectorfield/wind/{imagetovectorfieldandmagnitude.ts → imagetovectorfieldandmagnitude.js} +53 -78
  195. package/vectorfield/wind/index.js +5 -5
  196. package/vectorfield/wind/{plugin-persistant copy.ts → plugin-persistant copy.js } +364 -461
  197. package/vectorfield/wind/{plugin-persistant.ts → plugin-persistant.js} +375 -483
  198. package/vectorfield/wind/plugin.js +685 -883
  199. package/vectorfield/wind/vectorfieldimage.js +23 -27
  200. package/write-text/{context-text-bulk.ts → context-text-bulk.js} +200 -285
  201. package/write-text/context-text3.js +167 -0
  202. package/write-text/{context-text4.ts → context-text4.js} +146 -231
  203. package/write-text/context-textDELETE.js +94 -125
  204. package/write-text/objectarraylabels/{index.ts → index.js} +2 -2
  205. package/write-text/objectarraylabels/objectarraylabels.js +200 -247
  206. package/Math/matrix4.ts +0 -0
  207. package/Math/mesh/mapbox-delaunay.d.ts +0 -74
  208. package/Math/roadmap.md +0 -10
  209. package/Math/tessellation/constants.ts +0 -1
  210. package/Math/tessellation/roadmap.md +0 -48
  211. package/Math/tessellation/types.ts +0 -1
  212. package/Math/types.ts +0 -68
  213. package/investigation-tools/draw/tiles/adapters.ts +0 -133
  214. package/programs/line-on-globe/linestrip/data.ts +0 -29
  215. package/programs/polygon-on-globe/roadmap.md +0 -8
  216. package/programs/totems/camera-totem-attactment-interface.ts +0 -4
  217. package/programs/vectorfields/logics/particle-ubo.ts +0 -23
  218. package/publish.bat +0 -62
  219. package/range-tools-on-terrain/bearing-line/types.ts +0 -65
  220. package/range-tools-on-terrain/circle-line-chain/types.ts +0 -43
  221. package/range-tools-on-terrain/range-ring/rangeringangletext.ts +0 -396
  222. package/range-tools-on-terrain/range-ring/types.ts +0 -30
  223. package/semiplugins/interface.ts +0 -14
  224. package/semiplugins/shape-on-terrain/goal.md +0 -12
  225. package/semiplugins/shape-on-terrain/terrain-polygon/data/cache-shortcuts.md +0 -20
  226. package/semiplugins/shape-on-terrain/terrain-polygon/data/master-worker.ts +0 -209
  227. package/semiplugins/shape-on-terrain/terrain-polygon/data/readme.md +0 -5
  228. package/semiplugins/shape-on-terrain/terrain-polygon/data/types.ts +0 -37
  229. package/semiplugins/shape-on-terrain/terrain-polygon/notes.md +0 -90
  230. package/semiplugins/shape-on-terrain/terrain-polygon/types.ts +0 -69
  231. package/semiplugins/shell/bbox-renderer/index.ts +0 -2
  232. package/semiplugins/shell/bbox-renderer/object.ts +0 -129
  233. package/semiplugins/type.ts +0 -8
  234. package/terrain-plugin.mmd +0 -83
  235. package/tests/Math/arc-sampling-test.js +0 -367
  236. package/tests/Math/arc-sampling-test.ts +0 -429
  237. package/tests/Math/arc.test.ts +0 -77
  238. package/tests/Math/junction/arc-limit.test.ts +0 -7
  239. package/tests/Math/junction/arc-plane-points.test.ts +0 -196
  240. package/tests/Math/junction/arc-plane.test.ts +0 -172
  241. package/tests/Math/junction/line-sphere.test.ts +0 -127
  242. package/tests/Math/junction/plane-plane.test.ts +0 -91
  243. package/tests/Math/plane-test.ts +0 -17
  244. package/tests/Math/plane.test.ts +0 -43
  245. package/tests/Math/vec3.test.ts +0 -33
  246. package/tracks/point-heat-map/readme.md +0 -15
  247. package/tracks/timetracks/readme.md +0 -1
  248. package/tsconfig.json +0 -22
  249. package/types/@pirireis/webglobe.d.ts +0 -102
  250. package/types/delaunator.d.ts +0 -40
  251. package/types/earcut.d.ts +0 -11
  252. package/types/rbush.d.ts +0 -57
  253. package/types.ts +0 -319
  254. package/util/account/create-buffermap-orchastration.ts +0 -85
  255. package/util/account/single-attribute-buffer-management/types.ts +0 -43
  256. package/util/check/typecheck.ts +0 -74
  257. package/vectorfield/wind/adapters/types.ts +0 -12
  258. package/write-text/context-text3.ts +0 -252
  259. package/write-text/objectarraylabels/objectarraylabels.d.ts +0 -72
@@ -1,200 +1,165 @@
1
- /**
2
- * Author: Toprak Nihat Deniz Ozturk
3
- */
4
-
5
- // import { createProgram, defaultblendfunction, shaderfunctions } from "../../util";
6
- import { createProgram } from "../../util/webglobjectbuilders";
7
- import { defaultblendfunction } from "../../util/globe-default-gl-states";
8
- import {
9
- pixelXYToCartesian2DPoint,
10
- pixelXYToCartesian3DPoint,
11
- } from "../../util/shaderfunctions";
12
-
13
- export default class TrackGlowLineProgram {
14
- /**
15
- * @param {WebGL2RenderingContext} gl
16
- * @param {number} width
17
- * @param {number} height
18
- * @param {Object} options
19
- * @param {number} options.headPercentage 0 ~ 1
20
- * @param {number} options.routeAlpha 0 ~ 1
21
- * @param {Array.<Number>} options.weights [w1, w2, w3, w4, w5]
22
- * @param {number} options.alphaThreshold 0 ~ 1
23
- * @param {number} options.exposure 0 ~ inf
24
- * @param {number} options.gamma 0 ~ inf
25
- * @param {number} options.finalAlphaRatio 0 ~ 1
26
- * @param {+int} options.blurRepetition 1 ~ inf default 2
27
- */
28
- constructor(gl, attrBuffer, width, height, options = {}) {
29
- this.gl = gl;
30
- this.program = null;
31
-
32
-
33
- // this._inBuffer = gl.createBuffer();
34
- this._inBuffer = attrBuffer;
35
-
36
- this._frameBuffer = gl.createFramebuffer();
37
- this._lineProgram = this._createLineProgram();
38
- this._blurProgram = this._createBlurProgram();
39
- this._combineProgram = this._createCombineProgram();
40
- this.resize(width, height);
41
-
42
- this._middleTexture = null;
43
- this._blurTextures = null;
44
- this._createInnerTextures();
45
-
46
- this._blurFrameBuffers = [gl.createFramebuffer(), gl.createFramebuffer()];
47
-
48
- this._blurRepetition = options.blurRepetition || 1;
49
- this._totalLength = 0;
50
- this._initUniforms(options);
51
- }
52
-
53
-
54
- _createInnerTextures() {
55
- this._middleTexture = this._createTextures();
56
- this._blurTextures = [this._createTextures(), this._createTextures()];
57
- }
58
-
59
- _initUniforms(options = {}) {
60
- const { gl, _lineProgram, _blurProgram, _combineProgram } = this;
61
-
62
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
63
-
64
- gl.useProgram(_lineProgram.program);
65
- gl.uniform1f(_lineProgram.u_head_percentage, options.headPercentage || 1.0 / 30.0);
66
- gl.uniform1f(_lineProgram.u_route_alpha, options.routeAlpha || 0.025);
67
-
68
- gl.useProgram(_blurProgram.program);
69
- gl.uniform1fv(_blurProgram.u_weight, options.weights || [0.55, 0.45045946, 0.3216216, 0.254054, 0.056216]);
70
-
71
- gl.useProgram(_combineProgram.program);
72
- gl.uniform1f(_combineProgram.u_exposure, options.exposure || 1.0);
73
- gl.uniform1f(_combineProgram.u_gamma, options.gamma || 1.0);
74
- gl.uniform1f(_combineProgram.u_final_alpha_ratio, options.finalAlphaRatio || 1.0);
75
- gl.useProgram(currentProgram);
76
- }
77
-
78
-
79
-
80
-
81
-
82
- /**
83
- * @param {number} gamma 0 ~ inf
84
- */
85
- setGamma(gamma) {
86
- if (gamma < 0) {
87
- console.warn("gamma should be equal or greater than 0, but got", gamma);
88
- return;
89
- }
90
- const { gl, _combineProgram } = this;
91
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
92
- gl.useProgram(_combineProgram.program);
93
- gl.uniform1f(_combineProgram.u_gamma, gamma);
94
- gl.useProgram(currentProgram);
95
- }
96
-
97
- /**
98
- *
99
- * @param {number} exposure 0 ~ inf
100
- * @returns
101
- */
102
- setExposure(exposure) {
103
- if (exposure < 0) {
104
- console.warn("exposure should be equal or greater than 0, but got", exposure);
105
- return;
106
- }
107
- const { gl, _combineProgram } = this;
108
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
109
- gl.useProgram(_combineProgram.program);
110
- gl.uniform1f(_combineProgram.u_exposure, exposure);
111
- gl.useProgram(currentProgram);
112
- }
113
-
114
-
115
- /**
116
- *
117
- * @param {number} ratio 0 ~ 1
118
- * @returns
119
- */
120
- setFinalAlphaRatio(ratio) {
121
- if (ratio < 0 || ratio > 1) {
122
- console.warn("ratio should be between 0 and 1, but got", ratio);
123
- return;
124
- }
125
- const { gl, _combineProgram } = this;
126
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
127
- gl.useProgram(_combineProgram.program);
128
- gl.uniform1f(_combineProgram.u_final_alpha_ratio, ratio);
129
- gl.useProgram(currentProgram);
130
-
131
- }
132
-
133
- /**
134
- * @param {Array.<Number>} weight [w1, w2, w3, w4, w5]
135
- */
136
- setBlurWeights(weights) {
137
- if (weights.length !== 5) {
138
- console.warn("weights should be an array of 5 numbers, but got", weights);
139
- return;
140
- }
141
- const { gl, _blurProgram } = this;
142
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
143
- gl.useProgram(_blurProgram.program);
144
- gl.uniform1fv(_blurProgram.u_weight, weights);
145
- gl.useProgram(currentProgram);
146
- }
147
-
148
-
149
- /**
150
- * @param {number} routeAlpha 0 ~ 1
151
- */
152
- setRouteAlpha(routeAlpha) {
153
- if (routeAlpha < 0 || routeAlpha > 1) {
154
- console.warn("routeAlpha should be between 0 and 1, but got", routeAlpha);
155
- return;
156
- }
157
- const { gl, _lineProgram } = this;
158
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
159
- gl.useProgram(_lineProgram.program);
160
- gl.uniform1f(_lineProgram.u_route_alpha, routeAlpha);
161
- gl.useProgram(currentProgram);
162
- }
163
-
164
-
165
- /**
166
- * blur uses pingpong effect. This number decides how many times the blur will be applied.
167
- * @param {+int} repetition
168
- * @returns
169
- */
170
- setBlurRepetition(repetition) {
171
- if (repetition < 0 && repetition % 1 !== 0) {
172
- console.warn("repetition should be an integer greater than 0, but got", repetition);
173
- return;
174
- }
175
- this._blurRepetition = repetition;
176
- }
177
-
178
- /**
179
- * Head Is colored as white. This number decides proportion of the head according to the total length of the line.
180
- * @param {Number} percentage 0 ~ 1
181
- */
182
- setHeadPercentage(percentage) {
183
- if (percentage < 0 || 1 < percentage) {
184
- console.warn("percentage should be between 0 and 1, but got", percentage);
185
- return
186
- };
187
- const { gl, _lineProgram } = this;
188
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
189
- gl.useProgram(_lineProgram.program);
190
- gl.uniform1f(_lineProgram.u_head_percentage, percentage);
191
- gl.useProgram(currentProgram);
192
- }
193
-
194
-
195
- _createDrawTextureProgram() {
196
- const gl = this.gl;
197
-
1
+ /**
2
+ * Author: Toprak Nihat Deniz Ozturk
3
+ */
4
+ // import { createProgram, defaultblendfunction, shaderfunctions } from "../../util";
5
+ import { createProgram } from "../../util/webglobjectbuilders";
6
+ import { defaultblendfunction } from "../../util/globe-default-gl-states";
7
+ import { pixelXYToCartesian2DPoint, pixelXYToCartesian3DPoint, } from "../../util/shaderfunctions";
8
+ export default class TrackGlowLineProgram {
9
+ /**
10
+ * @param {WebGL2RenderingContext} gl
11
+ * @param {number} width
12
+ * @param {number} height
13
+ * @param {Object} options
14
+ * @param {number} options.headPercentage 0 ~ 1
15
+ * @param {number} options.routeAlpha 0 ~ 1
16
+ * @param {Array.<Number>} options.weights [w1, w2, w3, w4, w5]
17
+ * @param {number} options.alphaThreshold 0 ~ 1
18
+ * @param {number} options.exposure 0 ~ inf
19
+ * @param {number} options.gamma 0 ~ inf
20
+ * @param {number} options.finalAlphaRatio 0 ~ 1
21
+ * @param {+int} options.blurRepetition 1 ~ inf default 2
22
+ */
23
+ constructor(gl, attrBuffer, width, height, options = {}) {
24
+ this.gl = gl;
25
+ this.program = null;
26
+ // this._inBuffer = gl.createBuffer();
27
+ this._inBuffer = attrBuffer;
28
+ this._frameBuffer = gl.createFramebuffer();
29
+ this._lineProgram = this._createLineProgram();
30
+ this._blurProgram = this._createBlurProgram();
31
+ this._combineProgram = this._createCombineProgram();
32
+ this.resize(width, height);
33
+ this._middleTexture = null;
34
+ this._blurTextures = null;
35
+ this._createInnerTextures();
36
+ this._blurFrameBuffers = [gl.createFramebuffer(), gl.createFramebuffer()];
37
+ this._blurRepetition = options.blurRepetition || 1;
38
+ this._totalLength = 0;
39
+ this._initUniforms(options);
40
+ }
41
+ _createInnerTextures() {
42
+ this._middleTexture = this._createTextures();
43
+ this._blurTextures = [this._createTextures(), this._createTextures()];
44
+ }
45
+ _initUniforms(options = {}) {
46
+ const { gl, _lineProgram, _blurProgram, _combineProgram } = this;
47
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
48
+ gl.useProgram(_lineProgram.program);
49
+ gl.uniform1f(_lineProgram.u_head_percentage, options.headPercentage || 1.0 / 30.0);
50
+ gl.uniform1f(_lineProgram.u_route_alpha, options.routeAlpha || 0.025);
51
+ gl.useProgram(_blurProgram.program);
52
+ gl.uniform1fv(_blurProgram.u_weight, options.weights || [0.55, 0.45045946, 0.3216216, 0.254054, 0.056216]);
53
+ gl.useProgram(_combineProgram.program);
54
+ gl.uniform1f(_combineProgram.u_exposure, options.exposure || 1.0);
55
+ gl.uniform1f(_combineProgram.u_gamma, options.gamma || 1.0);
56
+ gl.uniform1f(_combineProgram.u_final_alpha_ratio, options.finalAlphaRatio || 1.0);
57
+ gl.useProgram(currentProgram);
58
+ }
59
+ /**
60
+ * @param {number} gamma 0 ~ inf
61
+ */
62
+ setGamma(gamma) {
63
+ if (gamma < 0) {
64
+ console.warn("gamma should be equal or greater than 0, but got", gamma);
65
+ return;
66
+ }
67
+ const { gl, _combineProgram } = this;
68
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
69
+ gl.useProgram(_combineProgram.program);
70
+ gl.uniform1f(_combineProgram.u_gamma, gamma);
71
+ gl.useProgram(currentProgram);
72
+ }
73
+ /**
74
+ *
75
+ * @param {number} exposure 0 ~ inf
76
+ * @returns
77
+ */
78
+ setExposure(exposure) {
79
+ if (exposure < 0) {
80
+ console.warn("exposure should be equal or greater than 0, but got", exposure);
81
+ return;
82
+ }
83
+ const { gl, _combineProgram } = this;
84
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
85
+ gl.useProgram(_combineProgram.program);
86
+ gl.uniform1f(_combineProgram.u_exposure, exposure);
87
+ gl.useProgram(currentProgram);
88
+ }
89
+ /**
90
+ *
91
+ * @param {number} ratio 0 ~ 1
92
+ * @returns
93
+ */
94
+ setFinalAlphaRatio(ratio) {
95
+ if (ratio < 0 || ratio > 1) {
96
+ console.warn("ratio should be between 0 and 1, but got", ratio);
97
+ return;
98
+ }
99
+ const { gl, _combineProgram } = this;
100
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
101
+ gl.useProgram(_combineProgram.program);
102
+ gl.uniform1f(_combineProgram.u_final_alpha_ratio, ratio);
103
+ gl.useProgram(currentProgram);
104
+ }
105
+ /**
106
+ * @param {Array.<Number>} weight [w1, w2, w3, w4, w5]
107
+ */
108
+ setBlurWeights(weights) {
109
+ if (weights.length !== 5) {
110
+ console.warn("weights should be an array of 5 numbers, but got", weights);
111
+ return;
112
+ }
113
+ const { gl, _blurProgram } = this;
114
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
115
+ gl.useProgram(_blurProgram.program);
116
+ gl.uniform1fv(_blurProgram.u_weight, weights);
117
+ gl.useProgram(currentProgram);
118
+ }
119
+ /**
120
+ * @param {number} routeAlpha 0 ~ 1
121
+ */
122
+ setRouteAlpha(routeAlpha) {
123
+ if (routeAlpha < 0 || routeAlpha > 1) {
124
+ console.warn("routeAlpha should be between 0 and 1, but got", routeAlpha);
125
+ return;
126
+ }
127
+ const { gl, _lineProgram } = this;
128
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
129
+ gl.useProgram(_lineProgram.program);
130
+ gl.uniform1f(_lineProgram.u_route_alpha, routeAlpha);
131
+ gl.useProgram(currentProgram);
132
+ }
133
+ /**
134
+ * blur uses pingpong effect. This number decides how many times the blur will be applied.
135
+ * @param {+int} repetition
136
+ * @returns
137
+ */
138
+ setBlurRepetition(repetition) {
139
+ if (repetition < 0 && repetition % 1 !== 0) {
140
+ console.warn("repetition should be an integer greater than 0, but got", repetition);
141
+ return;
142
+ }
143
+ this._blurRepetition = repetition;
144
+ }
145
+ /**
146
+ * Head Is colored as white. This number decides proportion of the head according to the total length of the line.
147
+ * @param {Number} percentage 0 ~ 1
148
+ */
149
+ setHeadPercentage(percentage) {
150
+ if (percentage < 0 || 1 < percentage) {
151
+ console.warn("percentage should be between 0 and 1, but got", percentage);
152
+ return;
153
+ }
154
+ ;
155
+ const { gl, _lineProgram } = this;
156
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
157
+ gl.useProgram(_lineProgram.program);
158
+ gl.uniform1f(_lineProgram.u_head_percentage, percentage);
159
+ gl.useProgram(currentProgram);
160
+ }
161
+ _createDrawTextureProgram() {
162
+ const gl = this.gl;
198
163
  const vertexShader = `#version 300 es
199
164
  precision highp float;
200
165
 
@@ -206,8 +171,7 @@ void main() {
206
171
  gl_Position = vec4(a_position, 0.0, 1.0);
207
172
  v_texcoord = a_position.xy * 0.5 + 0.5;
208
173
  }
209
- `;
210
-
174
+ `;
211
175
  const fragmentShader = `#version 300 es
212
176
  precision highp float;
213
177
 
@@ -226,38 +190,33 @@ void main() {
226
190
  outColor = hdrColor;
227
191
  outColor.a *= u_final_alpha_ratio;
228
192
  }
229
- `;
230
- const program = createProgram(this.gl, vertexShader, fragmentShader);
231
-
232
- const buffer = gl.createBuffer();
233
- const a_position = gl.getAttribLocation(program, "a_position");
234
- const vao = gl.createVertexArray();
235
- gl.bindVertexArray(vao);
236
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
237
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
238
- -1, -1,
239
- 1, -1,
240
- 1, 1,
241
- -1, -1,
242
- 1, 1,
243
- -1, 1,
244
- ]), gl.STATIC_DRAW);
245
- gl.enableVertexAttribArray(a_position);
246
- gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
247
- gl.bindVertexArray(null);
248
-
249
- return {
250
- program: program,
251
- vao: vao,
252
- u_main_texture: gl.getUniformLocation(program, "u_main_texture"),
253
- u_final_alpha_ratio: gl.getUniformLocation(program, "u_final_alpha_ratio"),
254
- };
255
- }
256
-
257
-
258
- _createCombineProgram() {
259
- const gl = this.gl;
260
-
193
+ `;
194
+ const program = createProgram(this.gl, vertexShader, fragmentShader);
195
+ const buffer = gl.createBuffer();
196
+ const a_position = gl.getAttribLocation(program, "a_position");
197
+ const vao = gl.createVertexArray();
198
+ gl.bindVertexArray(vao);
199
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
200
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
201
+ -1, -1,
202
+ 1, -1,
203
+ 1, 1,
204
+ -1, -1,
205
+ 1, 1,
206
+ -1, 1,
207
+ ]), gl.STATIC_DRAW);
208
+ gl.enableVertexAttribArray(a_position);
209
+ gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
210
+ gl.bindVertexArray(null);
211
+ return {
212
+ program: program,
213
+ vao: vao,
214
+ u_main_texture: gl.getUniformLocation(program, "u_main_texture"),
215
+ u_final_alpha_ratio: gl.getUniformLocation(program, "u_final_alpha_ratio"),
216
+ };
217
+ }
218
+ _createCombineProgram() {
219
+ const gl = this.gl;
261
220
  const vertexShader = `#version 300 es
262
221
  precision highp float;
263
222
 
@@ -269,8 +228,7 @@ void main() {
269
228
  gl_Position = vec4(a_position, 0.0, 1.0);
270
229
  v_texcoord = a_position.xy * 0.5 + 0.5;
271
230
  }
272
- `;
273
-
231
+ `;
274
232
  const fragmentShader = `#version 300 es
275
233
  precision highp float;
276
234
 
@@ -294,41 +252,36 @@ void main() {
294
252
  result.a *= u_final_alpha_ratio;
295
253
  outColor = result;
296
254
  }
297
- `;
298
- const program = createProgram(this.gl, vertexShader, fragmentShader);
299
-
300
- const buffer = gl.createBuffer();
301
- const a_position = gl.getAttribLocation(program, "a_position");
302
- const vao = gl.createVertexArray();
303
- gl.bindVertexArray(vao);
304
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
305
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
306
- -1, -1,
307
- 1, -1,
308
- 1, 1,
309
- -1, -1,
310
- 1, 1,
311
- -1, 1,
312
- ]), gl.STATIC_DRAW);
313
- gl.enableVertexAttribArray(a_position);
314
- gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
315
- gl.bindVertexArray(null);
316
-
317
- return {
318
- program: program,
319
- vao: vao,
320
- u_main_texture: gl.getUniformLocation(program, "u_main_texture"),
321
- u_bloom_texture: gl.getUniformLocation(program, "u_bloom_texture"),
322
- u_exposure: gl.getUniformLocation(program, "u_exposure"),
323
- u_gamma: gl.getUniformLocation(program, "u_gamma"),
324
- u_final_alpha_ratio: gl.getUniformLocation(program, "u_final_alpha_ratio"),
325
- };
326
- }
327
-
328
-
329
- _createBlurProgram() {
330
- const gl = this.gl;
331
-
255
+ `;
256
+ const program = createProgram(this.gl, vertexShader, fragmentShader);
257
+ const buffer = gl.createBuffer();
258
+ const a_position = gl.getAttribLocation(program, "a_position");
259
+ const vao = gl.createVertexArray();
260
+ gl.bindVertexArray(vao);
261
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
262
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
263
+ -1, -1,
264
+ 1, -1,
265
+ 1, 1,
266
+ -1, -1,
267
+ 1, 1,
268
+ -1, 1,
269
+ ]), gl.STATIC_DRAW);
270
+ gl.enableVertexAttribArray(a_position);
271
+ gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
272
+ gl.bindVertexArray(null);
273
+ return {
274
+ program: program,
275
+ vao: vao,
276
+ u_main_texture: gl.getUniformLocation(program, "u_main_texture"),
277
+ u_bloom_texture: gl.getUniformLocation(program, "u_bloom_texture"),
278
+ u_exposure: gl.getUniformLocation(program, "u_exposure"),
279
+ u_gamma: gl.getUniformLocation(program, "u_gamma"),
280
+ u_final_alpha_ratio: gl.getUniformLocation(program, "u_final_alpha_ratio"),
281
+ };
282
+ }
283
+ _createBlurProgram() {
284
+ const gl = this.gl;
332
285
  const vertexShader = `#version 300 es
333
286
  precision highp float;
334
287
 
@@ -338,7 +291,7 @@ out vec2 v_texcoord;
338
291
  void main() {
339
292
  gl_Position = vec4(a_position, 0.0, 1.0);
340
293
  v_texcoord = a_position.xy * 0.5 + 0.5;
341
- }`;
294
+ }`;
342
295
  const fragmentShader = `#version 300 es
343
296
  precision highp float;
344
297
 
@@ -388,54 +341,45 @@ void main()
388
341
  }
389
342
  outColor = vec4(color, total_alpha);
390
343
  }
391
- `;
392
-
393
- const program = createProgram(this.gl, vertexShader, fragmentShader);
394
-
395
- const buffer = gl.createBuffer();
396
- const a_position = gl.getAttribLocation(program, "a_position");
397
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
398
- gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
399
- -1, -1,
400
- 1, -1,
401
- 1, 1,
402
- -1, -1,
403
- 1, 1,
404
- -1, 1,
405
- ]), gl.STATIC_DRAW);
406
- const vao = gl.createVertexArray();
407
- gl.bindVertexArray(vao);
408
- gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
409
- gl.enableVertexAttribArray(a_position);
410
-
411
- gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
412
- gl.bindVertexArray(null);
413
-
414
- return {
415
- program: program,
416
- vao: vao,
417
- u_texture: gl.getUniformLocation(program, "u_texture"),
418
- u_horizontal: gl.getUniformLocation(program, "u_horizontal"),
419
- u_weight: gl.getUniformLocation(program, "u_weight"),
420
- };
421
- }
422
-
423
-
424
- resize(width, height) {
425
- const { gl, _lineProgram } = this;
426
- this._width = width;
427
- this._height = height;
428
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
429
- this._createInnerTextures();
430
- gl.useProgram(_lineProgram.program);
431
- gl.uniform2fv(_lineProgram.u_scrWH, [width, height]);
432
- gl.useProgram(currentProgram);
433
- }
434
-
435
- _createLineProgram() {
436
-
437
- const gl = this.gl;
438
-
344
+ `;
345
+ const program = createProgram(this.gl, vertexShader, fragmentShader);
346
+ const buffer = gl.createBuffer();
347
+ const a_position = gl.getAttribLocation(program, "a_position");
348
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
349
+ gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
350
+ -1, -1,
351
+ 1, -1,
352
+ 1, 1,
353
+ -1, -1,
354
+ 1, 1,
355
+ -1, 1,
356
+ ]), gl.STATIC_DRAW);
357
+ const vao = gl.createVertexArray();
358
+ gl.bindVertexArray(vao);
359
+ gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
360
+ gl.enableVertexAttribArray(a_position);
361
+ gl.vertexAttribPointer(a_position, 2, gl.FLOAT, false, 0, 0);
362
+ gl.bindVertexArray(null);
363
+ return {
364
+ program: program,
365
+ vao: vao,
366
+ u_texture: gl.getUniformLocation(program, "u_texture"),
367
+ u_horizontal: gl.getUniformLocation(program, "u_horizontal"),
368
+ u_weight: gl.getUniformLocation(program, "u_weight"),
369
+ };
370
+ }
371
+ resize(width, height) {
372
+ const { gl, _lineProgram } = this;
373
+ this._width = width;
374
+ this._height = height;
375
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
376
+ this._createInnerTextures();
377
+ gl.useProgram(_lineProgram.program);
378
+ gl.uniform2fv(_lineProgram.u_scrWH, [width, height]);
379
+ gl.useProgram(currentProgram);
380
+ }
381
+ _createLineProgram() {
382
+ const gl = this.gl;
439
383
  const vertexShader = `#version 300 es
440
384
  precision highp float;
441
385
 
@@ -474,8 +418,7 @@ void main() {
474
418
  gl_Position = uProjectionMatrix * vec4(xy.x, xy.y, 0.0, 1.0);
475
419
  }
476
420
  }
477
- `;
478
-
421
+ `;
479
422
  const fragmentShader = `#version 300 es
480
423
  precision lowp float;
481
424
 
@@ -514,179 +457,152 @@ void main() {
514
457
  }
515
458
  outColor0 = vec4(v_color , 1.0);
516
459
  }
517
- `;
518
- const program = createProgram(this.gl, vertexShader, fragmentShader);
519
- const a_position = gl.getAttribLocation(program, "a_position");
520
- const a_time = gl.getAttribLocation(program, "a_time");
521
- const a_track_start_time = gl.getAttribLocation(program, "a_track_start_time");
522
- const a_track_end_time = gl.getAttribLocation(program, "a_track_end_time");
523
- const a_color = gl.getAttribLocation(program, "a_color");
524
-
525
- const vao = gl.createVertexArray();
526
- gl.bindVertexArray(vao);
527
- gl.bindBuffer(gl.ARRAY_BUFFER, this._inBuffer);
528
- gl.enableVertexAttribArray(a_position);
529
- gl.vertexAttribPointer(a_position, 3, gl.FLOAT, false, 36, 0);
530
- gl.enableVertexAttribArray(a_time);
531
- gl.vertexAttribPointer(a_time, 1, gl.FLOAT, false, 36, 12);
532
- gl.enableVertexAttribArray(a_color);
533
- gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 36, 16);
534
- gl.enableVertexAttribArray(a_track_start_time);
535
- gl.vertexAttribPointer(a_track_start_time, 1, gl.FLOAT, false, 36, 28);
536
- gl.enableVertexAttribArray(a_track_end_time);
537
- gl.vertexAttribPointer(a_track_end_time, 1, gl.FLOAT, false, 36, 32);
538
- gl.bindVertexArray(null);
539
- return {
540
- program: program,
541
- vao: vao,
542
- u_head_time: gl.getUniformLocation(program, "u_head_time"),
543
- u_tail_time: gl.getUniformLocation(program, "u_tail_time"),
544
- uTranslate: gl.getUniformLocation(program, "uTranslate"),
545
- uModelViewMatrix: gl.getUniformLocation(program, "uModelViewMatrix"),
546
- uProjectionMatrix: gl.getUniformLocation(program, "uProjectionMatrix"),
547
- u_is_3d: gl.getUniformLocation(program, "u_is_3d"),
548
- u_mapWH: gl.getUniformLocation(program, "u_mapWH"),
549
- u_scrWH: gl.getUniformLocation(program, "u_scrWH"),
550
- u_head_percentage: gl.getUniformLocation(program, "u_head_percentage"),
551
- u_route_alpha: gl.getUniformLocation(program, "u_route_alpha"),
552
- };
553
- }
554
-
555
-
556
- /**
557
- * @param { Float32Array} data // [x, y, z, time, x, y, z, time, ...]
558
- */
559
- // setInBuffer(data) {
560
- // const gl = this.gl;
561
- // gl.bindBuffer(gl.ARRAY_BUFFER, this._inBuffer);
562
- // gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
563
- // }
564
-
565
-
566
-
567
- setIs3D(is3d) {
568
- const { gl, _lineProgram } = this;
569
- const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
570
- gl.useProgram(_lineProgram.program);
571
- gl.uniform1i(_lineProgram.u_is_3d, is3d);
572
- gl.useProgram(currentProgram);
573
- }
574
-
575
-
576
- setTotalLength(totalLength) {
577
- this._totalLength = totalLength;
578
- }
579
-
580
-
581
- _createTextures() {
582
- const { gl, _width, _height } = this;
583
-
584
- const texture = gl.createTexture();
585
- gl.bindTexture(gl.TEXTURE_2D, texture);
586
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // UNSIGNED_BYTE
587
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
588
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
589
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
590
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
591
- gl.bindTexture(gl.TEXTURE_2D, null);
592
- return texture;
593
- }
594
-
595
- _resetTexture() {
596
- const { gl, _width, _height } = this;
597
- gl.bindTexture(gl.TEXTURE_2D, this._middleTexture); // UNSIGNED_BYTE
598
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
599
- gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[0]);
600
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
601
- gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[1]);
602
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
603
- gl.bindTexture(gl.TEXTURE_2D, null);
604
- }
605
-
606
-
607
-
608
- draw(u_head_time, u_tail_time, uProjectionMatrix, uModelViewMatrix, uTranslate, u_mapWH = null) {
609
- const { gl, _lineProgram, _blurProgram, _blurRepetition } = this;
610
- this._resetTexture();
611
-
612
- gl.enable(gl.BLEND);
613
- gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
614
-
615
- // draw lines
616
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
617
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._middleTexture, 0);
618
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, this._blurTextures[0], 0);
619
- gl.drawBuffers([
620
- gl.COLOR_ATTACHMENT0,
621
- gl.COLOR_ATTACHMENT1,
622
-
623
- ])
624
- gl.useProgram(_lineProgram.program);
625
- gl.uniform1f(_lineProgram.u_head_time, u_head_time);
626
- gl.uniform1f(_lineProgram.u_tail_time, u_tail_time);
627
- gl.uniformMatrix4fv(_lineProgram.uProjectionMatrix, false, uProjectionMatrix);
628
- if (u_mapWH) {
629
- gl.uniform2fv(_lineProgram.u_mapWH, u_mapWH);
630
-
631
- } else {
632
- gl.uniformMatrix4fv(_lineProgram.uModelViewMatrix, false, uModelViewMatrix);
633
- }
634
- gl.uniform3fv(_lineProgram.uTranslate, uTranslate);
635
-
636
- gl.bindVertexArray(_lineProgram.vao);
637
- gl.drawArrays(gl.LINE_STRIP, 0, this._totalLength);
638
- gl.drawBuffers([
639
- gl.COLOR_ATTACHMENT0,
640
- gl.NONE
641
- ])
642
-
643
- // blur ping pong
644
- gl.useProgram(_blurProgram.program);
645
- gl.bindVertexArray(_blurProgram.vao);
646
- for (let i = 0; i < _blurRepetition * 2; i++) {
647
- gl.bindFramebuffer(gl.FRAMEBUFFER, this._blurFrameBuffers[i % 2]);
648
- gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._blurTextures[(i + 1) % 2], 0);
649
- gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[i % 2]);
650
- gl.uniform1i(_blurProgram.u_texture, 0);
651
- gl.uniform1f(_blurProgram.u_horizontal, i % 2 === 0);
652
- gl.drawArrays(gl.TRIANGLES, 0, 6);
653
- }
654
-
655
- // combine
656
- gl.bindFramebuffer(gl.FRAMEBUFFER, null);
657
- gl.useProgram(this._combineProgram.program);
658
- gl.bindVertexArray(this._combineProgram.vao);
659
- gl.activeTexture(gl.TEXTURE1);
660
- gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[1]);
661
- gl.uniform1i(this._combineProgram.u_bloom_texture, 1);
662
- gl.activeTexture(gl.TEXTURE0);
663
- gl.bindTexture(gl.TEXTURE_2D, this._middleTexture);
664
- gl.uniform1i(this._combineProgram.u_main_texture, 0);
665
- gl.drawArrays(gl.TRIANGLES, 0, 6);
666
-
667
-
668
- gl.bindVertexArray(null);
669
- defaultblendfunction(gl)
670
-
671
- }
672
-
673
-
674
- free() {
675
- const { gl, _lineProgram, _blurProgram, _combineProgram } = this;
676
- gl.deleteBuffer(this._inBuffer);
677
- gl.deleteFramebuffer(this._frameBuffer);
678
- gl.deleteFramebuffer(this._blurFrameBuffers[0]);
679
- gl.deleteFramebuffer(this._blurFrameBuffers[1]);
680
- // gl.deleteBuffer(this._middleTexture);
681
- gl.deleteTexture(this._middleTexture);
682
- gl.deleteTexture(this._blurTextures[0]);
683
- gl.deleteTexture(this._blurTextures[1]);
684
- gl.deleteVertexArray(_lineProgram.vao);
685
- gl.deleteVertexArray(_blurProgram.vao);
686
- gl.deleteVertexArray(_combineProgram.vao);
687
- gl.deleteProgram(_lineProgram.program);
688
- gl.deleteProgram(_blurProgram.program);
689
- gl.deleteProgram(_combineProgram.program);
690
- }
691
- }
692
-
460
+ `;
461
+ const program = createProgram(this.gl, vertexShader, fragmentShader);
462
+ const a_position = gl.getAttribLocation(program, "a_position");
463
+ const a_time = gl.getAttribLocation(program, "a_time");
464
+ const a_track_start_time = gl.getAttribLocation(program, "a_track_start_time");
465
+ const a_track_end_time = gl.getAttribLocation(program, "a_track_end_time");
466
+ const a_color = gl.getAttribLocation(program, "a_color");
467
+ const vao = gl.createVertexArray();
468
+ gl.bindVertexArray(vao);
469
+ gl.bindBuffer(gl.ARRAY_BUFFER, this._inBuffer);
470
+ gl.enableVertexAttribArray(a_position);
471
+ gl.vertexAttribPointer(a_position, 3, gl.FLOAT, false, 36, 0);
472
+ gl.enableVertexAttribArray(a_time);
473
+ gl.vertexAttribPointer(a_time, 1, gl.FLOAT, false, 36, 12);
474
+ gl.enableVertexAttribArray(a_color);
475
+ gl.vertexAttribPointer(a_color, 3, gl.FLOAT, false, 36, 16);
476
+ gl.enableVertexAttribArray(a_track_start_time);
477
+ gl.vertexAttribPointer(a_track_start_time, 1, gl.FLOAT, false, 36, 28);
478
+ gl.enableVertexAttribArray(a_track_end_time);
479
+ gl.vertexAttribPointer(a_track_end_time, 1, gl.FLOAT, false, 36, 32);
480
+ gl.bindVertexArray(null);
481
+ return {
482
+ program: program,
483
+ vao: vao,
484
+ u_head_time: gl.getUniformLocation(program, "u_head_time"),
485
+ u_tail_time: gl.getUniformLocation(program, "u_tail_time"),
486
+ uTranslate: gl.getUniformLocation(program, "uTranslate"),
487
+ uModelViewMatrix: gl.getUniformLocation(program, "uModelViewMatrix"),
488
+ uProjectionMatrix: gl.getUniformLocation(program, "uProjectionMatrix"),
489
+ u_is_3d: gl.getUniformLocation(program, "u_is_3d"),
490
+ u_mapWH: gl.getUniformLocation(program, "u_mapWH"),
491
+ u_scrWH: gl.getUniformLocation(program, "u_scrWH"),
492
+ u_head_percentage: gl.getUniformLocation(program, "u_head_percentage"),
493
+ u_route_alpha: gl.getUniformLocation(program, "u_route_alpha"),
494
+ };
495
+ }
496
+ /**
497
+ * @param { Float32Array} data // [x, y, z, time, x, y, z, time, ...]
498
+ */
499
+ // setInBuffer(data) {
500
+ // const gl = this.gl;
501
+ // gl.bindBuffer(gl.ARRAY_BUFFER, this._inBuffer);
502
+ // gl.bufferData(gl.ARRAY_BUFFER, data, gl.STATIC_DRAW);
503
+ // }
504
+ setIs3D(is3d) {
505
+ const { gl, _lineProgram } = this;
506
+ const currentProgram = gl.getParameter(gl.CURRENT_PROGRAM);
507
+ gl.useProgram(_lineProgram.program);
508
+ gl.uniform1i(_lineProgram.u_is_3d, is3d);
509
+ gl.useProgram(currentProgram);
510
+ }
511
+ setTotalLength(totalLength) {
512
+ this._totalLength = totalLength;
513
+ }
514
+ _createTextures() {
515
+ const { gl, _width, _height } = this;
516
+ const texture = gl.createTexture();
517
+ gl.bindTexture(gl.TEXTURE_2D, texture);
518
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); // UNSIGNED_BYTE
519
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
520
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
521
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
522
+ gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
523
+ gl.bindTexture(gl.TEXTURE_2D, null);
524
+ return texture;
525
+ }
526
+ _resetTexture() {
527
+ const { gl, _width, _height } = this;
528
+ gl.bindTexture(gl.TEXTURE_2D, this._middleTexture); // UNSIGNED_BYTE
529
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
530
+ gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[0]);
531
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
532
+ gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[1]);
533
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, _width, _height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
534
+ gl.bindTexture(gl.TEXTURE_2D, null);
535
+ }
536
+ draw(u_head_time, u_tail_time, uProjectionMatrix, uModelViewMatrix, uTranslate, u_mapWH = null) {
537
+ const { gl, _lineProgram, _blurProgram, _blurRepetition } = this;
538
+ this._resetTexture();
539
+ gl.enable(gl.BLEND);
540
+ gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA);
541
+ // draw lines
542
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._frameBuffer);
543
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._middleTexture, 0);
544
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT1, gl.TEXTURE_2D, this._blurTextures[0], 0);
545
+ gl.drawBuffers([
546
+ gl.COLOR_ATTACHMENT0,
547
+ gl.COLOR_ATTACHMENT1,
548
+ ]);
549
+ gl.useProgram(_lineProgram.program);
550
+ gl.uniform1f(_lineProgram.u_head_time, u_head_time);
551
+ gl.uniform1f(_lineProgram.u_tail_time, u_tail_time);
552
+ gl.uniformMatrix4fv(_lineProgram.uProjectionMatrix, false, uProjectionMatrix);
553
+ if (u_mapWH) {
554
+ gl.uniform2fv(_lineProgram.u_mapWH, u_mapWH);
555
+ }
556
+ else {
557
+ gl.uniformMatrix4fv(_lineProgram.uModelViewMatrix, false, uModelViewMatrix);
558
+ }
559
+ gl.uniform3fv(_lineProgram.uTranslate, uTranslate);
560
+ gl.bindVertexArray(_lineProgram.vao);
561
+ gl.drawArrays(gl.LINE_STRIP, 0, this._totalLength);
562
+ gl.drawBuffers([
563
+ gl.COLOR_ATTACHMENT0,
564
+ gl.NONE
565
+ ]);
566
+ // blur ping pong
567
+ gl.useProgram(_blurProgram.program);
568
+ gl.bindVertexArray(_blurProgram.vao);
569
+ for (let i = 0; i < _blurRepetition * 2; i++) {
570
+ gl.bindFramebuffer(gl.FRAMEBUFFER, this._blurFrameBuffers[i % 2]);
571
+ gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, this._blurTextures[(i + 1) % 2], 0);
572
+ gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[i % 2]);
573
+ gl.uniform1i(_blurProgram.u_texture, 0);
574
+ gl.uniform1f(_blurProgram.u_horizontal, i % 2 === 0);
575
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
576
+ }
577
+ // combine
578
+ gl.bindFramebuffer(gl.FRAMEBUFFER, null);
579
+ gl.useProgram(this._combineProgram.program);
580
+ gl.bindVertexArray(this._combineProgram.vao);
581
+ gl.activeTexture(gl.TEXTURE1);
582
+ gl.bindTexture(gl.TEXTURE_2D, this._blurTextures[1]);
583
+ gl.uniform1i(this._combineProgram.u_bloom_texture, 1);
584
+ gl.activeTexture(gl.TEXTURE0);
585
+ gl.bindTexture(gl.TEXTURE_2D, this._middleTexture);
586
+ gl.uniform1i(this._combineProgram.u_main_texture, 0);
587
+ gl.drawArrays(gl.TRIANGLES, 0, 6);
588
+ gl.bindVertexArray(null);
589
+ defaultblendfunction(gl);
590
+ }
591
+ free() {
592
+ const { gl, _lineProgram, _blurProgram, _combineProgram } = this;
593
+ gl.deleteBuffer(this._inBuffer);
594
+ gl.deleteFramebuffer(this._frameBuffer);
595
+ gl.deleteFramebuffer(this._blurFrameBuffers[0]);
596
+ gl.deleteFramebuffer(this._blurFrameBuffers[1]);
597
+ // gl.deleteBuffer(this._middleTexture);
598
+ gl.deleteTexture(this._middleTexture);
599
+ gl.deleteTexture(this._blurTextures[0]);
600
+ gl.deleteTexture(this._blurTextures[1]);
601
+ gl.deleteVertexArray(_lineProgram.vao);
602
+ gl.deleteVertexArray(_blurProgram.vao);
603
+ gl.deleteVertexArray(_combineProgram.vao);
604
+ gl.deleteProgram(_lineProgram.program);
605
+ gl.deleteProgram(_blurProgram.program);
606
+ gl.deleteProgram(_combineProgram.program);
607
+ }
608
+ }