@antv/l7-renderer 2.20.13 → 2.20.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import type { RenderPass, RenderTarget, SwapChain } from '@antv/g-device-api';
2
2
  import type { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
3
3
  import 'reflect-metadata';
4
+ import { RenderCache } from './DeviceCache';
4
5
  import DeviceFramebuffer from './DeviceFramebuffer';
5
6
  /**
6
7
  * Device API renderer
@@ -19,14 +20,18 @@ export default class DeviceRendererService implements IRendererService {
19
20
  * Current render pass.
20
21
  */
21
22
  renderPass: RenderPass;
23
+ preRenderPass: RenderPass;
22
24
  mainColorRT: RenderTarget;
23
25
  mainDepthRT: RenderTarget;
26
+ renderCache: RenderCache;
24
27
  /**
25
28
  * Current FBO.
26
29
  */
27
30
  currentFramebuffer: DeviceFramebuffer | null;
28
31
  queryVerdorInfo: () => string;
32
+ private viewportOrigin;
29
33
  init(canvas: HTMLCanvasElement, cfg: IRenderConfig): Promise<void>;
34
+ private createMainColorDepthRT;
30
35
  beginFrame(): void;
31
36
  endFrame(): void;
32
37
  getPointSizeRange(): any;
@@ -38,6 +43,7 @@ export default class DeviceRendererService implements IRendererService {
38
43
  createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
39
44
  createFramebuffer: (options: IFramebufferInitializationOptions) => DeviceFramebuffer;
40
45
  useFramebuffer: (framebuffer: IFramebuffer | null, drawCommands: () => void) => void;
46
+ useFramebufferAsync: (framebuffer: IFramebuffer | null, drawCommands: () => Promise<void>) => Promise<void>;
41
47
  clear: (options: IClearOptions) => void;
42
48
  viewport: ({ width, height, }: {
43
49
  x: number;
@@ -46,6 +52,7 @@ export default class DeviceRendererService implements IRendererService {
46
52
  height: number;
47
53
  }) => void;
48
54
  readPixels: (options: IReadPixelsOptions) => Uint8Array;
55
+ readPixelsAsync: (options: IReadPixelsOptions) => Promise<Uint8Array>;
49
56
  getViewportSize: () => {
50
57
  width: number;
51
58
  height: number;
@@ -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 (_ref) {
71
- var width = _ref.width,
72
- height = _ref.height;
73
- // use WebGL context directly
74
- // @see https://github.com/regl-project/regl/blob/gh-pages/API.md#unsafe-escape-hatch
75
- // this.gl._gl.viewport(x, y, width, height);
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
- return readback.readTextureSync(texture, x, y, width, height, new Uint8Array(width * height * 4));
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 _callee(canvas, cfg) {
225
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(canvas, cfg) {
134
226
  var enableWebGPU, shaderCompilerPath, deviceContribution, swapChain, gl;
135
- return _regeneratorRuntime.wrap(function _callee$(_context) {
136
- while (1) switch (_context.prev = _context.next) {
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
- _context.next = 5;
249
+ _context3.next = 5;
158
250
  return deviceContribution.createSwapChain(canvas);
159
251
  case 5:
160
- swapChain = _context.sent;
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,49 +265,60 @@ 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.mainColorRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
175
- format: Format.U8_RGBA_RT,
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 _context.stop();
271
+ return _context3.stop();
189
272
  }
190
- }, _callee, this);
273
+ }, _callee3, this);
191
274
  }));
192
- function init(_x, _x2) {
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() {
305
+ this.device.beginFrame();
200
306
  var currentFramebuffer = this.currentFramebuffer,
201
307
  swapChain = this.swapChain,
202
308
  mainColorRT = this.mainColorRT,
203
309
  mainDepthRT = this.mainDepthRT;
204
- var onscreenTexture = swapChain.getOnscreenTexture();
205
310
  var colorAttachment = currentFramebuffer ? currentFramebuffer['colorRenderTarget'] : mainColorRT;
206
- var colorResolveTo = currentFramebuffer ? null : onscreenTexture;
311
+ var colorResolveTo = currentFramebuffer ? null : swapChain.getOnscreenTexture();
207
312
  var depthStencilAttachment = currentFramebuffer ? currentFramebuffer['depthRenderTarget'] : mainDepthRT;
208
- var _ref2 =
313
+ var _ref4 =
209
314
  // @ts-ignore
210
315
  (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer.clearOptions) || {},
211
- _ref2$color = _ref2.color,
212
- color = _ref2$color === void 0 ? [0, 0, 0, 0] : _ref2$color,
213
- _ref2$depth = _ref2.depth,
214
- depth = _ref2$depth === void 0 ? 1 : _ref2$depth,
215
- _ref2$stencil = _ref2.stencil,
216
- stencil = _ref2$stencil === void 0 ? 0 : _ref2$stencil;
316
+ _ref4$color = _ref4.color,
317
+ color = _ref4$color === void 0 ? [0, 0, 0, 0] : _ref4$color,
318
+ _ref4$depth = _ref4.depth,
319
+ depth = _ref4$depth === void 0 ? 1 : _ref4$depth,
320
+ _ref4$stencil = _ref4.stencil,
321
+ stencil = _ref4$stencil === void 0 ? 0 : _ref4$stencil;
217
322
  var colorClearColor = colorAttachment ? colorNewFromRGBA(color[0] * 255, color[1] * 255, color[2] * 255, color[3]) : TransparentBlack;
218
323
  var depthClearValue = depthStencilAttachment ? depth : undefined;
219
324
  var stencilClearValue = depthStencilAttachment ? stencil : undefined;
@@ -221,6 +326,8 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
221
326
  colorAttachment: [colorAttachment],
222
327
  colorResolveTo: [colorResolveTo],
223
328
  colorClearColor: [colorClearColor],
329
+ // colorStore: [!!currentFramebuffer],
330
+ colorStore: [true],
224
331
  depthStencilAttachment: depthStencilAttachment,
225
332
  depthClearValue: depthClearValue,
226
333
  stencilClearValue: stencilClearValue
@@ -231,6 +338,7 @@ var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/fun
231
338
  key: "endFrame",
232
339
  value: function endFrame() {
233
340
  this.device.submitPass(this.renderPass);
341
+ this.device.endFrame();
234
342
  }
235
343
  }, {
236
344
  key: "getPointSizeRange",
@@ -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
+ }();
@@ -1,2 +1,7 @@
1
1
  export type TypedArray = Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array;
2
2
  export declare function isTypedArray(x: any): x is TypedArray;
3
+ /**
4
+ * WebGPU does not support RGB texture, so we need to convert RGB to RGBA
5
+ * @see https://github.com/antvis/L7/pull/2262
6
+ */
7
+ export declare function extend3ChannelsTo4(array: Float32Array, valueToInsert: number): Float32Array;
@@ -13,4 +13,22 @@ var dtypes = {
13
13
  // eslint-disable-next-line
14
14
  export function isTypedArray(x) {
15
15
  return Object.prototype.toString.call(x) in dtypes;
16
+ }
17
+
18
+ /**
19
+ * WebGPU does not support RGB texture, so we need to convert RGB to RGBA
20
+ * @see https://github.com/antvis/L7/pull/2262
21
+ */
22
+ export function extend3ChannelsTo4(array, valueToInsert) {
23
+ var originalLength = array.length;
24
+ var insertCount = Math.ceil(originalLength / 3);
25
+ var newLength = originalLength + insertCount;
26
+ var newArray = new Float32Array(newLength);
27
+ for (var i = 0; i < newLength; i += 4) {
28
+ newArray[i] = array[i / 4 * 3];
29
+ newArray[i + 1] = array[i / 4 * 3 + 1];
30
+ newArray[i + 2] = array[i / 4 * 3 + 2];
31
+ newArray[i + 3] = valueToInsert;
32
+ }
33
+ return newArray;
16
34
  }
@@ -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;