@antv/l7-renderer 2.20.12 → 2.20.14
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/es/device/DeviceCache.d.ts +12 -0
- package/es/device/DeviceCache.js +197 -0
- package/es/device/DeviceFramebuffer.js +21 -2
- package/es/device/DeviceModel.js +40 -11
- package/es/device/DeviceTexture2D.d.ts +3 -0
- package/es/device/DeviceTexture2D.js +70 -51
- package/es/device/index.d.ts +7 -0
- package/es/device/index.js +147 -41
- package/es/device/utils/HashMap.d.ts +24 -0
- package/es/device/utils/HashMap.js +153 -0
- package/es/regl/index.d.ts +2 -0
- package/es/regl/index.js +49 -15
- package/lib/device/DeviceCache.js +181 -0
- package/lib/device/DeviceFramebuffer.js +12 -4
- package/lib/device/DeviceModel.js +32 -10
- package/lib/device/DeviceTexture2D.js +42 -22
- package/lib/device/index.js +86 -8
- package/lib/device/utils/HashMap.js +113 -0
- package/lib/regl/index.js +8 -0
- package/package.json +6 -6
package/es/device/index.js
CHANGED
|
@@ -4,16 +4,19 @@ import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
5
|
var _dec, _class;
|
|
6
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
-
import { Format, TextureUsage, TransparentBlack, WebGLDeviceContribution, WebGPUDeviceContribution, colorNewFromRGBA } from '@antv/g-device-api';
|
|
7
|
+
import { Format, TextureUsage, TransparentBlack, ViewportOrigin, WebGLDeviceContribution, WebGPUDeviceContribution, colorNewFromRGBA } from '@antv/g-device-api';
|
|
8
|
+
import { lodashUtil } from '@antv/l7-utils';
|
|
8
9
|
import { injectable } from 'inversify';
|
|
9
10
|
import 'reflect-metadata';
|
|
10
11
|
import DeviceAttribute from "./DeviceAttribute";
|
|
11
12
|
import DeviceBuffer from "./DeviceBuffer";
|
|
13
|
+
import { RenderCache } from "./DeviceCache";
|
|
12
14
|
import DeviceElements from "./DeviceElements";
|
|
13
15
|
import DeviceFramebuffer from "./DeviceFramebuffer";
|
|
14
16
|
import DeviceModel from "./DeviceModel";
|
|
15
17
|
import DeviceTexture2D from "./DeviceTexture2D";
|
|
16
18
|
import { isWebGL2 } from "./utils/webgl";
|
|
19
|
+
var isUndefined = lodashUtil.isUndefined;
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Device API renderer
|
|
@@ -51,6 +54,30 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
51
54
|
_this.endFrame();
|
|
52
55
|
_this.currentFramebuffer = null;
|
|
53
56
|
});
|
|
57
|
+
_defineProperty(this, "useFramebufferAsync", /*#__PURE__*/function () {
|
|
58
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(framebuffer, drawCommands) {
|
|
59
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
60
|
+
while (1) switch (_context.prev = _context.next) {
|
|
61
|
+
case 0:
|
|
62
|
+
_this.currentFramebuffer = framebuffer;
|
|
63
|
+
_this.preRenderPass = _this.renderPass;
|
|
64
|
+
_this.beginFrame();
|
|
65
|
+
_context.next = 5;
|
|
66
|
+
return drawCommands();
|
|
67
|
+
case 5:
|
|
68
|
+
_this.endFrame();
|
|
69
|
+
_this.currentFramebuffer = null;
|
|
70
|
+
_this.renderPass = _this.preRenderPass;
|
|
71
|
+
case 8:
|
|
72
|
+
case "end":
|
|
73
|
+
return _context.stop();
|
|
74
|
+
}
|
|
75
|
+
}, _callee);
|
|
76
|
+
}));
|
|
77
|
+
return function (_x, _x2) {
|
|
78
|
+
return _ref.apply(this, arguments);
|
|
79
|
+
};
|
|
80
|
+
}());
|
|
54
81
|
_defineProperty(this, "clear", function (options) {
|
|
55
82
|
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
|
|
56
83
|
var color = options.color,
|
|
@@ -65,18 +92,37 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
65
92
|
depth: depth,
|
|
66
93
|
stencil: stencil
|
|
67
94
|
};
|
|
95
|
+
} else {
|
|
96
|
+
var platformString = _this.queryVerdorInfo();
|
|
97
|
+
if (platformString === 'WebGL1') {
|
|
98
|
+
var gl = _this.getGLContext();
|
|
99
|
+
if (!isUndefined(stencil)) {
|
|
100
|
+
gl.clearStencil(stencil);
|
|
101
|
+
gl.clear(gl.STENCIL_BUFFER_BIT);
|
|
102
|
+
} else if (!isUndefined(depth)) {
|
|
103
|
+
gl.clearDepth(depth);
|
|
104
|
+
gl.clear(gl.DEPTH_BUFFER_BIT);
|
|
105
|
+
}
|
|
106
|
+
} else if (platformString === 'WebGL2') {
|
|
107
|
+
var _gl = _this.getGLContext();
|
|
108
|
+
if (!isUndefined(stencil)) {
|
|
109
|
+
_gl.clearBufferiv(_gl.STENCIL, 0, [stencil]);
|
|
110
|
+
} else if (!isUndefined(depth)) {
|
|
111
|
+
_gl.clearBufferfv(_gl.DEPTH, 0, [depth]);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
68
114
|
}
|
|
115
|
+
// Recreate render pass
|
|
116
|
+
// this.beginFrame();
|
|
69
117
|
});
|
|
70
|
-
_defineProperty(this, "viewport", function (
|
|
71
|
-
var width =
|
|
72
|
-
height =
|
|
73
|
-
//
|
|
74
|
-
|
|
75
|
-
|
|
118
|
+
_defineProperty(this, "viewport", function (_ref2) {
|
|
119
|
+
var width = _ref2.width,
|
|
120
|
+
height = _ref2.height;
|
|
121
|
+
// @see https://observablehq.com/@antv/g-device-api#cell-267
|
|
122
|
+
_this.swapChain.configureSwapChain(width, height);
|
|
123
|
+
_this.createMainColorDepthRT(width, height);
|
|
76
124
|
_this.width = width;
|
|
77
125
|
_this.height = height;
|
|
78
|
-
// Will be used in `setViewport` from RenderPass later.
|
|
79
|
-
// this.gl._refresh();
|
|
80
126
|
});
|
|
81
127
|
_defineProperty(this, "readPixels", function (options) {
|
|
82
128
|
var framebuffer = options.framebuffer,
|
|
@@ -86,8 +132,54 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
86
132
|
height = options.height;
|
|
87
133
|
var readback = _this.device.createReadback();
|
|
88
134
|
var texture = framebuffer['colorTexture'];
|
|
89
|
-
|
|
135
|
+
var result = readback.readTextureSync(texture, x,
|
|
136
|
+
/**
|
|
137
|
+
* Origin is at lower-left corner. Width / height is already multiplied by dpr.
|
|
138
|
+
* WebGPU needs flipY
|
|
139
|
+
*/
|
|
140
|
+
_this.viewportOrigin === ViewportOrigin.LOWER_LEFT ? y : _this.height - y, width, height, new Uint8Array(width * height * 4));
|
|
141
|
+
readback.destroy();
|
|
142
|
+
return result;
|
|
90
143
|
});
|
|
144
|
+
_defineProperty(this, "readPixelsAsync", /*#__PURE__*/function () {
|
|
145
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
|
|
146
|
+
var framebuffer, x, y, width, height, readback, texture, result, j, t;
|
|
147
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
148
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
149
|
+
case 0:
|
|
150
|
+
framebuffer = options.framebuffer, x = options.x, y = options.y, width = options.width, height = options.height;
|
|
151
|
+
readback = _this.device.createReadback();
|
|
152
|
+
texture = framebuffer['colorTexture'];
|
|
153
|
+
_context2.next = 5;
|
|
154
|
+
return readback.readTexture(texture, x,
|
|
155
|
+
/**
|
|
156
|
+
* Origin is at lower-left corner. Width / height is already multiplied by dpr.
|
|
157
|
+
* WebGPU needs flipY
|
|
158
|
+
*/
|
|
159
|
+
_this.viewportOrigin === ViewportOrigin.LOWER_LEFT ? y : _this.height - y, width, height, new Uint8Array(width * height * 4));
|
|
160
|
+
case 5:
|
|
161
|
+
result = _context2.sent;
|
|
162
|
+
// Since we use U8_RGBA_RT format in render target, need to change bgranorm -> rgba here.
|
|
163
|
+
if (_this.viewportOrigin !== ViewportOrigin.LOWER_LEFT) {
|
|
164
|
+
for (j = 0; j < result.length; j += 4) {
|
|
165
|
+
// Switch b and r components.
|
|
166
|
+
t = result[j];
|
|
167
|
+
result[j] = result[j + 2];
|
|
168
|
+
result[j + 2] = t;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
readback.destroy();
|
|
172
|
+
return _context2.abrupt("return", result);
|
|
173
|
+
case 9:
|
|
174
|
+
case "end":
|
|
175
|
+
return _context2.stop();
|
|
176
|
+
}
|
|
177
|
+
}, _callee2);
|
|
178
|
+
}));
|
|
179
|
+
return function (_x3) {
|
|
180
|
+
return _ref3.apply(this, arguments);
|
|
181
|
+
};
|
|
182
|
+
}());
|
|
91
183
|
_defineProperty(this, "getViewportSize", function () {
|
|
92
184
|
// FIXME: add viewport size in Device API.
|
|
93
185
|
return {
|
|
@@ -100,7 +192,6 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
100
192
|
return (_this$canvas = _this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.parentElement;
|
|
101
193
|
});
|
|
102
194
|
_defineProperty(this, "getCanvas", function () {
|
|
103
|
-
// return this.$container?.getElementsByTagName('canvas')[0] || null;
|
|
104
195
|
return _this.canvas;
|
|
105
196
|
});
|
|
106
197
|
_defineProperty(this, "getGLContext", function () {
|
|
@@ -116,6 +207,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
116
207
|
buffer.destroy();
|
|
117
208
|
});
|
|
118
209
|
_this.device.destroy();
|
|
210
|
+
_this.renderCache.destroy();
|
|
119
211
|
|
|
120
212
|
// make sure release webgl context
|
|
121
213
|
// this.gl?._gl?.getExtension('WEBGL_lose_context')?.loseContext();
|
|
@@ -130,10 +222,10 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
130
222
|
_createClass(DeviceRendererService, [{
|
|
131
223
|
key: "init",
|
|
132
224
|
value: function () {
|
|
133
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
225
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(canvas, cfg) {
|
|
134
226
|
var enableWebGPU, shaderCompilerPath, deviceContribution, swapChain, gl;
|
|
135
|
-
return _regeneratorRuntime.wrap(function
|
|
136
|
-
while (1) switch (
|
|
227
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
228
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
137
229
|
case 0:
|
|
138
230
|
enableWebGPU = cfg.enableWebGPU, shaderCompilerPath = cfg.shaderCompilerPath; // this.$container = $container;
|
|
139
231
|
this.canvas = canvas;
|
|
@@ -154,16 +246,18 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
154
246
|
console.warn('context restored', e);
|
|
155
247
|
}
|
|
156
248
|
});
|
|
157
|
-
|
|
249
|
+
_context3.next = 5;
|
|
158
250
|
return deviceContribution.createSwapChain(canvas);
|
|
159
251
|
case 5:
|
|
160
|
-
swapChain =
|
|
252
|
+
swapChain = _context3.sent;
|
|
161
253
|
swapChain.configureSwapChain(canvas.width, canvas.height);
|
|
162
254
|
this.device = swapChain.getDevice();
|
|
163
255
|
this.swapChain = swapChain;
|
|
256
|
+
this.renderCache = new RenderCache(this.device);
|
|
164
257
|
|
|
165
258
|
// Create default RT
|
|
166
259
|
this.currentFramebuffer = null;
|
|
260
|
+
this.viewportOrigin = this.device.queryVendorInfo().viewportOrigin;
|
|
167
261
|
|
|
168
262
|
// @ts-ignore
|
|
169
263
|
gl = this.device['gl'];
|
|
@@ -171,29 +265,40 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
171
265
|
// @ts-ignore
|
|
172
266
|
OES_texture_float: !isWebGL2(gl) && this.device['OES_texture_float']
|
|
173
267
|
};
|
|
174
|
-
this.
|
|
175
|
-
|
|
176
|
-
width: canvas.width,
|
|
177
|
-
height: canvas.height,
|
|
178
|
-
usage: TextureUsage.RENDER_TARGET
|
|
179
|
-
}));
|
|
180
|
-
this.mainDepthRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
|
|
181
|
-
format: Format.D24_S8,
|
|
182
|
-
width: canvas.width,
|
|
183
|
-
height: canvas.height,
|
|
184
|
-
usage: TextureUsage.RENDER_TARGET
|
|
185
|
-
}));
|
|
186
|
-
case 14:
|
|
268
|
+
this.createMainColorDepthRT(canvas.width, canvas.height);
|
|
269
|
+
case 15:
|
|
187
270
|
case "end":
|
|
188
|
-
return
|
|
271
|
+
return _context3.stop();
|
|
189
272
|
}
|
|
190
|
-
},
|
|
273
|
+
}, _callee3, this);
|
|
191
274
|
}));
|
|
192
|
-
function init(
|
|
275
|
+
function init(_x4, _x5) {
|
|
193
276
|
return _init.apply(this, arguments);
|
|
194
277
|
}
|
|
195
278
|
return init;
|
|
196
279
|
}()
|
|
280
|
+
}, {
|
|
281
|
+
key: "createMainColorDepthRT",
|
|
282
|
+
value: function createMainColorDepthRT(width, height) {
|
|
283
|
+
if (this.mainColorRT) {
|
|
284
|
+
this.mainColorRT.destroy();
|
|
285
|
+
}
|
|
286
|
+
if (this.mainDepthRT) {
|
|
287
|
+
this.mainDepthRT.destroy();
|
|
288
|
+
}
|
|
289
|
+
this.mainColorRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
|
|
290
|
+
format: Format.U8_RGBA_RT,
|
|
291
|
+
width: width,
|
|
292
|
+
height: height,
|
|
293
|
+
usage: TextureUsage.RENDER_TARGET
|
|
294
|
+
}));
|
|
295
|
+
this.mainDepthRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
|
|
296
|
+
format: Format.D24_S8,
|
|
297
|
+
width: width,
|
|
298
|
+
height: height,
|
|
299
|
+
usage: TextureUsage.RENDER_TARGET
|
|
300
|
+
}));
|
|
301
|
+
}
|
|
197
302
|
}, {
|
|
198
303
|
key: "beginFrame",
|
|
199
304
|
value: function beginFrame() {
|
|
@@ -201,19 +306,18 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
201
306
|
swapChain = this.swapChain,
|
|
202
307
|
mainColorRT = this.mainColorRT,
|
|
203
308
|
mainDepthRT = this.mainDepthRT;
|
|
204
|
-
var onscreenTexture = swapChain.getOnscreenTexture();
|
|
205
309
|
var colorAttachment = currentFramebuffer ? currentFramebuffer['colorRenderTarget'] : mainColorRT;
|
|
206
|
-
var colorResolveTo = currentFramebuffer ? null :
|
|
310
|
+
var colorResolveTo = currentFramebuffer ? null : swapChain.getOnscreenTexture();
|
|
207
311
|
var depthStencilAttachment = currentFramebuffer ? currentFramebuffer['depthRenderTarget'] : mainDepthRT;
|
|
208
|
-
var
|
|
312
|
+
var _ref4 =
|
|
209
313
|
// @ts-ignore
|
|
210
314
|
(currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer.clearOptions) || {},
|
|
211
|
-
|
|
212
|
-
color =
|
|
213
|
-
|
|
214
|
-
depth =
|
|
215
|
-
|
|
216
|
-
stencil =
|
|
315
|
+
_ref4$color = _ref4.color,
|
|
316
|
+
color = _ref4$color === void 0 ? [0, 0, 0, 0] : _ref4$color,
|
|
317
|
+
_ref4$depth = _ref4.depth,
|
|
318
|
+
depth = _ref4$depth === void 0 ? 1 : _ref4$depth,
|
|
319
|
+
_ref4$stencil = _ref4.stencil,
|
|
320
|
+
stencil = _ref4$stencil === void 0 ? 0 : _ref4$stencil;
|
|
217
321
|
var colorClearColor = colorAttachment ? colorNewFromRGBA(color[0] * 255, color[1] * 255, color[2] * 255, color[3]) : TransparentBlack;
|
|
218
322
|
var depthClearValue = depthStencilAttachment ? depth : undefined;
|
|
219
323
|
var stencilClearValue = depthStencilAttachment ? stencil : undefined;
|
|
@@ -221,6 +325,8 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
|
|
|
221
325
|
colorAttachment: [colorAttachment],
|
|
222
326
|
colorResolveTo: [colorResolveTo],
|
|
223
327
|
colorClearColor: [colorClearColor],
|
|
328
|
+
// colorStore: [!!currentFramebuffer],
|
|
329
|
+
colorStore: [true],
|
|
224
330
|
depthStencilAttachment: depthStencilAttachment,
|
|
225
331
|
depthClearValue: depthClearValue,
|
|
226
332
|
stencilClearValue: stencilClearValue
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function hashCodeNumberUpdate(hash: number, v?: number): number;
|
|
2
|
+
export declare function hashCodeNumberFinish(hash: number): number;
|
|
3
|
+
export declare function nullHashFunc<T>(k: T): number;
|
|
4
|
+
export type EqualFunc<K> = (a: K, b: K) => boolean;
|
|
5
|
+
export type HashFunc<K> = (a: K) => number;
|
|
6
|
+
declare class HashBucket<K, V> {
|
|
7
|
+
keys: K[];
|
|
8
|
+
values: V[];
|
|
9
|
+
}
|
|
10
|
+
export declare class HashMap<K, V> {
|
|
11
|
+
private keyEqualFunc;
|
|
12
|
+
private keyHashFunc;
|
|
13
|
+
buckets: Map<number, HashBucket<K, V>>;
|
|
14
|
+
constructor(keyEqualFunc: EqualFunc<K>, keyHashFunc: HashFunc<K>);
|
|
15
|
+
private findBucketIndex;
|
|
16
|
+
private findBucket;
|
|
17
|
+
get(k: K): V | null;
|
|
18
|
+
add(k: K, v: V): void;
|
|
19
|
+
delete(k: K): void;
|
|
20
|
+
clear(): void;
|
|
21
|
+
size(): number;
|
|
22
|
+
values(): IterableIterator<V>;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
+
// Jenkins One-at-a-Time hash from http://www.burtleburtle.net/bob/hash/doobs.html
|
|
9
|
+
export function hashCodeNumberUpdate(hash) {
|
|
10
|
+
var v = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
11
|
+
hash += v;
|
|
12
|
+
hash += hash << 10;
|
|
13
|
+
hash += hash >>> 6;
|
|
14
|
+
return hash >>> 0;
|
|
15
|
+
}
|
|
16
|
+
export function hashCodeNumberFinish(hash) {
|
|
17
|
+
hash += hash << 3;
|
|
18
|
+
hash ^= hash >>> 11;
|
|
19
|
+
hash += hash << 15;
|
|
20
|
+
return hash >>> 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Pass this as a hash function to use a one-bucket HashMap (equivalent to linear search in an array),
|
|
24
|
+
// which can be efficient for small numbers of items.
|
|
25
|
+
export function nullHashFunc(k) {
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
var HashBucket = /*#__PURE__*/_createClass(function HashBucket() {
|
|
29
|
+
_classCallCheck(this, HashBucket);
|
|
30
|
+
_defineProperty(this, "keys", []);
|
|
31
|
+
_defineProperty(this, "values", []);
|
|
32
|
+
});
|
|
33
|
+
export var HashMap = /*#__PURE__*/function () {
|
|
34
|
+
function HashMap(keyEqualFunc, keyHashFunc) {
|
|
35
|
+
_classCallCheck(this, HashMap);
|
|
36
|
+
_defineProperty(this, "buckets", new Map());
|
|
37
|
+
this.keyEqualFunc = keyEqualFunc;
|
|
38
|
+
this.keyHashFunc = keyHashFunc;
|
|
39
|
+
}
|
|
40
|
+
_createClass(HashMap, [{
|
|
41
|
+
key: "findBucketIndex",
|
|
42
|
+
value: function findBucketIndex(bucket, k) {
|
|
43
|
+
for (var i = 0; i < bucket.keys.length; i++) if (this.keyEqualFunc(k, bucket.keys[i])) return i;
|
|
44
|
+
return -1;
|
|
45
|
+
}
|
|
46
|
+
}, {
|
|
47
|
+
key: "findBucket",
|
|
48
|
+
value: function findBucket(k) {
|
|
49
|
+
var bw = this.keyHashFunc(k);
|
|
50
|
+
return this.buckets.get(bw);
|
|
51
|
+
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "get",
|
|
54
|
+
value: function get(k) {
|
|
55
|
+
var bucket = this.findBucket(k);
|
|
56
|
+
if (bucket === undefined) return null;
|
|
57
|
+
var bi = this.findBucketIndex(bucket, k);
|
|
58
|
+
if (bi < 0) return null;
|
|
59
|
+
return bucket.values[bi];
|
|
60
|
+
}
|
|
61
|
+
}, {
|
|
62
|
+
key: "add",
|
|
63
|
+
value: function add(k, v) {
|
|
64
|
+
var bw = this.keyHashFunc(k);
|
|
65
|
+
if (this.buckets.get(bw) === undefined) this.buckets.set(bw, new HashBucket());
|
|
66
|
+
var bucket = this.buckets.get(bw);
|
|
67
|
+
bucket.keys.push(k);
|
|
68
|
+
bucket.values.push(v);
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
71
|
+
key: "delete",
|
|
72
|
+
value: function _delete(k) {
|
|
73
|
+
var bucket = this.findBucket(k);
|
|
74
|
+
if (bucket === undefined) return;
|
|
75
|
+
var bi = this.findBucketIndex(bucket, k);
|
|
76
|
+
if (bi === -1) return;
|
|
77
|
+
bucket.keys.splice(bi, 1);
|
|
78
|
+
bucket.values.splice(bi, 1);
|
|
79
|
+
}
|
|
80
|
+
}, {
|
|
81
|
+
key: "clear",
|
|
82
|
+
value: function clear() {
|
|
83
|
+
this.buckets.clear();
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "size",
|
|
87
|
+
value: function size() {
|
|
88
|
+
var acc = 0;
|
|
89
|
+
var _iterator = _createForOfIteratorHelper(this.buckets.values()),
|
|
90
|
+
_step;
|
|
91
|
+
try {
|
|
92
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
93
|
+
var bucket = _step.value;
|
|
94
|
+
acc += bucket.values.length;
|
|
95
|
+
}
|
|
96
|
+
} catch (err) {
|
|
97
|
+
_iterator.e(err);
|
|
98
|
+
} finally {
|
|
99
|
+
_iterator.f();
|
|
100
|
+
}
|
|
101
|
+
return acc;
|
|
102
|
+
}
|
|
103
|
+
}, {
|
|
104
|
+
key: "values",
|
|
105
|
+
value: /*#__PURE__*/_regeneratorRuntime.mark(function values() {
|
|
106
|
+
var _iterator2, _step2, bucket, j;
|
|
107
|
+
return _regeneratorRuntime.wrap(function values$(_context) {
|
|
108
|
+
while (1) switch (_context.prev = _context.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
_iterator2 = _createForOfIteratorHelper(this.buckets.values());
|
|
111
|
+
_context.prev = 1;
|
|
112
|
+
_iterator2.s();
|
|
113
|
+
case 3:
|
|
114
|
+
if ((_step2 = _iterator2.n()).done) {
|
|
115
|
+
_context.next = 14;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
bucket = _step2.value;
|
|
119
|
+
j = bucket.values.length - 1;
|
|
120
|
+
case 6:
|
|
121
|
+
if (!(j >= 0)) {
|
|
122
|
+
_context.next = 12;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
_context.next = 9;
|
|
126
|
+
return bucket.values[j];
|
|
127
|
+
case 9:
|
|
128
|
+
j--;
|
|
129
|
+
_context.next = 6;
|
|
130
|
+
break;
|
|
131
|
+
case 12:
|
|
132
|
+
_context.next = 3;
|
|
133
|
+
break;
|
|
134
|
+
case 14:
|
|
135
|
+
_context.next = 19;
|
|
136
|
+
break;
|
|
137
|
+
case 16:
|
|
138
|
+
_context.prev = 16;
|
|
139
|
+
_context.t0 = _context["catch"](1);
|
|
140
|
+
_iterator2.e(_context.t0);
|
|
141
|
+
case 19:
|
|
142
|
+
_context.prev = 19;
|
|
143
|
+
_iterator2.f();
|
|
144
|
+
return _context.finish(19);
|
|
145
|
+
case 22:
|
|
146
|
+
case "end":
|
|
147
|
+
return _context.stop();
|
|
148
|
+
}
|
|
149
|
+
}, values, this, [[1, 16, 19, 22]]);
|
|
150
|
+
})
|
|
151
|
+
}]);
|
|
152
|
+
return HashMap;
|
|
153
|
+
}();
|
package/es/regl/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ export default class ReglRendererService implements IRendererService {
|
|
|
29
29
|
createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
|
|
30
30
|
createFramebuffer: (options: IFramebufferInitializationOptions) => ReglFramebuffer;
|
|
31
31
|
useFramebuffer: (framebuffer: IFramebuffer | null, drawCommands: () => void) => void;
|
|
32
|
+
useFramebufferAsync: (framebuffer: IFramebuffer | null, drawCommands: () => Promise<void>) => Promise<void>;
|
|
32
33
|
clear: (options: IClearOptions) => void;
|
|
33
34
|
viewport: ({ x, y, width, height, }: {
|
|
34
35
|
x: number;
|
|
@@ -37,6 +38,7 @@ export default class ReglRendererService implements IRendererService {
|
|
|
37
38
|
height: number;
|
|
38
39
|
}) => void;
|
|
39
40
|
readPixels: (options: IReadPixelsOptions) => Uint8Array;
|
|
41
|
+
readPixelsAsync: (options: IReadPixelsOptions) => Promise<Uint8Array>;
|
|
40
42
|
getViewportSize: () => {
|
|
41
43
|
width: number;
|
|
42
44
|
height: number;
|
package/es/regl/index.js
CHANGED
|
@@ -53,6 +53,24 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
53
53
|
framebuffer: framebuffer ? framebuffer.get() : null
|
|
54
54
|
})(drawCommands);
|
|
55
55
|
});
|
|
56
|
+
_defineProperty(this, "useFramebufferAsync", /*#__PURE__*/function () {
|
|
57
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(framebuffer, drawCommands) {
|
|
58
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
59
|
+
while (1) switch (_context.prev = _context.next) {
|
|
60
|
+
case 0:
|
|
61
|
+
_this.gl({
|
|
62
|
+
framebuffer: framebuffer ? framebuffer.get() : null
|
|
63
|
+
})(drawCommands);
|
|
64
|
+
case 1:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee);
|
|
69
|
+
}));
|
|
70
|
+
return function (_x, _x2) {
|
|
71
|
+
return _ref.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}());
|
|
56
74
|
_defineProperty(this, "clear", function (options) {
|
|
57
75
|
var _this$gl;
|
|
58
76
|
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
|
|
@@ -69,11 +87,11 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
69
87
|
reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
|
|
70
88
|
(_this$gl = _this.gl) === null || _this$gl === void 0 || _this$gl.clear(reglClearOptions);
|
|
71
89
|
});
|
|
72
|
-
_defineProperty(this, "viewport", function (
|
|
73
|
-
var x =
|
|
74
|
-
y =
|
|
75
|
-
width =
|
|
76
|
-
height =
|
|
90
|
+
_defineProperty(this, "viewport", function (_ref2) {
|
|
91
|
+
var x = _ref2.x,
|
|
92
|
+
y = _ref2.y,
|
|
93
|
+
width = _ref2.width,
|
|
94
|
+
height = _ref2.height;
|
|
77
95
|
// use WebGL context directly
|
|
78
96
|
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#unsafe-escape-hatch
|
|
79
97
|
_this.gl._gl.viewport(x, y, width, height);
|
|
@@ -98,6 +116,22 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
98
116
|
}
|
|
99
117
|
return _this.gl.read(readPixelsOptions);
|
|
100
118
|
});
|
|
119
|
+
_defineProperty(this, "readPixelsAsync", /*#__PURE__*/function () {
|
|
120
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(options) {
|
|
121
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
122
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
123
|
+
case 0:
|
|
124
|
+
return _context2.abrupt("return", _this.readPixels(options));
|
|
125
|
+
case 1:
|
|
126
|
+
case "end":
|
|
127
|
+
return _context2.stop();
|
|
128
|
+
}
|
|
129
|
+
}, _callee2);
|
|
130
|
+
}));
|
|
131
|
+
return function (_x3) {
|
|
132
|
+
return _ref3.apply(this, arguments);
|
|
133
|
+
};
|
|
134
|
+
}());
|
|
101
135
|
_defineProperty(this, "getViewportSize", function () {
|
|
102
136
|
return {
|
|
103
137
|
width: _this.gl._gl.drawingBufferWidth,
|
|
@@ -134,22 +168,22 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
134
168
|
_createClass(ReglRendererService, [{
|
|
135
169
|
key: "init",
|
|
136
170
|
value: function () {
|
|
137
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
171
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(canvas, cfg, gl) {
|
|
138
172
|
var _this2 = this;
|
|
139
|
-
return _regeneratorRuntime.wrap(function
|
|
140
|
-
while (1) switch (
|
|
173
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
174
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
141
175
|
case 0:
|
|
142
176
|
// this.$container = $container;
|
|
143
177
|
this.canvas = canvas;
|
|
144
178
|
if (!gl) {
|
|
145
|
-
|
|
179
|
+
_context3.next = 5;
|
|
146
180
|
break;
|
|
147
181
|
}
|
|
148
182
|
this.gl = gl;
|
|
149
|
-
|
|
183
|
+
_context3.next = 8;
|
|
150
184
|
break;
|
|
151
185
|
case 5:
|
|
152
|
-
|
|
186
|
+
_context3.next = 7;
|
|
153
187
|
return new Promise(function (resolve, reject) {
|
|
154
188
|
regl({
|
|
155
189
|
canvas: _this2.canvas,
|
|
@@ -180,18 +214,18 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
180
214
|
});
|
|
181
215
|
});
|
|
182
216
|
case 7:
|
|
183
|
-
this.gl =
|
|
217
|
+
this.gl = _context3.sent;
|
|
184
218
|
case 8:
|
|
185
219
|
this.extensionObject = {
|
|
186
220
|
OES_texture_float: this.testExtension('OES_texture_float')
|
|
187
221
|
};
|
|
188
222
|
case 9:
|
|
189
223
|
case "end":
|
|
190
|
-
return
|
|
224
|
+
return _context3.stop();
|
|
191
225
|
}
|
|
192
|
-
},
|
|
226
|
+
}, _callee3, this);
|
|
193
227
|
}));
|
|
194
|
-
function init(
|
|
228
|
+
function init(_x4, _x5, _x6) {
|
|
195
229
|
return _init.apply(this, arguments);
|
|
196
230
|
}
|
|
197
231
|
return init;
|