@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.
@@ -42,15 +42,18 @@ __export(device_exports, {
42
42
  });
43
43
  module.exports = __toCommonJS(device_exports);
44
44
  var import_g_device_api = require("@antv/g-device-api");
45
+ var import_l7_utils = require("@antv/l7-utils");
45
46
  var import_inversify = require("inversify");
46
47
  var import_reflect_metadata = require("reflect-metadata");
47
48
  var import_DeviceAttribute = __toESM(require("./DeviceAttribute"));
48
49
  var import_DeviceBuffer = __toESM(require("./DeviceBuffer"));
50
+ var import_DeviceCache = require("./DeviceCache");
49
51
  var import_DeviceElements = __toESM(require("./DeviceElements"));
50
52
  var import_DeviceFramebuffer = __toESM(require("./DeviceFramebuffer"));
51
53
  var import_DeviceModel = __toESM(require("./DeviceModel"));
52
54
  var import_DeviceTexture2D = __toESM(require("./DeviceTexture2D"));
53
55
  var import_webgl = require("./utils/webgl");
56
+ var { isUndefined } = import_l7_utils.lodashUtil;
54
57
  var DeviceRendererService = class {
55
58
  constructor() {
56
59
  this.uniformBuffers = [];
@@ -70,10 +73,38 @@ var DeviceRendererService = class {
70
73
  this.endFrame();
71
74
  this.currentFramebuffer = null;
72
75
  };
76
+ this.useFramebufferAsync = async (framebuffer, drawCommands) => {
77
+ this.currentFramebuffer = framebuffer;
78
+ this.preRenderPass = this.renderPass;
79
+ this.beginFrame();
80
+ await drawCommands();
81
+ this.endFrame();
82
+ this.currentFramebuffer = null;
83
+ this.renderPass = this.preRenderPass;
84
+ };
73
85
  this.clear = (options) => {
74
86
  const { color, depth, stencil, framebuffer = null } = options;
75
87
  if (framebuffer) {
76
88
  framebuffer.clearOptions = { color, depth, stencil };
89
+ } else {
90
+ const platformString = this.queryVerdorInfo();
91
+ if (platformString === "WebGL1") {
92
+ const gl = this.getGLContext();
93
+ if (!isUndefined(stencil)) {
94
+ gl.clearStencil(stencil);
95
+ gl.clear(gl.STENCIL_BUFFER_BIT);
96
+ } else if (!isUndefined(depth)) {
97
+ gl.clearDepth(depth);
98
+ gl.clear(gl.DEPTH_BUFFER_BIT);
99
+ }
100
+ } else if (platformString === "WebGL2") {
101
+ const gl = this.getGLContext();
102
+ if (!isUndefined(stencil)) {
103
+ gl.clearBufferiv(gl.STENCIL, 0, [stencil]);
104
+ } else if (!isUndefined(depth)) {
105
+ gl.clearBufferfv(gl.DEPTH, 0, [depth]);
106
+ }
107
+ }
77
108
  }
78
109
  };
79
110
  this.viewport = ({
@@ -82,6 +113,8 @@ var DeviceRendererService = class {
82
113
  width,
83
114
  height
84
115
  }) => {
116
+ this.swapChain.configureSwapChain(width, height);
117
+ this.createMainColorDepthRT(width, height);
85
118
  this.width = width;
86
119
  this.height = height;
87
120
  };
@@ -89,14 +122,46 @@ var DeviceRendererService = class {
89
122
  const { framebuffer, x, y, width, height } = options;
90
123
  const readback = this.device.createReadback();
91
124
  const texture = framebuffer["colorTexture"];
92
- return readback.readTextureSync(
125
+ const result = readback.readTextureSync(
93
126
  texture,
94
127
  x,
95
- y,
128
+ /**
129
+ * Origin is at lower-left corner. Width / height is already multiplied by dpr.
130
+ * WebGPU needs flipY
131
+ */
132
+ this.viewportOrigin === import_g_device_api.ViewportOrigin.LOWER_LEFT ? y : this.height - y,
96
133
  width,
97
134
  height,
98
135
  new Uint8Array(width * height * 4)
99
136
  );
137
+ readback.destroy();
138
+ return result;
139
+ };
140
+ this.readPixelsAsync = async (options) => {
141
+ const { framebuffer, x, y, width, height } = options;
142
+ const readback = this.device.createReadback();
143
+ const texture = framebuffer["colorTexture"];
144
+ const result = await readback.readTexture(
145
+ texture,
146
+ x,
147
+ /**
148
+ * Origin is at lower-left corner. Width / height is already multiplied by dpr.
149
+ * WebGPU needs flipY
150
+ */
151
+ this.viewportOrigin === import_g_device_api.ViewportOrigin.LOWER_LEFT ? y : this.height - y,
152
+ width,
153
+ height,
154
+ new Uint8Array(width * height * 4)
155
+ );
156
+ if (this.viewportOrigin !== import_g_device_api.ViewportOrigin.LOWER_LEFT) {
157
+ for (let j = 0; j < result.length; j += 4) {
158
+ const t = result[j];
159
+ result[j] = result[j + 2];
160
+ result[j + 2] = t;
161
+ }
162
+ }
163
+ readback.destroy();
164
+ return result;
100
165
  };
101
166
  this.getViewportSize = () => {
102
167
  return {
@@ -121,6 +186,7 @@ var DeviceRendererService = class {
121
186
  buffer.destroy();
122
187
  });
123
188
  this.device.destroy();
189
+ this.renderCache.destroy();
124
190
  };
125
191
  }
126
192
  async init(canvas, cfg) {
@@ -145,34 +211,45 @@ var DeviceRendererService = class {
145
211
  swapChain.configureSwapChain(canvas.width, canvas.height);
146
212
  this.device = swapChain.getDevice();
147
213
  this.swapChain = swapChain;
214
+ this.renderCache = new import_DeviceCache.RenderCache(this.device);
148
215
  this.currentFramebuffer = null;
216
+ this.viewportOrigin = this.device.queryVendorInfo().viewportOrigin;
149
217
  const gl = this.device["gl"];
150
218
  this.extensionObject = {
151
219
  // @ts-ignore
152
220
  OES_texture_float: !(0, import_webgl.isWebGL2)(gl) && this.device["OES_texture_float"]
153
221
  };
222
+ this.createMainColorDepthRT(canvas.width, canvas.height);
223
+ }
224
+ createMainColorDepthRT(width, height) {
225
+ if (this.mainColorRT) {
226
+ this.mainColorRT.destroy();
227
+ }
228
+ if (this.mainDepthRT) {
229
+ this.mainDepthRT.destroy();
230
+ }
154
231
  this.mainColorRT = this.device.createRenderTargetFromTexture(
155
232
  this.device.createTexture({
156
233
  format: import_g_device_api.Format.U8_RGBA_RT,
157
- width: canvas.width,
158
- height: canvas.height,
234
+ width,
235
+ height,
159
236
  usage: import_g_device_api.TextureUsage.RENDER_TARGET
160
237
  })
161
238
  );
162
239
  this.mainDepthRT = this.device.createRenderTargetFromTexture(
163
240
  this.device.createTexture({
164
241
  format: import_g_device_api.Format.D24_S8,
165
- width: canvas.width,
166
- height: canvas.height,
242
+ width,
243
+ height,
167
244
  usage: import_g_device_api.TextureUsage.RENDER_TARGET
168
245
  })
169
246
  );
170
247
  }
171
248
  beginFrame() {
249
+ this.device.beginFrame();
172
250
  const { currentFramebuffer, swapChain, mainColorRT, mainDepthRT } = this;
173
- const onscreenTexture = swapChain.getOnscreenTexture();
174
251
  const colorAttachment = currentFramebuffer ? currentFramebuffer["colorRenderTarget"] : mainColorRT;
175
- const colorResolveTo = currentFramebuffer ? null : onscreenTexture;
252
+ const colorResolveTo = currentFramebuffer ? null : swapChain.getOnscreenTexture();
176
253
  const depthStencilAttachment = currentFramebuffer ? currentFramebuffer["depthRenderTarget"] : mainDepthRT;
177
254
  const { color = [0, 0, 0, 0], depth = 1, stencil = 0 } = (
178
255
  // @ts-ignore
@@ -190,6 +267,8 @@ var DeviceRendererService = class {
190
267
  colorAttachment: [colorAttachment],
191
268
  colorResolveTo: [colorResolveTo],
192
269
  colorClearColor: [colorClearColor],
270
+ // colorStore: [!!currentFramebuffer],
271
+ colorStore: [true],
193
272
  depthStencilAttachment,
194
273
  depthClearValue,
195
274
  stencilClearValue
@@ -198,6 +277,7 @@ var DeviceRendererService = class {
198
277
  }
199
278
  endFrame() {
200
279
  this.device.submitPass(this.renderPass);
280
+ this.device.endFrame();
201
281
  }
202
282
  getPointSizeRange() {
203
283
  const gl = this.device["gl"];
@@ -0,0 +1,113 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/device/utils/HashMap.ts
20
+ var HashMap_exports = {};
21
+ __export(HashMap_exports, {
22
+ HashMap: () => HashMap,
23
+ hashCodeNumberFinish: () => hashCodeNumberFinish,
24
+ hashCodeNumberUpdate: () => hashCodeNumberUpdate,
25
+ nullHashFunc: () => nullHashFunc
26
+ });
27
+ module.exports = __toCommonJS(HashMap_exports);
28
+ function hashCodeNumberUpdate(hash, v = 0) {
29
+ hash += v;
30
+ hash += hash << 10;
31
+ hash += hash >>> 6;
32
+ return hash >>> 0;
33
+ }
34
+ function hashCodeNumberFinish(hash) {
35
+ hash += hash << 3;
36
+ hash ^= hash >>> 11;
37
+ hash += hash << 15;
38
+ return hash >>> 0;
39
+ }
40
+ function nullHashFunc(k) {
41
+ return 0;
42
+ }
43
+ var HashBucket = class {
44
+ constructor() {
45
+ this.keys = [];
46
+ this.values = [];
47
+ }
48
+ };
49
+ var HashMap = class {
50
+ constructor(keyEqualFunc, keyHashFunc) {
51
+ this.keyEqualFunc = keyEqualFunc;
52
+ this.keyHashFunc = keyHashFunc;
53
+ this.buckets = /* @__PURE__ */ new Map();
54
+ }
55
+ findBucketIndex(bucket, k) {
56
+ for (let i = 0; i < bucket.keys.length; i++)
57
+ if (this.keyEqualFunc(k, bucket.keys[i]))
58
+ return i;
59
+ return -1;
60
+ }
61
+ findBucket(k) {
62
+ const bw = this.keyHashFunc(k);
63
+ return this.buckets.get(bw);
64
+ }
65
+ get(k) {
66
+ const bucket = this.findBucket(k);
67
+ if (bucket === void 0)
68
+ return null;
69
+ const bi = this.findBucketIndex(bucket, k);
70
+ if (bi < 0)
71
+ return null;
72
+ return bucket.values[bi];
73
+ }
74
+ add(k, v) {
75
+ const bw = this.keyHashFunc(k);
76
+ if (this.buckets.get(bw) === void 0)
77
+ this.buckets.set(bw, new HashBucket());
78
+ const bucket = this.buckets.get(bw);
79
+ bucket.keys.push(k);
80
+ bucket.values.push(v);
81
+ }
82
+ delete(k) {
83
+ const bucket = this.findBucket(k);
84
+ if (bucket === void 0)
85
+ return;
86
+ const bi = this.findBucketIndex(bucket, k);
87
+ if (bi === -1)
88
+ return;
89
+ bucket.keys.splice(bi, 1);
90
+ bucket.values.splice(bi, 1);
91
+ }
92
+ clear() {
93
+ this.buckets.clear();
94
+ }
95
+ size() {
96
+ let acc = 0;
97
+ for (const bucket of this.buckets.values())
98
+ acc += bucket.values.length;
99
+ return acc;
100
+ }
101
+ *values() {
102
+ for (const bucket of this.buckets.values())
103
+ for (let j = bucket.values.length - 1; j >= 0; j--)
104
+ yield bucket.values[j];
105
+ }
106
+ };
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ HashMap,
110
+ hashCodeNumberFinish,
111
+ hashCodeNumberUpdate,
112
+ nullHashFunc
113
+ });
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/device/utils/typedarray.ts
20
20
  var typedarray_exports = {};
21
21
  __export(typedarray_exports, {
22
+ extend3ChannelsTo4: () => extend3ChannelsTo4,
22
23
  isTypedArray: () => isTypedArray
23
24
  });
24
25
  module.exports = __toCommonJS(typedarray_exports);
@@ -37,7 +38,21 @@ var dtypes = {
37
38
  function isTypedArray(x) {
38
39
  return Object.prototype.toString.call(x) in dtypes;
39
40
  }
41
+ function extend3ChannelsTo4(array, valueToInsert) {
42
+ const originalLength = array.length;
43
+ const insertCount = Math.ceil(originalLength / 3);
44
+ const newLength = originalLength + insertCount;
45
+ const newArray = new Float32Array(newLength);
46
+ for (let i = 0; i < newLength; i += 4) {
47
+ newArray[i] = array[i / 4 * 3];
48
+ newArray[i + 1] = array[i / 4 * 3 + 1];
49
+ newArray[i + 2] = array[i / 4 * 3 + 2];
50
+ newArray[i + 3] = valueToInsert;
51
+ }
52
+ return newArray;
53
+ }
40
54
  // Annotate the CommonJS export names for ESM import in node:
41
55
  0 && (module.exports = {
56
+ extend3ChannelsTo4,
42
57
  isTypedArray
43
58
  });
package/lib/regl/index.js CHANGED
@@ -67,6 +67,11 @@ var ReglRendererService = class {
67
67
  framebuffer: framebuffer ? framebuffer.get() : null
68
68
  })(drawCommands);
69
69
  };
70
+ this.useFramebufferAsync = async (framebuffer, drawCommands) => {
71
+ this.gl({
72
+ framebuffer: framebuffer ? framebuffer.get() : null
73
+ })(drawCommands);
74
+ };
70
75
  this.clear = (options) => {
71
76
  var _a;
72
77
  const { color, depth, stencil, framebuffer = null } = options;
@@ -102,6 +107,9 @@ var ReglRendererService = class {
102
107
  }
103
108
  return this.gl.read(readPixelsOptions);
104
109
  };
110
+ this.readPixelsAsync = async (options) => {
111
+ return this.readPixels(options);
112
+ };
105
113
  this.getViewportSize = () => {
106
114
  return {
107
115
  width: this.gl._gl.drawingBufferWidth,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/l7-renderer",
3
- "version": "2.20.13",
3
+ "version": "2.20.15",
4
4
  "description": "",
5
5
  "license": "ISC",
6
6
  "author": "xiaoiver",
@@ -24,20 +24,20 @@
24
24
  "tsc": "tsc --project tsconfig.build.json"
25
25
  },
26
26
  "dependencies": {
27
- "@antv/g-device-api": "^1.4.10",
28
- "@antv/l7-core": "2.20.13",
29
- "@antv/l7-utils": "2.20.13",
27
+ "@antv/g-device-api": "^1.6.4",
28
+ "@antv/l7-core": "2.20.15",
29
+ "@antv/l7-utils": "2.20.15",
30
30
  "@babel/runtime": "^7.7.7",
31
31
  "inversify": "^5.0.1",
32
32
  "reflect-metadata": "^0.2.1",
33
33
  "regl": "1.6.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@antv/l7-test-utils": "2.20.13",
36
+ "@antv/l7-test-utils": "2.20.15",
37
37
  "gl": "^6.0.2"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "9487cca3bdd14eb2fc81b310e4eae5d30a30496f"
42
+ "gitHead": "283c12854a06cd2181552d6a9cf00d3e34bbd58e"
43
43
  }