@pirireis/webglobeplugins 0.9.7 → 0.9.8
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/dist/Math/angle-calculation.js +15 -0
- package/dist/Math/arc.js +65 -0
- package/dist/Math/bounds/line-bbox.js +188 -0
- package/dist/Math/constants.js +9 -0
- package/dist/Math/frustum/camera.js +24 -0
- package/dist/Math/frustum/from-globeinfo.js +48 -0
- package/dist/Math/frustum/types.js +2 -0
- package/dist/Math/globe-util/horizon-plane.js +112 -0
- package/dist/Math/index.js +1 -0
- package/dist/Math/juction/arc-plane.js +83 -0
- package/dist/Math/juction/line-sphere.js +25 -0
- package/dist/Math/juction/plane-plane.js +58 -0
- package/dist/Math/line.js +56 -0
- package/dist/Math/matrix4.js +1 -0
- package/dist/Math/methods.js +201 -0
- package/dist/Math/plane.js +60 -0
- package/dist/Math/quaternion.js +104 -0
- package/dist/Math/types.js +2 -0
- package/dist/Math/utils.js +4 -0
- package/dist/Math/vec3.js +126 -0
- package/dist/algorithms/search-binary.js +19 -0
- package/dist/altitude-locator/adaptors.js +1 -0
- package/dist/altitude-locator/draw-subset-obj.js +18 -0
- package/dist/altitude-locator/keymethod.js +1 -0
- package/dist/altitude-locator/plugin.js +341 -0
- package/dist/altitude-locator/types.js +23 -0
- package/dist/arrowfield/adaptor.js +14 -0
- package/dist/arrowfield/index.js +10 -0
- package/dist/arrowfield/plugin.js +86 -0
- package/dist/bearing-line/index.js +8 -0
- package/dist/bearing-line/plugin.js +449 -0
- package/dist/circle-line-chain/chain-list-map.js +205 -0
- package/dist/circle-line-chain/init.js +1 -0
- package/dist/circle-line-chain/plugin.js +424 -0
- package/dist/circle-line-chain/util.js +5 -0
- package/dist/compass-rose/compass-rose-padding-flat.js +225 -0
- package/dist/compass-rose/compass-text-writer.js +153 -0
- package/dist/compass-rose/index.js +7 -0
- package/dist/compassrose/compassrose.js +296 -0
- package/dist/compassrose/index.js +8 -0
- package/dist/globe-types.js +1 -0
- package/dist/heatwave/index.js +10 -0
- package/dist/heatwave/isobar/objectarraylabels.js +202 -0
- package/dist/heatwave/isobar/plugin.js +343 -0
- package/dist/heatwave/isobar/quadtreecontours.js +300 -0
- package/dist/heatwave/plugins/heatwaveglobeshell.js +206 -0
- package/dist/index.js +58 -0
- package/dist/jest.config.js +7 -0
- package/dist/partialrings/buffer-manager.js +81 -0
- package/dist/partialrings/index.js +41 -0
- package/dist/partialrings/plugin.js +135 -0
- package/dist/partialrings/program.js +286 -0
- package/dist/pin/pin-object-array.js +305 -0
- package/dist/pin/pin-point-totem.js +60 -0
- package/dist/point-heat-map/adaptors/timetracksplugin-format-to-this.js +66 -0
- package/dist/point-heat-map/index.js +1 -0
- package/dist/point-heat-map/plugin-webworker.js +126 -0
- package/dist/point-heat-map/point-to-heat-map-flow.js +127 -0
- package/dist/point-tracks/key-methods.js +5 -0
- package/dist/point-tracks/plugin.js +338 -0
- package/dist/programs/arrowfield/index.js +7 -0
- package/dist/programs/arrowfield/logic.js +257 -0
- package/dist/programs/arrowfield/object.js +66 -0
- package/dist/programs/data2legend/density-to-legend.js +101 -0
- package/dist/programs/data2legend/point-to-density-texture.js +100 -0
- package/dist/programs/float2legendwithratio/index.js +8 -0
- package/dist/programs/float2legendwithratio/logic.js +171 -0
- package/dist/programs/float2legendwithratio/object.js +110 -0
- package/dist/programs/globe-util/is-globe-moved.js +21 -0
- package/dist/programs/globeshell/index.js +8 -0
- package/dist/programs/globeshell/noise/noises.js +1 -0
- package/dist/programs/globeshell/wiggle/index.js +8 -0
- package/dist/programs/globeshell/wiggle/logic.js +345 -0
- package/dist/programs/globeshell/wiggle/object.js +72 -0
- package/dist/programs/helpers/blender/index.js +1 -0
- package/dist/programs/helpers/blender/program.js +79 -0
- package/dist/programs/helpers/fadeaway/index.js +7 -0
- package/dist/programs/helpers/fadeaway/logic.js +72 -0
- package/dist/programs/helpers/fadeaway/object.js +20 -0
- package/dist/programs/helpers/index.js +8 -0
- package/dist/programs/index.js +58 -0
- package/dist/programs/interface.js +1 -0
- package/dist/programs/line-on-globe/angled-line.js +176 -0
- package/dist/programs/line-on-globe/circle-accurate-3d.js +141 -0
- package/dist/programs/line-on-globe/circle-accurate-flat.js +216 -0
- package/dist/programs/line-on-globe/circle-accurate.js +178 -0
- package/dist/programs/line-on-globe/circle.js +167 -0
- package/dist/programs/line-on-globe/degree-padding-around-circle-3d.js +159 -0
- package/dist/programs/line-on-globe/index.js +1 -0
- package/dist/programs/line-on-globe/lines-color-instanced-flat.js +136 -0
- package/dist/programs/line-on-globe/linestrip.js +171 -0
- package/dist/programs/line-on-globe/naive-accurate-flexible.js +195 -0
- package/dist/programs/line-on-globe/to-the-surface.js +111 -0
- package/dist/programs/line-on-globe/util.js +8 -0
- package/dist/programs/picking/pickable-renderer.js +188 -0
- package/dist/programs/point-on-globe/element-globe-surface-glow.js +142 -0
- package/dist/programs/point-on-globe/element-point-glow.js +153 -0
- package/dist/programs/point-on-globe/square-pixel-point.js +174 -0
- package/dist/programs/programcache.js +131 -0
- package/dist/programs/rings/distancering/circleflatprogram.js +156 -0
- package/dist/programs/rings/distancering/circlepaddingfreeangleprogram.js +369 -0
- package/dist/programs/rings/distancering/circlepaddysharedbuffer.js +357 -0
- package/dist/programs/rings/distancering/index.js +14 -0
- package/dist/programs/rings/distancering/paddyflatprogram.js +172 -0
- package/dist/programs/rings/distancering/paddyflatprogram2d.js +174 -0
- package/dist/programs/rings/distancering/paddyflatprogram3d.js +172 -0
- package/dist/programs/rings/distancering/shader.js +1 -0
- package/dist/programs/rings/index.js +17 -0
- package/dist/programs/rings/partial-ring/piece-of-pie.js +275 -0
- package/dist/programs/totems/camerauniformblock.js +160 -0
- package/dist/programs/totems/canvas-webglobe-info.js +110 -0
- package/dist/programs/totems/gpu-selection-uniform-block.js +108 -0
- package/dist/programs/totems/index.js +40 -0
- package/dist/programs/two-d/pixel-circle.js +1 -0
- package/dist/programs/two-d/pixel-padding-for-compass.js +162 -0
- package/dist/programs/util.js +17 -0
- package/dist/programs/vectorfields/index.js +23 -0
- package/dist/programs/vectorfields/logics/drawrectangleparticles.js +107 -0
- package/dist/programs/vectorfields/logics/index.js +12 -0
- package/dist/programs/vectorfields/logics/pixelbased.js +142 -0
- package/dist/programs/vectorfields/logics/ubo.js +63 -0
- package/dist/programs/vectorfields/pingpongbuffermanager.js +76 -0
- package/dist/rangerings/enum.js +5 -0
- package/dist/rangerings/index.js +15 -0
- package/dist/rangerings/plugin.js +560 -0
- package/dist/rangerings/rangeringangletext.js +329 -0
- package/dist/rangerings/ring-account.js +117 -0
- package/dist/shaders/fragment-toy/firework.js +58 -0
- package/dist/shaders/fragment-toy/singularity.js +59 -0
- package/dist/shape-on-terrain/arc/naive/plugin.js +252 -0
- package/dist/timetracks/adaptors-line-strip.js +71 -0
- package/dist/timetracks/adaptors.js +122 -0
- package/dist/timetracks/index.js +19 -0
- package/dist/timetracks/plugin-line-strip.js +250 -0
- package/dist/timetracks/plugin.js +258 -0
- package/dist/timetracks/program-line-strip.js +611 -0
- package/dist/timetracks/program.js +772 -0
- package/dist/timetracks/programpoint-line-strip.js +154 -0
- package/dist/timetracks/programpoint.js +147 -0
- package/dist/types.js +15 -0
- package/dist/util/account/bufferoffsetmanager.js +179 -0
- package/dist/util/account/index.js +23 -0
- package/dist/util/account/single-attribute-buffer-management/buffer-manager.js +108 -0
- package/dist/util/account/single-attribute-buffer-management/buffer-orchestrator.js +150 -0
- package/dist/util/account/single-attribute-buffer-management/index.js +9 -0
- package/dist/util/account/single-attribute-buffer-management/object-store.js +51 -0
- package/dist/util/account/single-attribute-buffer-management/types.js +2 -0
- package/dist/util/account/util.js +22 -0
- package/dist/util/algorithms/index.js +1 -0
- package/dist/util/algorithms/search-binary.js +28 -0
- package/dist/util/check/get.js +18 -0
- package/dist/util/check/index.js +1 -0
- package/dist/util/check/typecheck.js +49 -0
- package/dist/util/geometry/index.js +51 -0
- package/dist/util/gl-util/buffer/attribute-loader.js +69 -0
- package/dist/util/gl-util/buffer/index.js +6 -0
- package/dist/util/gl-util/buffer/types.js +1 -0
- package/dist/util/gl-util/draw-options/methods.js +38 -0
- package/dist/util/gl-util/draw-options/types.js +15 -0
- package/dist/util/gl-util/uniform-block/manager.js +156 -0
- package/dist/util/gl-util/uniform-block/shader.js +1 -0
- package/dist/util/gl-util/uniform-block/types.js +8 -0
- package/dist/util/heatwavedatamanager/datamanager.js +152 -0
- package/dist/util/heatwavedatamanager/index.js +10 -0
- package/dist/util/heatwavedatamanager/pointcoordinatesdatacalculator.js +122 -0
- package/dist/util/heatwavedatamanager/pointcoordsmeta.js +20 -0
- package/dist/util/index.js +57 -0
- package/dist/util/interpolation/index.js +1 -0
- package/dist/util/interpolation/timetrack/index.js +5 -0
- package/dist/util/interpolation/timetrack/timetrack-interpolator.js +79 -0
- package/dist/util/interpolation/timetrack/web-worker-str.js +183 -0
- package/dist/util/interpolation/timetrack/web-worker.js +48 -0
- package/dist/util/jshelpers/data-filler.js +20 -0
- package/dist/util/jshelpers/equality.js +20 -0
- package/dist/util/jshelpers/index.js +37 -0
- package/dist/util/jshelpers/timefilters.js +32 -0
- package/dist/util/picking/fence.js +46 -0
- package/dist/util/picking/picker-displayer.js +139 -0
- package/dist/util/programs/draw-texture-on-canvas.js +89 -0
- package/dist/util/programs/index.js +17 -0
- package/dist/util/programs/shapesonglobe.js +214 -0
- package/dist/util/programs/supersampletotextures.js +113 -0
- package/dist/util/programs/texturetoglobe.js +182 -0
- package/dist/util/shaderfunctions/geometrytransformations.js +340 -0
- package/dist/util/shaderfunctions/index.js +18 -0
- package/dist/util/shaderfunctions/nodata.js +11 -0
- package/dist/util/shaderfunctions/noisefunctions.js +43 -0
- package/dist/util/surface-line-data/arc-bboxes.js +25 -0
- package/dist/util/surface-line-data/arcs-to-cuts.js +50 -0
- package/dist/util/surface-line-data/cut-arc.js +1 -0
- package/dist/util/surface-line-data/flow.js +28 -0
- package/dist/util/surface-line-data/rbush-manager.js +1 -0
- package/dist/util/surface-line-data/types.js +1 -0
- package/dist/util/surface-line-data/web-worker.js +1 -0
- package/dist/util/webglobe/gldefaultstates.js +7 -0
- package/dist/util/webglobe/index.js +18 -0
- package/dist/util/webglobe/rasteroverlay.js +78 -0
- package/dist/util/webglobjectbuilders.js +388 -0
- package/dist/util/webglobjectbuilders1.js +237 -0
- package/dist/waveparticles/adaptor.js +17 -0
- package/dist/waveparticles/index.js +10 -0
- package/dist/waveparticles/plugin.js +266 -0
- package/dist/wind/imagetovectorfieldandmagnitude.js +35 -0
- package/dist/wind/index.js +14 -0
- package/dist/wind/plugin.js +926 -0
- package/dist/wind/vectorfieldimage.js +25 -0
- package/dist/write-text/attached-text-writer.js +91 -0
- package/dist/write-text/context-text.js +98 -0
- package/dist/write-text/context-text3.js +155 -0
- package/dist/write-text/index.js +5 -0
- package/dist/write-text/writer-plugin.js +8 -0
- package/package.json +1 -1
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("../util");
|
|
4
|
+
const programs_1 = require("../programs");
|
|
5
|
+
const vertexShader = `#version 300 es
|
|
6
|
+
|
|
7
|
+
layout(std140) uniform GlobeCamera {
|
|
8
|
+
mat4 view; // 64 bytes 0
|
|
9
|
+
mat4 projection; // 64 bytes 64
|
|
10
|
+
vec3 translate; // 12 bytes 128
|
|
11
|
+
bool is3D; // 4 bytes 140
|
|
12
|
+
vec2 mapWH; // 8 bytes 144
|
|
13
|
+
vec2 screenWH; // 8 bytes 152
|
|
14
|
+
float z_level; // 4 bytes 160
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
layout(std140) uniform Globals {
|
|
18
|
+
float head_time;
|
|
19
|
+
float final_opacity;
|
|
20
|
+
float point_size;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
in vec3 start_position;
|
|
24
|
+
in float start_time;
|
|
25
|
+
in vec3 start_color;
|
|
26
|
+
in vec3 end_position;
|
|
27
|
+
in float end_time;
|
|
28
|
+
in vec3 end_color;
|
|
29
|
+
out vec4 v_color;
|
|
30
|
+
|
|
31
|
+
` + util_1.shaderfunctions.pixelXYToCartesian3DPoint + util_1.shaderfunctions.pixelXYToCartesian2DPoint + `
|
|
32
|
+
|
|
33
|
+
void main() {
|
|
34
|
+
if (head_time < start_time || head_time > end_time) { return; }
|
|
35
|
+
if ( start_color.r < 0.0 || end_color.r < 0.0) { return; }
|
|
36
|
+
float t = (head_time - start_time) / (end_time - start_time);
|
|
37
|
+
vec3 position = mix(start_position, end_position, t);
|
|
38
|
+
if (is3D){
|
|
39
|
+
vec3 pos = pixelXYToCartesian3DPoint(position);
|
|
40
|
+
gl_Position = projection * view * vec4(pos - translate, 1.0);
|
|
41
|
+
} else {
|
|
42
|
+
vec2 xy = pixelXYToCartesian2DPoint(position.xy, translate.xy, mapWH, screenWH);
|
|
43
|
+
gl_Position = projection * vec4(xy.x, xy.y, 0.0, 1.0);
|
|
44
|
+
}
|
|
45
|
+
v_color = vec4(mix(start_color, end_color, t), final_opacity);
|
|
46
|
+
gl_PointSize = point_size;
|
|
47
|
+
}`;
|
|
48
|
+
const fragmentShader = `#version 300 es
|
|
49
|
+
precision highp float;
|
|
50
|
+
in vec4 v_color;
|
|
51
|
+
out vec4 outColor;
|
|
52
|
+
void main() {
|
|
53
|
+
// circle point
|
|
54
|
+
vec2 cxy = 2.0 * gl_PointCoord - 1.0;
|
|
55
|
+
float cc = dot(cxy, cxy);
|
|
56
|
+
outColor = v_color;
|
|
57
|
+
if (cc > 0.5) {
|
|
58
|
+
outColor.a = 0.0;
|
|
59
|
+
}
|
|
60
|
+
}`;
|
|
61
|
+
class default_1 {
|
|
62
|
+
constructor(gl, globe, attrBuffer, options) {
|
|
63
|
+
this.gl = gl;
|
|
64
|
+
this._cameraBlockBindingPoint = 0;
|
|
65
|
+
this._globalsBlockBindingPoint = 1;
|
|
66
|
+
this.cameraUniformBlockTotem = programs_1.globeProgramCache.getProgram(globe, programs_1.CameraUniformBlockTotem);
|
|
67
|
+
this._vao = gl.createVertexArray();
|
|
68
|
+
this._attbuffer = attrBuffer;
|
|
69
|
+
this.program = this._createProgram();
|
|
70
|
+
this._drawCount = 0;
|
|
71
|
+
this._globalsbuffer = gl.createBuffer();
|
|
72
|
+
{
|
|
73
|
+
const { gl, _globalsbuffer } = this;
|
|
74
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
75
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 12, gl.STREAM_DRAW);
|
|
76
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([0, options.opacity, options.pointSize]));
|
|
77
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, _globalsbuffer);
|
|
78
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
_createProgram() {
|
|
82
|
+
const gl = this.gl;
|
|
83
|
+
const program = (0, util_1.createProgram)(gl, vertexShader, fragmentShader);
|
|
84
|
+
const ubo = this.cameraUniformBlockTotem.getUBO(); // ubo bl
|
|
85
|
+
const cameraBlockIndex = gl.getUniformBlockIndex(program, "GlobeCamera");
|
|
86
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this._cameraBlockBindingPoint);
|
|
87
|
+
const globalsBlockIndex = gl.getUniformBlockIndex(program, "Globals");
|
|
88
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._cameraBlockBindingPoint, ubo);
|
|
89
|
+
gl.uniformBlockBinding(program, globalsBlockIndex, this._globalsBlockBindingPoint);
|
|
90
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, this._globalsbuffer);
|
|
91
|
+
// numaralarda yanlışlık olabilir
|
|
92
|
+
const start_position = gl.getAttribLocation(program, "start_position");
|
|
93
|
+
const start_time = gl.getAttribLocation(program, "start_time");
|
|
94
|
+
const start_color = gl.getAttribLocation(program, "start_color");
|
|
95
|
+
const end_position = gl.getAttribLocation(program, "end_position");
|
|
96
|
+
const end_time = gl.getAttribLocation(program, "end_time");
|
|
97
|
+
const end_color = gl.getAttribLocation(program, "end_color");
|
|
98
|
+
gl.bindVertexArray(this._vao);
|
|
99
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._attbuffer);
|
|
100
|
+
gl.enableVertexAttribArray(start_position);
|
|
101
|
+
gl.vertexAttribPointer(start_position, 3, gl.FLOAT, false, 36, 0);
|
|
102
|
+
gl.enableVertexAttribArray(start_time);
|
|
103
|
+
gl.vertexAttribPointer(start_time, 1, gl.FLOAT, false, 36, 12);
|
|
104
|
+
gl.enableVertexAttribArray(start_color);
|
|
105
|
+
gl.vertexAttribPointer(start_color, 3, gl.FLOAT, false, 36, 16);
|
|
106
|
+
gl.enableVertexAttribArray(end_position);
|
|
107
|
+
gl.vertexAttribPointer(end_position, 3, gl.FLOAT, false, 36, 36);
|
|
108
|
+
gl.enableVertexAttribArray(end_time);
|
|
109
|
+
gl.vertexAttribPointer(end_time, 1, gl.FLOAT, false, 36, 48);
|
|
110
|
+
gl.enableVertexAttribArray(end_color);
|
|
111
|
+
gl.vertexAttribPointer(end_color, 3, gl.FLOAT, false, 36, 52);
|
|
112
|
+
gl.bindVertexArray(null);
|
|
113
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
114
|
+
return program;
|
|
115
|
+
}
|
|
116
|
+
setOpacity(opacity) {
|
|
117
|
+
const { gl, _globalsbuffer } = this;
|
|
118
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
119
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 4, new Float32Array([opacity]));
|
|
120
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
121
|
+
}
|
|
122
|
+
setDrawCount(count) {
|
|
123
|
+
this._drawCount = count;
|
|
124
|
+
}
|
|
125
|
+
setPointSize(size) {
|
|
126
|
+
const { gl, _globalsbuffer } = this;
|
|
127
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
128
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 8, new Float32Array([size]));
|
|
129
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
130
|
+
}
|
|
131
|
+
setHeadTime(time) {
|
|
132
|
+
const { gl, _globalsbuffer } = this;
|
|
133
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
134
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([time]));
|
|
135
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
136
|
+
}
|
|
137
|
+
draw() {
|
|
138
|
+
const { gl, program, _vao, _drawCount } = this;
|
|
139
|
+
gl.useProgram(program);
|
|
140
|
+
gl.bindVertexArray(_vao);
|
|
141
|
+
gl.disable(gl.DEPTH_TEST);
|
|
142
|
+
gl.drawArrays(gl.POINTS, 0, _drawCount);
|
|
143
|
+
gl.enable(gl.DEPTH_TEST);
|
|
144
|
+
gl.bindVertexArray(null);
|
|
145
|
+
}
|
|
146
|
+
free() {
|
|
147
|
+
const { gl, _vao, _globalsbuffer, program } = this;
|
|
148
|
+
gl.deleteVertexArray(_vao);
|
|
149
|
+
// gl.deleteBuffer(_attbuffer);
|
|
150
|
+
gl.deleteBuffer(_globalsbuffer);
|
|
151
|
+
gl.deleteProgram(program);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const util_1 = require("../util");
|
|
4
|
+
const programs_1 = require("../programs");
|
|
5
|
+
const vertexShader = `#version 300 es
|
|
6
|
+
|
|
7
|
+
layout(std140) uniform GlobeCamera {
|
|
8
|
+
mat4 view; // 64 bytes 0
|
|
9
|
+
mat4 projection; // 64 bytes 64
|
|
10
|
+
vec3 translate; // 12 bytes 128
|
|
11
|
+
bool is3D; // 4 bytes 140
|
|
12
|
+
vec2 mapWH; // 8 bytes 144
|
|
13
|
+
vec2 screenWH; // 8 bytes 152
|
|
14
|
+
float z_level; // 4 bytes 160
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
layout(std140) uniform Globals {
|
|
18
|
+
float head_time;
|
|
19
|
+
float final_opacity;
|
|
20
|
+
float point_size;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
in vec3 start_position;
|
|
24
|
+
in float start_time;
|
|
25
|
+
in vec3 start_color;
|
|
26
|
+
in vec3 end_position;
|
|
27
|
+
in float end_time;
|
|
28
|
+
in vec3 end_color;
|
|
29
|
+
out vec4 v_color;
|
|
30
|
+
|
|
31
|
+
` + util_1.shaderfunctions.pixelXYToCartesian3DPoint + util_1.shaderfunctions.pixelXYToCartesian2DPoint + `
|
|
32
|
+
|
|
33
|
+
void main() {
|
|
34
|
+
if (head_time < start_time || head_time > end_time) { return; }
|
|
35
|
+
float t = (head_time - start_time) / (end_time - start_time);
|
|
36
|
+
vec3 position = mix(start_position, end_position, t);
|
|
37
|
+
if (is3D){
|
|
38
|
+
vec3 pos = pixelXYToCartesian3DPoint(position);
|
|
39
|
+
gl_Position = projection * view * vec4(pos - translate, 1.0);
|
|
40
|
+
} else {
|
|
41
|
+
vec2 xy = pixelXYToCartesian2DPoint(position.xy, translate.xy, mapWH, screenWH);
|
|
42
|
+
gl_Position = projection * vec4(xy.x, xy.y, 0.0, 1.0);
|
|
43
|
+
}
|
|
44
|
+
v_color = vec4(mix(start_color, end_color, t), final_opacity);
|
|
45
|
+
gl_PointSize = point_size;
|
|
46
|
+
}`;
|
|
47
|
+
const fragmentShader = `#version 300 es
|
|
48
|
+
precision highp float;
|
|
49
|
+
in vec4 v_color;
|
|
50
|
+
out vec4 outColor;
|
|
51
|
+
void main() {
|
|
52
|
+
outColor = v_color;
|
|
53
|
+
}`;
|
|
54
|
+
class default_1 {
|
|
55
|
+
constructor(gl, globe, attrBuffer, options) {
|
|
56
|
+
this.gl = gl;
|
|
57
|
+
this._cameraBlockBindingPoint = 0;
|
|
58
|
+
this._globalsBlockBindingPoint = 1;
|
|
59
|
+
this.cameraUniformBlockTotem = programs_1.globeProgramCache.getProgram(globe, programs_1.CameraUniformBlockTotem);
|
|
60
|
+
this._vao = gl.createVertexArray();
|
|
61
|
+
this._attbuffer = attrBuffer;
|
|
62
|
+
this.program = this._createProgram();
|
|
63
|
+
this._drawCount = 0;
|
|
64
|
+
this._globalsbuffer = gl.createBuffer();
|
|
65
|
+
{
|
|
66
|
+
const { gl, _globalsbuffer } = this;
|
|
67
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
68
|
+
gl.bufferData(gl.UNIFORM_BUFFER, 12, gl.STREAM_DRAW);
|
|
69
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([0, options.opacity, options.pointSize]));
|
|
70
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, _globalsbuffer);
|
|
71
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
_createProgram() {
|
|
75
|
+
const gl = this.gl;
|
|
76
|
+
const program = (0, util_1.createProgram)(gl, vertexShader, fragmentShader);
|
|
77
|
+
const ubo = this.cameraUniformBlockTotem.getUBO(); // ubo bl
|
|
78
|
+
const cameraBlockIndex = gl.getUniformBlockIndex(program, "GlobeCamera");
|
|
79
|
+
gl.uniformBlockBinding(program, cameraBlockIndex, this._cameraBlockBindingPoint);
|
|
80
|
+
const globalsBlockIndex = gl.getUniformBlockIndex(program, "Globals");
|
|
81
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._cameraBlockBindingPoint, ubo);
|
|
82
|
+
gl.uniformBlockBinding(program, globalsBlockIndex, this._globalsBlockBindingPoint);
|
|
83
|
+
gl.bindBufferBase(gl.UNIFORM_BUFFER, this._globalsBlockBindingPoint, this._globalsbuffer);
|
|
84
|
+
// numaralarda yanlışlık olabilir
|
|
85
|
+
const start_position = gl.getAttribLocation(program, "start_position");
|
|
86
|
+
const start_time = gl.getAttribLocation(program, "start_time");
|
|
87
|
+
const start_color = gl.getAttribLocation(program, "start_color");
|
|
88
|
+
const end_position = gl.getAttribLocation(program, "end_position");
|
|
89
|
+
const end_time = gl.getAttribLocation(program, "end_time");
|
|
90
|
+
const end_color = gl.getAttribLocation(program, "end_color");
|
|
91
|
+
gl.bindVertexArray(this._vao);
|
|
92
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, this._attbuffer);
|
|
93
|
+
gl.enableVertexAttribArray(start_position);
|
|
94
|
+
gl.vertexAttribPointer(start_position, 3, gl.FLOAT, false, 72, 0);
|
|
95
|
+
gl.enableVertexAttribArray(start_time);
|
|
96
|
+
gl.vertexAttribPointer(start_time, 1, gl.FLOAT, false, 72, 12);
|
|
97
|
+
gl.enableVertexAttribArray(start_color);
|
|
98
|
+
gl.vertexAttribPointer(start_color, 3, gl.FLOAT, false, 72, 16);
|
|
99
|
+
gl.enableVertexAttribArray(end_position);
|
|
100
|
+
gl.vertexAttribPointer(end_position, 3, gl.FLOAT, false, 72, 36);
|
|
101
|
+
gl.enableVertexAttribArray(end_time);
|
|
102
|
+
gl.vertexAttribPointer(end_time, 1, gl.FLOAT, false, 72, 48);
|
|
103
|
+
gl.enableVertexAttribArray(end_color);
|
|
104
|
+
gl.vertexAttribPointer(end_color, 3, gl.FLOAT, false, 72, 52);
|
|
105
|
+
gl.bindVertexArray(null);
|
|
106
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
107
|
+
return program;
|
|
108
|
+
}
|
|
109
|
+
setOpacity(opacity) {
|
|
110
|
+
const { gl, _globalsbuffer } = this;
|
|
111
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
112
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 4, new Float32Array([opacity]));
|
|
113
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
114
|
+
}
|
|
115
|
+
setDrawCount(count) {
|
|
116
|
+
this._drawCount = count;
|
|
117
|
+
}
|
|
118
|
+
setPointSize(size) {
|
|
119
|
+
const { gl, _globalsbuffer } = this;
|
|
120
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
121
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 8, new Float32Array([size]));
|
|
122
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
123
|
+
}
|
|
124
|
+
setHeadTime(time) {
|
|
125
|
+
const { gl, _globalsbuffer } = this;
|
|
126
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, _globalsbuffer);
|
|
127
|
+
gl.bufferSubData(gl.UNIFORM_BUFFER, 0, new Float32Array([time]));
|
|
128
|
+
gl.bindBuffer(gl.UNIFORM_BUFFER, null);
|
|
129
|
+
}
|
|
130
|
+
draw() {
|
|
131
|
+
const { gl, program, _vao, _drawCount } = this;
|
|
132
|
+
gl.useProgram(program);
|
|
133
|
+
gl.bindVertexArray(_vao);
|
|
134
|
+
gl.disable(gl.DEPTH_TEST);
|
|
135
|
+
gl.drawArrays(gl.POINTS, 0, _drawCount);
|
|
136
|
+
gl.enable(gl.DEPTH_TEST);
|
|
137
|
+
gl.bindVertexArray(null);
|
|
138
|
+
}
|
|
139
|
+
free() {
|
|
140
|
+
const { gl, _vao, _globalsbuffer, program } = this;
|
|
141
|
+
gl.deleteVertexArray(_vao);
|
|
142
|
+
// gl.deleteBuffer(_attbuffer);
|
|
143
|
+
gl.deleteBuffer(_globalsbuffer);
|
|
144
|
+
gl.deleteProgram(program);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.default = default_1;
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @typedef DrawRange
|
|
4
|
+
* @type {Object}
|
|
5
|
+
* @property {int} first
|
|
6
|
+
* @property {int} count
|
|
7
|
+
*
|
|
8
|
+
* @typedef DrawRangeIndexParamsClient
|
|
9
|
+
* @type {Object}
|
|
10
|
+
* @property {null|DrawRange} drawRange
|
|
11
|
+
* @property {null|Int32List} indexes
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* * @typedef {Array<number>} Color rgba color 0-1 values
|
|
15
|
+
*/
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BufferOffsetManager
|
|
4
|
+
* Purpose: To manage the offset of the buffer. Plus extend and defrag the buffer.
|
|
5
|
+
* -------------------------------------------------------------------------------------------------------------------------------------------
|
|
6
|
+
* Functions:
|
|
7
|
+
* 1. getOffet(key) : return the offset of the key if not found return false.
|
|
8
|
+
* 2. setOffset(key, offset) : set the offset of the key.
|
|
9
|
+
* 3. nextOffset() : return the next available offset if not return false.
|
|
10
|
+
* 4. delete(key) : delete the key and return true if not found return false.
|
|
11
|
+
* 5. defragBuffer(gl, buffer, bufferType, newCapacity = null) : defrag the buffer. if newCapacity is not provided the buffer is vacumed.
|
|
12
|
+
* 6. extendBuffer(gl, buffer, bufferType, newCapacity) : extend the buffer.
|
|
13
|
+
* -------------------------------------------------------------------------------------------------------------------------------------------
|
|
14
|
+
* What this class does NOT do:
|
|
15
|
+
* ADD, DELETE, READ
|
|
16
|
+
* ADD, inputs needs to be turn into a block and put into buffer. Bulk will be more performant.
|
|
17
|
+
* DELETE, might be a set to single byte to indicate the tombstone.
|
|
18
|
+
* READ, most of the time is not needed to be read, unless for defraging.
|
|
19
|
+
* This unpredicatable behavior is not handled by this class.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
class default_1 {
|
|
23
|
+
constructor(itemSize, { capacity = 10, bufferType = "STATIC_DRAW" } = {}) {
|
|
24
|
+
this.itemSize = itemSize;
|
|
25
|
+
this.bufferType = bufferType;
|
|
26
|
+
this.offSetMap = new Map();
|
|
27
|
+
this.tombstoneOffSet = [];
|
|
28
|
+
this._capacity = capacity;
|
|
29
|
+
this._length = 0;
|
|
30
|
+
}
|
|
31
|
+
get length() {
|
|
32
|
+
return this._length;
|
|
33
|
+
}
|
|
34
|
+
get capacity() {
|
|
35
|
+
return this._capacity;
|
|
36
|
+
}
|
|
37
|
+
getOffset(key) {
|
|
38
|
+
return this.offSetMap.get(key);
|
|
39
|
+
}
|
|
40
|
+
setOffset(key, offset) {
|
|
41
|
+
this.offSetMap.set(key, offset);
|
|
42
|
+
}
|
|
43
|
+
nextOffset() {
|
|
44
|
+
if (this.tombstoneOffSet.length > 0) {
|
|
45
|
+
const offset = this.tombstoneOffSet.pop();
|
|
46
|
+
return offset;
|
|
47
|
+
}
|
|
48
|
+
if (this._length < this._capacity) {
|
|
49
|
+
return this._length++ * this.itemSize * 4;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
get spaceLeft() {
|
|
54
|
+
return this._capacity - (this._length - this.tombstoneOffSet.length);
|
|
55
|
+
}
|
|
56
|
+
get itemCount() {
|
|
57
|
+
return this._length - this.tombstoneOffSet.length;
|
|
58
|
+
}
|
|
59
|
+
deleteFromAccount(key) {
|
|
60
|
+
const offSet = this.offSetMap.get(key);
|
|
61
|
+
if (offSet !== undefined) {
|
|
62
|
+
this.tombstoneOffSet.push(offSet);
|
|
63
|
+
this.offSetMap.delete(key);
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
_deleteBulk(keys) {
|
|
71
|
+
const { gl, buffer } = this;
|
|
72
|
+
const emptyBlock = new Float32Array(this.itemSize).fill(0);
|
|
73
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
74
|
+
for (let key of keys) {
|
|
75
|
+
const offset = this.getOffset(key);
|
|
76
|
+
if (offset !== undefined) {
|
|
77
|
+
this.deleteFromAccount(key);
|
|
78
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, emptyBlock);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
82
|
+
}
|
|
83
|
+
offsetMapIterator() {
|
|
84
|
+
return this.offSetMap.entries();
|
|
85
|
+
}
|
|
86
|
+
// TODO: this is broken
|
|
87
|
+
defrag(newCapacity = null) {
|
|
88
|
+
const { gl, buffer, bufferType } = this;
|
|
89
|
+
if (gl === undefined || buffer === undefined || bufferType === undefined) {
|
|
90
|
+
throw new Error("gl, buffer, bufferType are required");
|
|
91
|
+
}
|
|
92
|
+
const itemSize = this.itemSize;
|
|
93
|
+
const itemCount = this.itemCount;
|
|
94
|
+
const capacity = (newCapacity && newCapacity > itemCount) ? newCapacity : itemCount;
|
|
95
|
+
const newArray = new Float32Array(itemCount * itemSize);
|
|
96
|
+
const bufferData = this._getBufferData();
|
|
97
|
+
let newOffSet = 0;
|
|
98
|
+
const newOffSetMap = new Map();
|
|
99
|
+
for (const [key, offSet] of this.offSetMap) {
|
|
100
|
+
const itemOffSet = offSet / 4;
|
|
101
|
+
newArray.set(bufferData.slice(itemOffSet, itemOffSet + itemSize), newOffSet);
|
|
102
|
+
// this.offSetMap.set(key, newOffSet * 4);
|
|
103
|
+
newOffSetMap.set(key, newOffSet * 4);
|
|
104
|
+
newOffSet += itemSize;
|
|
105
|
+
}
|
|
106
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
107
|
+
gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
|
|
108
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
|
|
109
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
110
|
+
this._capacity = capacity;
|
|
111
|
+
this.tombstoneOffSet = [];
|
|
112
|
+
this._length = itemCount;
|
|
113
|
+
this.offSetMap = newOffSetMap;
|
|
114
|
+
}
|
|
115
|
+
autoExtendBuffer(payloadSize) {
|
|
116
|
+
if (payloadSize <= this.spaceLeft)
|
|
117
|
+
return;
|
|
118
|
+
const newCapacity = Math.ceil((payloadSize + this.length));
|
|
119
|
+
this.extendBuffer(newCapacity);
|
|
120
|
+
}
|
|
121
|
+
extendBuffer(newCapacity) {
|
|
122
|
+
const { gl, buffer, bufferType } = this;
|
|
123
|
+
const itemSize = this.itemSize;
|
|
124
|
+
const bufferData = this._getBufferData();
|
|
125
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
126
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
|
|
127
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
128
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
129
|
+
this._capacity = newCapacity;
|
|
130
|
+
}
|
|
131
|
+
/** implicit methods to be used by the child class */
|
|
132
|
+
/**
|
|
133
|
+
* @typedef {Float32Array} payload
|
|
134
|
+
* @param {Array<{key, payload}>} items
|
|
135
|
+
* @param {number} partOffset
|
|
136
|
+
* @returns
|
|
137
|
+
*/
|
|
138
|
+
_updatePartial(items, partOffset) {
|
|
139
|
+
const { gl, buffer } = this;
|
|
140
|
+
const partStart = partOffset * 4;
|
|
141
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
142
|
+
for (let { key, payload } of items) {
|
|
143
|
+
let offset = this.getOffset(key);
|
|
144
|
+
if (offset !== undefined) {
|
|
145
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset + partStart, payload);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
149
|
+
}
|
|
150
|
+
_getBufferData() {
|
|
151
|
+
const { gl, buffer } = this;
|
|
152
|
+
const size = new Float32Array(this.length * this.itemSize);
|
|
153
|
+
const bufferData = new Float32Array(size);
|
|
154
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
155
|
+
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
156
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
157
|
+
return bufferData;
|
|
158
|
+
}
|
|
159
|
+
_removeFromBuffer(keys) {
|
|
160
|
+
const { gl, buffer } = this;
|
|
161
|
+
const emptyBlock = new Float32Array(this.itemSize).fill(0);
|
|
162
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
163
|
+
for (let key of keys) {
|
|
164
|
+
let offset = this.getOffset(key);
|
|
165
|
+
if (offset !== undefined) {
|
|
166
|
+
this.deleteFromAccount(key);
|
|
167
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, emptyBlock);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
171
|
+
}
|
|
172
|
+
free() {
|
|
173
|
+
this.gl.deleteBuffer(this.buffer);
|
|
174
|
+
this.buffer = null;
|
|
175
|
+
this.vao = null;
|
|
176
|
+
this.gl = null;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
exports.default = default_1;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.BufferOffsetManager = void 0;
|
|
21
|
+
const bufferoffsetmanager_1 = __importDefault(require("./bufferoffsetmanager"));
|
|
22
|
+
exports.BufferOffsetManager = bufferoffsetmanager_1.default;
|
|
23
|
+
__exportStar(require("./single-attribute-buffer-management/index"), exports);
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* BufferOffsetManager
|
|
4
|
+
* Purpose: To manage the offset of the buffer. Plus extend and defrag the buffer.
|
|
5
|
+
* ------------------------------------------------------------------------------------------------------------------------------------------- * Functions:
|
|
6
|
+
* 1. getOffet(key) : return the offset of the key if not found return false.
|
|
7
|
+
* 2. setOffset(key, offset) : set the offset of the key.
|
|
8
|
+
* 3. nextOffset() : return the next available offset if not return false.
|
|
9
|
+
* 4. delete(key) : delete the key and return true if not found return false.
|
|
10
|
+
* 5. defragBuffer(gl, buffer, bufferType, newCapacity = null) : defrag the buffer. if newCapacity is not provided the buffer is vacumed.
|
|
11
|
+
* 6. extendBuffer(gl, buffer, bufferType, newCapacity) : extend the buffer.
|
|
12
|
+
* -------------------------------------------------------------------------------------------------------------------------------------------
|
|
13
|
+
* What this class does NOT do:
|
|
14
|
+
* ADD, DELETE, READ
|
|
15
|
+
* ADD, inputs needs to be turn into a block and put into buffer. Bulk will be more performant.
|
|
16
|
+
* DELETE, might be a set to single byte to indicate the tombstone.
|
|
17
|
+
* READ, most of the time is not needed to be read, unless for defraging.
|
|
18
|
+
* This unpredicatable behavior is not handled by this class.
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.BufferManager = void 0;
|
|
22
|
+
class BufferManager {
|
|
23
|
+
constructor(gl, itemSize, { bufferType = "STATIC_DRAW", buffer = null, initialCapacity = null } = {}) {
|
|
24
|
+
this.isFreed = false;
|
|
25
|
+
this.gl = gl;
|
|
26
|
+
this.itemSize = itemSize;
|
|
27
|
+
this.bufferType = bufferType;
|
|
28
|
+
this.buffer = buffer === null ? gl.createBuffer() : buffer;
|
|
29
|
+
if (initialCapacity !== null)
|
|
30
|
+
this.resetWithCapacity(initialCapacity);
|
|
31
|
+
}
|
|
32
|
+
resetWithCapacity(capacity) {
|
|
33
|
+
const { gl, buffer, bufferType, itemSize } = this;
|
|
34
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
gl.bufferData(gl.ARRAY_BUFFER, capacity * itemSize * 4, gl[bufferType]);
|
|
37
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
38
|
+
}
|
|
39
|
+
deleteBulk(offsets) {
|
|
40
|
+
const { gl, buffer, itemSize } = this;
|
|
41
|
+
const emptyBlock = new Float32Array(this.itemSize).fill(NaN);
|
|
42
|
+
const offsetMultiplier = itemSize * 4;
|
|
43
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
44
|
+
for (let offset of offsets) {
|
|
45
|
+
if (offset !== undefined) {
|
|
46
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset * offsetMultiplier, emptyBlock);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
50
|
+
}
|
|
51
|
+
insertBulk(blocks, offsets) {
|
|
52
|
+
const { gl, buffer, itemSize } = this;
|
|
53
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
54
|
+
const offsetMultiplier = itemSize * 4;
|
|
55
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
56
|
+
const block = blocks[i];
|
|
57
|
+
const offset = offsets[i] * offsetMultiplier;
|
|
58
|
+
if (offset !== undefined)
|
|
59
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, offset, block);
|
|
60
|
+
}
|
|
61
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
62
|
+
}
|
|
63
|
+
// TODO: this is broken
|
|
64
|
+
defrag(offsetValues, occupiedCapacity, newCapacity) {
|
|
65
|
+
const { gl, buffer, bufferType, itemSize } = this;
|
|
66
|
+
const newArray = new Float32Array(newCapacity * itemSize);
|
|
67
|
+
const bufferData = this._getBufferData(occupiedCapacity);
|
|
68
|
+
let newOffset = 0;
|
|
69
|
+
for (const offset of offsetValues) {
|
|
70
|
+
const itemOffset = offset * itemSize;
|
|
71
|
+
newArray.set(bufferData.slice(itemOffset, itemOffset + itemSize), newOffset);
|
|
72
|
+
newOffset += itemSize;
|
|
73
|
+
}
|
|
74
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
|
|
77
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, newArray);
|
|
78
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
79
|
+
}
|
|
80
|
+
extendBuffer(occupiedCapacity, newCapacity) {
|
|
81
|
+
const { gl, buffer, bufferType } = this;
|
|
82
|
+
const itemSize = this.itemSize;
|
|
83
|
+
const bufferData = this._getBufferData(occupiedCapacity);
|
|
84
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
gl.bufferData(gl.ARRAY_BUFFER, newCapacity * itemSize * 4, gl[bufferType]);
|
|
87
|
+
gl.bufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
88
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
89
|
+
}
|
|
90
|
+
_getBufferData(occupiedCapacity) {
|
|
91
|
+
const { gl, buffer } = this;
|
|
92
|
+
const size = occupiedCapacity * this.itemSize;
|
|
93
|
+
const bufferData = new Float32Array(size);
|
|
94
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buffer);
|
|
95
|
+
gl.getBufferSubData(gl.ARRAY_BUFFER, 0, bufferData);
|
|
96
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
97
|
+
return bufferData;
|
|
98
|
+
}
|
|
99
|
+
free() {
|
|
100
|
+
if (this.isFreed)
|
|
101
|
+
return;
|
|
102
|
+
this.gl.deleteBuffer(this.buffer);
|
|
103
|
+
// this.buffer = null;
|
|
104
|
+
// this.gl = null;
|
|
105
|
+
this.isFreed = true;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.BufferManager = BufferManager;
|