@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.
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 (_ref) {
73
- var x = _ref.x,
74
- y = _ref.y,
75
- width = _ref.width,
76
- height = _ref.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 _callee(canvas, cfg, gl) {
171
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(canvas, cfg, gl) {
138
172
  var _this2 = this;
139
- return _regeneratorRuntime.wrap(function _callee$(_context) {
140
- while (1) switch (_context.prev = _context.next) {
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
- _context.next = 5;
179
+ _context3.next = 5;
146
180
  break;
147
181
  }
148
182
  this.gl = gl;
149
- _context.next = 8;
183
+ _context3.next = 8;
150
184
  break;
151
185
  case 5:
152
- _context.next = 7;
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 = _context.sent;
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 _context.stop();
224
+ return _context3.stop();
191
225
  }
192
- }, _callee, this);
226
+ }, _callee3, this);
193
227
  }));
194
- function init(_x, _x2, _x3) {
228
+ function init(_x4, _x5, _x6) {
195
229
  return _init.apply(this, arguments);
196
230
  }
197
231
  return init;
@@ -0,0 +1,212 @@
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/DeviceCache.ts
20
+ var DeviceCache_exports = {};
21
+ __export(DeviceCache_exports, {
22
+ RenderCache: () => RenderCache
23
+ });
24
+ module.exports = __toCommonJS(DeviceCache_exports);
25
+ var import_g_device_api = require("@antv/g-device-api");
26
+ var import_HashMap = require("./utils/HashMap");
27
+ function blendStateHash(hash, a) {
28
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.blendMode);
29
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.blendSrcFactor);
30
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.blendDstFactor);
31
+ return hash;
32
+ }
33
+ function attachmentStateHash(hash, a) {
34
+ hash = blendStateHash(hash, a.rgbBlendState);
35
+ hash = blendStateHash(hash, a.alphaBlendState);
36
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.channelWriteMask);
37
+ return hash;
38
+ }
39
+ function colorHash(hash, a) {
40
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(
41
+ hash,
42
+ a.r << 24 | a.g << 16 | a.b << 8 | a.a
43
+ );
44
+ return hash;
45
+ }
46
+ function megaStateDescriptorHash(hash, a) {
47
+ var _a, _b, _c, _d, _e, _f, _g, _h;
48
+ for (let i = 0; i < a.attachmentsState.length; i++)
49
+ hash = attachmentStateHash(hash, a.attachmentsState[i]);
50
+ hash = colorHash(hash, a.blendConstant || import_g_device_api.TransparentBlack);
51
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.depthCompare);
52
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.depthWrite ? 1 : 0);
53
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_a = a.stencilFront) == null ? void 0 : _a.compare);
54
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_b = a.stencilFront) == null ? void 0 : _b.passOp);
55
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_c = a.stencilFront) == null ? void 0 : _c.failOp);
56
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_d = a.stencilFront) == null ? void 0 : _d.depthFailOp);
57
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_e = a.stencilBack) == null ? void 0 : _e.compare);
58
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_f = a.stencilBack) == null ? void 0 : _f.passOp);
59
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_g = a.stencilBack) == null ? void 0 : _g.failOp);
60
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, (_h = a.stencilBack) == null ? void 0 : _h.depthFailOp);
61
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.stencilWrite ? 1 : 0);
62
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.cullMode);
63
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.frontFace ? 1 : 0);
64
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.polygonOffset ? 1 : 0);
65
+ return hash;
66
+ }
67
+ function renderPipelineDescriptorHash(a) {
68
+ let hash = 0;
69
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.program.id);
70
+ if (a.inputLayout !== null)
71
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.inputLayout.id);
72
+ hash = megaStateDescriptorHash(hash, a.megaStateDescriptor);
73
+ for (let i = 0; i < a.colorAttachmentFormats.length; i++)
74
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.colorAttachmentFormats[i] || 0);
75
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, a.depthStencilAttachmentFormat || 0);
76
+ return (0, import_HashMap.hashCodeNumberFinish)(hash);
77
+ }
78
+ function bindingsDescriptorHash(a) {
79
+ let hash = 0;
80
+ if (a.samplerBindings) {
81
+ for (let i = 0; i < a.samplerBindings.length; i++) {
82
+ const binding = a.samplerBindings[i];
83
+ if (binding !== null && binding.texture !== null)
84
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.texture.id);
85
+ }
86
+ }
87
+ if (a.uniformBufferBindings) {
88
+ for (let i = 0; i < a.uniformBufferBindings.length; i++) {
89
+ const binding = a.uniformBufferBindings[i];
90
+ if (binding !== null && binding.buffer !== null) {
91
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.buffer.id);
92
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.binding);
93
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.offset);
94
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.size);
95
+ }
96
+ }
97
+ }
98
+ if (a.storageBufferBindings) {
99
+ for (let i = 0; i < a.storageBufferBindings.length; i++) {
100
+ const binding = a.storageBufferBindings[i];
101
+ if (binding !== null && binding.buffer !== null) {
102
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.buffer.id);
103
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.binding);
104
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.offset);
105
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.size);
106
+ }
107
+ }
108
+ }
109
+ if (a.storageTextureBindings) {
110
+ for (let i = 0; i < a.storageTextureBindings.length; i++) {
111
+ const binding = a.storageTextureBindings[i];
112
+ if (binding !== null && binding.texture !== null) {
113
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.texture.id);
114
+ hash = (0, import_HashMap.hashCodeNumberUpdate)(hash, binding.binding);
115
+ }
116
+ }
117
+ }
118
+ return (0, import_HashMap.hashCodeNumberFinish)(hash);
119
+ }
120
+ function programDescriptorEquals(a, b) {
121
+ var _a, _b, _c, _d;
122
+ return ((_a = a.vertex) == null ? void 0 : _a.glsl) === ((_b = b.vertex) == null ? void 0 : _b.glsl) && ((_c = a.fragment) == null ? void 0 : _c.glsl) === ((_d = b.fragment) == null ? void 0 : _d.glsl);
123
+ }
124
+ function programDescriptorCopy(a) {
125
+ var _a, _b;
126
+ return {
127
+ vertex: {
128
+ glsl: (_a = a.vertex) == null ? void 0 : _a.glsl
129
+ },
130
+ fragment: {
131
+ glsl: (_b = a.fragment) == null ? void 0 : _b.glsl
132
+ }
133
+ };
134
+ }
135
+ var RenderCache = class {
136
+ constructor(device) {
137
+ this.device = device;
138
+ this.bindingsCache = new import_HashMap.HashMap(
139
+ import_g_device_api.bindingsDescriptorEquals,
140
+ bindingsDescriptorHash
141
+ );
142
+ this.renderPipelinesCache = new import_HashMap.HashMap(import_g_device_api.renderPipelineDescriptorEquals, renderPipelineDescriptorHash);
143
+ this.inputLayoutsCache = new import_HashMap.HashMap(
144
+ import_g_device_api.inputLayoutDescriptorEquals,
145
+ import_HashMap.nullHashFunc
146
+ );
147
+ this.programCache = new import_HashMap.HashMap(
148
+ programDescriptorEquals,
149
+ import_HashMap.nullHashFunc
150
+ );
151
+ }
152
+ createBindings(descriptor) {
153
+ var _a;
154
+ let bindings = this.bindingsCache.get(descriptor);
155
+ if (bindings === null) {
156
+ const descriptorCopy = (0, import_g_device_api.bindingsDescriptorCopy)(descriptor);
157
+ descriptorCopy.uniformBufferBindings = (_a = descriptorCopy.uniformBufferBindings) == null ? void 0 : _a.filter(
158
+ ({ size }) => size && size > 0
159
+ );
160
+ bindings = this.device.createBindings(descriptorCopy);
161
+ this.bindingsCache.add(descriptorCopy, bindings);
162
+ }
163
+ return bindings;
164
+ }
165
+ createRenderPipeline(descriptor) {
166
+ let renderPipeline = this.renderPipelinesCache.get(descriptor);
167
+ if (renderPipeline === null) {
168
+ const descriptorCopy = (0, import_g_device_api.renderPipelineDescriptorCopy)(descriptor);
169
+ descriptorCopy.colorAttachmentFormats = descriptorCopy.colorAttachmentFormats.filter((f) => f);
170
+ renderPipeline = this.device.createRenderPipeline(descriptorCopy);
171
+ this.renderPipelinesCache.add(descriptorCopy, renderPipeline);
172
+ }
173
+ return renderPipeline;
174
+ }
175
+ createInputLayout(descriptor) {
176
+ descriptor.vertexBufferDescriptors = descriptor.vertexBufferDescriptors.filter((d) => !!d);
177
+ let inputLayout = this.inputLayoutsCache.get(descriptor);
178
+ if (inputLayout === null) {
179
+ const descriptorCopy = (0, import_g_device_api.inputLayoutDescriptorCopy)(descriptor);
180
+ inputLayout = this.device.createInputLayout(descriptorCopy);
181
+ this.inputLayoutsCache.add(descriptorCopy, inputLayout);
182
+ }
183
+ return inputLayout;
184
+ }
185
+ createProgram(descriptor) {
186
+ let program = this.programCache.get(descriptor);
187
+ if (program === null) {
188
+ const descriptorCopy = programDescriptorCopy(descriptor);
189
+ program = this.device.createProgram(descriptor);
190
+ this.programCache.add(descriptorCopy, program);
191
+ }
192
+ return program;
193
+ }
194
+ destroy() {
195
+ for (const bindings of this.bindingsCache.values())
196
+ bindings.destroy();
197
+ for (const renderPipeline of this.renderPipelinesCache.values())
198
+ renderPipeline.destroy();
199
+ for (const inputLayout of this.inputLayoutsCache.values())
200
+ inputLayout.destroy();
201
+ for (const program of this.programCache.values())
202
+ program.destroy();
203
+ this.bindingsCache.clear();
204
+ this.renderPipelinesCache.clear();
205
+ this.inputLayoutsCache.clear();
206
+ this.programCache.clear();
207
+ }
208
+ };
209
+ // Annotate the CommonJS export names for ESM import in node:
210
+ 0 && (module.exports = {
211
+ RenderCache
212
+ });
@@ -31,10 +31,13 @@ var DeviceFramebuffer = class {
31
31
  this.createColorRenderTarget();
32
32
  this.createDepthRenderTarget();
33
33
  }
34
- createColorRenderTarget() {
34
+ createColorRenderTarget(resize = false) {
35
35
  const { width, height, color } = this.options;
36
36
  if (color) {
37
37
  if ((0, import_DeviceTexture2D.isTexture2D)(color)) {
38
+ if (resize) {
39
+ color.resize({ width, height });
40
+ }
38
41
  this.colorTexture = color.get();
39
42
  this.colorRenderTarget = this.device.createRenderTargetFromTexture(
40
43
  this.colorTexture
@@ -56,10 +59,13 @@ var DeviceFramebuffer = class {
56
59
  }
57
60
  }
58
61
  }
59
- createDepthRenderTarget() {
62
+ createDepthRenderTarget(resize = false) {
60
63
  const { width, height, depth } = this.options;
61
64
  if (depth) {
62
65
  if ((0, import_DeviceTexture2D.isTexture2D)(depth)) {
66
+ if (resize) {
67
+ depth.resize({ width, height });
68
+ }
63
69
  this.depthTexture = depth.get();
64
70
  this.depthRenderTarget = this.device.createRenderTargetFromTexture(
65
71
  this.depthTexture
@@ -92,10 +98,12 @@ var DeviceFramebuffer = class {
92
98
  resize({ width, height }) {
93
99
  if (this.width !== width || this.height !== height) {
94
100
  this.destroy();
101
+ this.colorTexture.destroyed = true;
102
+ this.depthTexture.destroyed = true;
95
103
  this.options.width = width;
96
104
  this.options.height = height;
97
- this.createColorRenderTarget();
98
- this.createDepthRenderTarget();
105
+ this.createColorRenderTarget(true);
106
+ this.createDepthRenderTarget(true);
99
107
  }
100
108
  }
101
109
  };
@@ -47,17 +47,26 @@ var DeviceModel = class {
47
47
  this.destroyed = false;
48
48
  this.uniforms = {};
49
49
  this.vertexBuffers = [];
50
- const { vs, fs, attributes, uniforms, count, elements } = options;
50
+ const {
51
+ vs,
52
+ fs,
53
+ attributes,
54
+ uniforms,
55
+ count,
56
+ elements,
57
+ diagnosticDerivativeUniformityEnabled
58
+ } = options;
51
59
  this.options = options;
52
- const program = device.createProgram({
60
+ const diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? "" : this.service["viewportOrigin"] === import_g_device_api.ViewportOrigin.UPPER_LEFT ? "diagnostic(off,derivative_uniformity);" : "";
61
+ this.program = service.renderCache.createProgram({
53
62
  vertex: {
54
63
  glsl: vs
55
64
  },
56
65
  fragment: {
57
- glsl: fs
66
+ glsl: fs,
67
+ postprocess: (fs2) => diagnosticDerivativeUniformityHeader + fs2
58
68
  }
59
69
  });
60
- this.program = program;
61
70
  if (uniforms) {
62
71
  this.uniforms = this.extractUniforms(uniforms);
63
72
  }
@@ -96,10 +105,10 @@ var DeviceModel = class {
96
105
  if (elements) {
97
106
  this.indexBuffer = elements.get();
98
107
  }
99
- const inputLayout = device.createInputLayout({
108
+ const inputLayout = service.renderCache.createInputLayout({
100
109
  vertexBufferDescriptors,
101
110
  indexBufferFormat: elements ? import_g_device_api.Format.U32_R : null,
102
- program
111
+ program: this.program
103
112
  });
104
113
  this.inputLayout = inputLayout;
105
114
  this.pipeline = this.createPipeline(options);
@@ -115,6 +124,7 @@ var DeviceModel = class {
115
124
  const stencilParams = this.getStencilDrawParams({ stencil });
116
125
  const stencilEnabled = !!(stencilParams && stencilParams.enable);
117
126
  return this.device.createRenderPipeline({
127
+ // return this.service.renderCache.createRenderPipeline({
118
128
  inputLayout: this.inputLayout,
119
129
  program: this.program,
120
130
  topology: import_constants.primitiveMap[primitive],
@@ -155,11 +165,17 @@ var DeviceModel = class {
155
165
  stencilWrite: stencilEnabled,
156
166
  stencilFront: {
157
167
  compare: stencilEnabled ? stencilParams.func.cmp : import_g_device_api.CompareFunction.ALWAYS,
158
- passOp: stencilParams.opFront.zpass
168
+ passOp: stencilParams.opFront.zpass,
169
+ failOp: stencilParams.opFront.fail,
170
+ depthFailOp: stencilParams.opFront.zfail,
171
+ mask: stencilParams.opFront.mask
159
172
  },
160
173
  stencilBack: {
161
174
  compare: stencilEnabled ? stencilParams.func.cmp : import_g_device_api.CompareFunction.ALWAYS,
162
- passOp: stencilParams.opBack.zpass
175
+ passOp: stencilParams.opBack.zpass,
176
+ failOp: stencilParams.opBack.fail,
177
+ depthFailOp: stencilParams.opBack.zfail,
178
+ mask: stencilParams.opBack.mask
163
179
  }
164
180
  }
165
181
  });
@@ -202,14 +218,18 @@ var DeviceModel = class {
202
218
  ...this.uniforms,
203
219
  ...this.extractUniforms(uniforms)
204
220
  };
205
- const { renderPass, currentFramebuffer, width, height } = this.service;
221
+ const { renderPass, currentFramebuffer, width, height, renderCache } = this.service;
206
222
  this.pipeline = this.createPipeline(mergedOptions, pick);
223
+ const device = this.service["device"];
224
+ const tmpHeight = device["swapChainHeight"];
225
+ device["swapChainHeight"] = (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height;
207
226
  renderPass.setViewport(
208
227
  0,
209
228
  0,
210
229
  (currentFramebuffer == null ? void 0 : currentFramebuffer["width"]) || width,
211
230
  (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height
212
231
  );
232
+ device["swapChainHeight"] = tmpHeight;
213
233
  renderPass.setPipeline(this.pipeline);
214
234
  renderPass.setStencilReference(1);
215
235
  renderPass.setVertexInput(
@@ -223,7 +243,7 @@ var DeviceModel = class {
223
243
  } : null
224
244
  );
225
245
  if (uniformBuffers) {
226
- this.bindings = this.device.createBindings({
246
+ this.bindings = renderCache.createBindings({
227
247
  pipeline: this.pipeline,
228
248
  uniformBufferBindings: uniformBuffers.map((uniformBuffer, i) => {
229
249
  const buffer = uniformBuffer;
@@ -311,11 +331,11 @@ var DeviceModel = class {
311
331
  }) {
312
332
  const {
313
333
  enable,
314
- mask = -1,
334
+ mask = 4294967295,
315
335
  func = {
316
336
  cmp: import_l7_core.gl.ALWAYS,
317
337
  ref: 0,
318
- mask: -1
338
+ mask: 4294967295
319
339
  },
320
340
  opFront = {
321
341
  fail: import_l7_core.gl.KEEP,
@@ -338,12 +358,14 @@ var DeviceModel = class {
338
358
  opFront: {
339
359
  fail: import_constants.stencilOpMap[opFront.fail],
340
360
  zfail: import_constants.stencilOpMap[opFront.zfail],
341
- zpass: import_constants.stencilOpMap[opFront.zpass]
361
+ zpass: import_constants.stencilOpMap[opFront.zpass],
362
+ mask: func.mask
342
363
  },
343
364
  opBack: {
344
365
  fail: import_constants.stencilOpMap[opBack.fail],
345
366
  zfail: import_constants.stencilOpMap[opBack.zfail],
346
- zpass: import_constants.stencilOpMap[opBack.zpass]
367
+ zpass: import_constants.stencilOpMap[opBack.zpass],
368
+ mask: func.mask
347
369
  }
348
370
  };
349
371
  }
@@ -26,42 +26,71 @@ module.exports = __toCommonJS(DeviceTexture2D_exports);
26
26
  var import_g_device_api = require("@antv/g-device-api");
27
27
  var import_l7_core = require("@antv/l7-core");
28
28
  var import_constants = require("./constants");
29
+ var import_typedarray = require("./utils/typedarray");
29
30
  function isTexture2D(t) {
30
31
  return !!(t && t["texture"]);
31
32
  }
32
33
  var DeviceTexture2D = class {
33
34
  constructor(device, options) {
35
+ this.device = device;
36
+ this.options = options;
34
37
  this.isDestroy = false;
35
38
  const {
36
- data,
39
+ wrapS = import_l7_core.gl.CLAMP_TO_EDGE,
40
+ wrapT = import_l7_core.gl.CLAMP_TO_EDGE,
41
+ aniso,
42
+ mipmap = false,
43
+ // premultiplyAlpha = false,
44
+ mag = import_l7_core.gl.NEAREST,
45
+ min = import_l7_core.gl.NEAREST
46
+ } = options;
47
+ this.createTexture(options);
48
+ this.sampler = device.createSampler({
49
+ addressModeU: import_constants.wrapModeMap[wrapS],
50
+ addressModeV: import_constants.wrapModeMap[wrapT],
51
+ minFilter: min === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
52
+ magFilter: mag === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
53
+ mipmapFilter: import_g_device_api.MipmapFilterMode.NO_MIP,
54
+ // lodMinClamp: 0,
55
+ // lodMaxClamp: 0,
56
+ maxAnisotropy: aniso
57
+ });
58
+ }
59
+ createTexture(options) {
60
+ const {
37
61
  type = import_l7_core.gl.UNSIGNED_BYTE,
38
62
  width,
39
63
  height,
40
64
  flipY = false,
41
65
  format = import_l7_core.gl.RGBA,
42
- wrapS = import_l7_core.gl.CLAMP_TO_EDGE,
43
- wrapT = import_l7_core.gl.CLAMP_TO_EDGE,
44
- aniso = 0,
66
+ aniso,
45
67
  alignment = 1,
46
68
  usage = import_l7_core.TextureUsage.SAMPLED,
47
- mipmap = false,
48
69
  // premultiplyAlpha = false,
49
- mag = import_l7_core.gl.NEAREST,
50
- min = import_l7_core.gl.NEAREST
70
+ unorm = false,
51
71
  // colorSpace = gl.BROWSER_DEFAULT_WEBGL,
52
72
  // x = 0,
53
73
  // y = 0,
54
74
  // copy = false,
75
+ label
55
76
  } = options;
77
+ let { data } = options;
56
78
  this.width = width;
57
79
  this.height = height;
58
80
  let pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
59
81
  if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.RGBA) {
60
- pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
82
+ pixelFormat = unorm ? import_g_device_api.Format.U8_RGBA_NORM : import_g_device_api.Format.U8_RGBA_RT;
61
83
  } else if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.LUMINANCE) {
62
84
  pixelFormat = import_g_device_api.Format.U8_LUMINANCE;
63
85
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGB) {
64
- pixelFormat = import_g_device_api.Format.F32_RGB;
86
+ if (this.device.queryVendorInfo().platformString === "WebGPU") {
87
+ if (data) {
88
+ data = (0, import_typedarray.extend3ChannelsTo4)(data, 0);
89
+ }
90
+ pixelFormat = import_g_device_api.Format.F32_RGBA;
91
+ } else {
92
+ pixelFormat = import_g_device_api.Format.F32_RGB;
93
+ }
65
94
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGBA) {
66
95
  pixelFormat = import_g_device_api.Format.F32_RGBA;
67
96
  } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RED) {
@@ -69,7 +98,7 @@ var DeviceTexture2D = class {
69
98
  } else {
70
99
  throw new Error(`create texture error, type: ${type}, format: ${format}`);
71
100
  }
72
- this.texture = device.createTexture({
101
+ this.texture = this.device.createTexture({
73
102
  format: pixelFormat,
74
103
  width,
75
104
  height,
@@ -78,21 +107,15 @@ var DeviceTexture2D = class {
78
107
  unpackFlipY: flipY,
79
108
  packAlignment: alignment
80
109
  },
81
- mipLevelCount: usage === import_l7_core.TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0
110
+ // mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
111
+ mipLevelCount: 1
82
112
  });
113
+ if (label) {
114
+ this.device.setResourceName(this.texture, label);
115
+ }
83
116
  if (data) {
84
117
  this.texture.setImageData([data]);
85
118
  }
86
- this.sampler = device.createSampler({
87
- addressModeU: import_constants.wrapModeMap[wrapS],
88
- addressModeV: import_constants.wrapModeMap[wrapT],
89
- minFilter: min === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
90
- magFilter: mag === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
91
- mipmapFilter: import_g_device_api.MipmapFilterMode.NO_MIP,
92
- // lodMinClamp: 0,
93
- // lodMaxClamp: 0,
94
- maxAnisotropy: aniso
95
- });
96
119
  }
97
120
  get() {
98
121
  return this.texture;
@@ -104,15 +127,20 @@ var DeviceTexture2D = class {
104
127
  bind() {
105
128
  }
106
129
  resize({ width, height }) {
107
- this.width = width;
108
- this.height = height;
130
+ if (this.width !== width || this.height !== height) {
131
+ this.destroy();
132
+ }
133
+ this.options.width = width;
134
+ this.options.height = height;
135
+ this.createTexture(this.options);
136
+ this.isDestroy = false;
109
137
  }
110
138
  getSize() {
111
139
  return [this.width, this.height];
112
140
  }
113
141
  destroy() {
114
142
  var _a;
115
- if (!this.isDestroy) {
143
+ if (!this.isDestroy && !this.texture.destroyed) {
116
144
  (_a = this.texture) == null ? void 0 : _a.destroy();
117
145
  }
118
146
  this.isDestroy = true;