@antv/l7-renderer 2.25.7 → 2.25.9

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.
Files changed (93) hide show
  1. package/es/device/DeviceAttribute.d.ts +13 -0
  2. package/es/device/DeviceAttribute.js +30 -0
  3. package/es/device/DeviceBuffer.d.ts +18 -0
  4. package/es/device/DeviceBuffer.js +51 -0
  5. package/es/device/DeviceCache.d.ts +14 -0
  6. package/es/device/DeviceCache.js +198 -0
  7. package/es/device/DeviceElements.d.ts +13 -0
  8. package/es/device/DeviceElements.js +42 -0
  9. package/es/device/DeviceFramebuffer.d.ts +24 -0
  10. package/es/device/DeviceFramebuffer.js +81 -0
  11. package/es/device/DeviceModel.d.ts +61 -0
  12. package/es/device/DeviceModel.js +488 -0
  13. package/es/device/DeviceTexture2D.d.ts +23 -0
  14. package/es/device/DeviceTexture2D.js +132 -0
  15. package/es/device/constants.d.ts +35 -0
  16. package/es/device/constants.js +117 -0
  17. package/es/device/index.d.ts +68 -0
  18. package/es/device/index.js +311 -0
  19. package/es/device/utils/HashMap.d.ts +24 -0
  20. package/es/device/utils/HashMap.js +86 -0
  21. package/es/device/utils/pipeline.d.ts +1 -0
  22. package/es/device/utils/pipeline.js +6 -0
  23. package/es/device/utils/typedarray.d.ts +7 -0
  24. package/es/device/utils/typedarray.js +33 -0
  25. package/es/device/utils/webgl.d.ts +1 -0
  26. package/es/device/utils/webgl.js +10 -0
  27. package/es/index.d.ts +3 -0
  28. package/es/index.js +7 -0
  29. package/es/regl/ReglAttribute.d.ts +16 -0
  30. package/es/regl/ReglAttribute.js +29 -0
  31. package/es/regl/ReglBuffer.d.ts +17 -0
  32. package/es/regl/ReglBuffer.js +33 -0
  33. package/es/regl/ReglElements.d.ts +14 -0
  34. package/es/regl/ReglElements.js +27 -0
  35. package/es/regl/ReglFramebuffer.d.ts +16 -0
  36. package/es/regl/ReglFramebuffer.js +31 -0
  37. package/es/regl/ReglModel.d.ts +46 -0
  38. package/es/regl/ReglModel.js +302 -0
  39. package/es/regl/ReglRenderbuffer.d.ts +16 -0
  40. package/es/regl/ReglRenderbuffer.js +24 -0
  41. package/es/regl/ReglTexture2D.d.ts +22 -0
  42. package/es/regl/ReglTexture2D.js +94 -0
  43. package/es/regl/constants.d.ts +43 -0
  44. package/es/regl/constants.js +133 -0
  45. package/es/regl/index.d.ts +56 -0
  46. package/es/regl/index.js +227 -0
  47. package/lib/device/DeviceAttribute.d.ts +13 -0
  48. package/lib/device/DeviceAttribute.js +50 -0
  49. package/lib/device/DeviceBuffer.d.ts +18 -0
  50. package/lib/device/DeviceBuffer.js +71 -0
  51. package/lib/device/DeviceCache.d.ts +14 -0
  52. package/lib/device/DeviceCache.js +214 -0
  53. package/lib/device/DeviceElements.d.ts +13 -0
  54. package/lib/device/DeviceElements.js +62 -0
  55. package/lib/device/DeviceFramebuffer.d.ts +24 -0
  56. package/lib/device/DeviceFramebuffer.js +101 -0
  57. package/lib/device/DeviceModel.d.ts +61 -0
  58. package/lib/device/DeviceModel.js +495 -0
  59. package/lib/device/DeviceTexture2D.d.ts +23 -0
  60. package/lib/device/DeviceTexture2D.js +151 -0
  61. package/lib/device/constants.d.ts +35 -0
  62. package/lib/device/constants.js +141 -0
  63. package/lib/device/index.d.ts +68 -0
  64. package/lib/device/index.js +332 -0
  65. package/lib/device/utils/HashMap.d.ts +24 -0
  66. package/lib/device/utils/HashMap.js +113 -0
  67. package/lib/device/utils/pipeline.d.ts +1 -0
  68. package/lib/device/utils/pipeline.js +30 -0
  69. package/lib/device/utils/typedarray.d.ts +7 -0
  70. package/lib/device/utils/typedarray.js +58 -0
  71. package/lib/device/utils/webgl.d.ts +1 -0
  72. package/lib/device/utils/webgl.js +34 -0
  73. package/lib/index.d.ts +3 -0
  74. package/lib/index.js +42 -0
  75. package/lib/regl/ReglAttribute.d.ts +16 -0
  76. package/lib/regl/ReglAttribute.js +49 -0
  77. package/lib/regl/ReglBuffer.d.ts +17 -0
  78. package/lib/regl/ReglBuffer.js +53 -0
  79. package/lib/regl/ReglElements.d.ts +14 -0
  80. package/lib/regl/ReglElements.js +47 -0
  81. package/lib/regl/ReglFramebuffer.d.ts +16 -0
  82. package/lib/regl/ReglFramebuffer.js +51 -0
  83. package/lib/regl/ReglModel.d.ts +46 -0
  84. package/lib/regl/ReglModel.js +311 -0
  85. package/lib/regl/ReglRenderbuffer.d.ts +16 -0
  86. package/lib/regl/ReglRenderbuffer.js +44 -0
  87. package/lib/regl/ReglTexture2D.d.ts +22 -0
  88. package/lib/regl/ReglTexture2D.js +107 -0
  89. package/lib/regl/constants.d.ts +43 -0
  90. package/lib/regl/constants.js +170 -0
  91. package/lib/regl/index.d.ts +56 -0
  92. package/lib/regl/index.js +256 -0
  93. package/package.json +4 -4
@@ -0,0 +1,495 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
44
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
45
+
46
+ // src/device/DeviceModel.ts
47
+ var DeviceModel_exports = {};
48
+ __export(DeviceModel_exports, {
49
+ default: () => DeviceModel
50
+ });
51
+ module.exports = __toCommonJS(DeviceModel_exports);
52
+ var import_g_device_api = require("@antv/g-device-api");
53
+ var import_l7_core = require("@antv/l7-core");
54
+ var import_l7_utils = require("@antv/l7-utils");
55
+ var import_DeviceFramebuffer = __toESM(require("./DeviceFramebuffer"));
56
+ var import_DeviceTexture2D = __toESM(require("./DeviceTexture2D"));
57
+ var import_constants = require("./constants");
58
+ var { isPlainObject, isTypedArray, isNil } = import_l7_utils.lodashUtil;
59
+ var DeviceModel = class {
60
+ constructor(device, options, service) {
61
+ this.device = device;
62
+ this.options = options;
63
+ this.service = service;
64
+ this.destroyed = false;
65
+ this.uniforms = {};
66
+ this.vertexBuffers = [];
67
+ // Pipeline cache to avoid recreating pipeline on every draw call
68
+ this.pipelineCache = /* @__PURE__ */ new Map();
69
+ this.currentPipelineKey = "";
70
+ const { vs, fs, attributes, uniforms, count, elements, diagnosticDerivativeUniformityEnabled } = options;
71
+ this.options = options;
72
+ const diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? "" : this.service["viewportOrigin"] === import_g_device_api.ViewportOrigin.UPPER_LEFT ? "diagnostic(off,derivative_uniformity);" : "";
73
+ this.program = service.renderCache.createProgram({
74
+ vertex: {
75
+ glsl: vs
76
+ },
77
+ fragment: {
78
+ glsl: fs,
79
+ postprocess: (fs2) => diagnosticDerivativeUniformityHeader + fs2
80
+ }
81
+ });
82
+ if (uniforms) {
83
+ this.uniforms = this.extractUniforms(uniforms);
84
+ }
85
+ const vertexBufferDescriptors = [];
86
+ let inferredCount = 0;
87
+ Object.keys(attributes).forEach((name) => {
88
+ const attribute = attributes[name];
89
+ const buffer = attribute.get();
90
+ this.vertexBuffers.push(buffer.get());
91
+ const {
92
+ offset = 0,
93
+ stride = 0,
94
+ // TODO: normalized
95
+ size = 1,
96
+ divisor = 0,
97
+ shaderLocation = 0
98
+ } = attribute["attribute"];
99
+ vertexBufferDescriptors.push({
100
+ arrayStride: stride || size * 4,
101
+ // TODO: L7 hasn't use instanced array for now.
102
+ stepMode: import_g_device_api.VertexStepMode.VERTEX,
103
+ attributes: [
104
+ {
105
+ format: import_constants.sizeFormatMap[size],
106
+ shaderLocation,
107
+ offset,
108
+ divisor
109
+ }
110
+ ]
111
+ });
112
+ inferredCount = buffer["size"] / size;
113
+ });
114
+ if (!count) {
115
+ this.options.count = inferredCount;
116
+ }
117
+ if (elements) {
118
+ this.indexBuffer = elements.get();
119
+ }
120
+ const inputLayout = service.renderCache.createInputLayout({
121
+ vertexBufferDescriptors,
122
+ indexBufferFormat: elements ? import_g_device_api.Format.U32_R : null,
123
+ program: this.program
124
+ });
125
+ this.inputLayout = inputLayout;
126
+ this.pipeline = this.createPipeline(options);
127
+ const initialKey = this.getPipelineKey(options);
128
+ this.pipelineCache.set(initialKey, this.pipeline);
129
+ this.currentPipelineKey = initialKey;
130
+ }
131
+ /**
132
+ * 生成 Pipeline 缓存键,用于判断是否需要重新创建 Pipeline
133
+ * 包含所有影响 Pipeline 创建的参数
134
+ * 注意:当 blend/stencil 禁用时,使用简化的 key 以避免创建重复 Pipeline
135
+ */
136
+ getPipelineKey(options, pick) {
137
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J;
138
+ const { primitive = import_l7_core.gl.TRIANGLES, depth, cull, blend, stencil } = options;
139
+ let stencilKey;
140
+ if (stencil == null ? void 0 : stencil.enable) {
141
+ stencilKey = [
142
+ 1,
143
+ // enabled
144
+ (_a = stencil.mask) != null ? _a : 4294967295,
145
+ (_c = (_b = stencil.func) == null ? void 0 : _b.cmp) != null ? _c : import_l7_core.gl.ALWAYS,
146
+ (_e = (_d = stencil.func) == null ? void 0 : _d.ref) != null ? _e : 0,
147
+ (_g = (_f = stencil.func) == null ? void 0 : _f.mask) != null ? _g : 4294967295,
148
+ (_i = (_h = stencil.opFront) == null ? void 0 : _h.fail) != null ? _i : import_l7_core.gl.KEEP,
149
+ (_k = (_j = stencil.opFront) == null ? void 0 : _j.zfail) != null ? _k : import_l7_core.gl.KEEP,
150
+ (_m = (_l = stencil.opFront) == null ? void 0 : _l.zpass) != null ? _m : import_l7_core.gl.KEEP,
151
+ (_o = (_n = stencil.opBack) == null ? void 0 : _n.fail) != null ? _o : import_l7_core.gl.KEEP,
152
+ (_q = (_p = stencil.opBack) == null ? void 0 : _p.zfail) != null ? _q : import_l7_core.gl.KEEP,
153
+ (_s = (_r = stencil.opBack) == null ? void 0 : _r.zpass) != null ? _s : import_l7_core.gl.KEEP
154
+ ].join(",");
155
+ } else {
156
+ stencilKey = "0";
157
+ }
158
+ let blendKey;
159
+ if (blend == null ? void 0 : blend.enable) {
160
+ blendKey = [
161
+ 1,
162
+ // enabled
163
+ (_u = (_t = blend.func) == null ? void 0 : _t.srcRGB) != null ? _u : import_l7_core.gl.SRC_ALPHA,
164
+ (_w = (_v = blend.func) == null ? void 0 : _v.dstRGB) != null ? _w : import_l7_core.gl.ONE_MINUS_SRC_ALPHA,
165
+ (_y = (_x = blend.func) == null ? void 0 : _x.srcAlpha) != null ? _y : import_l7_core.gl.SRC_ALPHA,
166
+ (_A = (_z = blend.func) == null ? void 0 : _z.dstAlpha) != null ? _A : import_l7_core.gl.ONE_MINUS_SRC_ALPHA,
167
+ (_C = (_B = blend.equation) == null ? void 0 : _B.rgb) != null ? _C : import_l7_core.gl.FUNC_ADD,
168
+ (_E = (_D = blend.equation) == null ? void 0 : _D.alpha) != null ? _E : import_l7_core.gl.FUNC_ADD
169
+ ].join(",");
170
+ } else {
171
+ blendKey = "0";
172
+ }
173
+ const parts = [
174
+ `primitive:${primitive}`,
175
+ `pick:${!!pick}`,
176
+ `depth:${(_F = depth == null ? void 0 : depth.enable) != null ? _F : true}:${(_G = depth == null ? void 0 : depth.func) != null ? _G : import_l7_core.gl.LESS}:${(_H = depth == null ? void 0 : depth.mask) != null ? _H : true}`,
177
+ `cull:${(_I = cull == null ? void 0 : cull.enable) != null ? _I : false}:${(_J = cull == null ? void 0 : cull.face) != null ? _J : import_l7_core.gl.BACK}`,
178
+ `blend:${blendKey}`,
179
+ `stencil:${stencilKey}`
180
+ ];
181
+ return parts.join("|");
182
+ }
183
+ createPipeline(options, pick) {
184
+ var _a;
185
+ const { primitive = import_l7_core.gl.TRIANGLES, depth, cull, blend, stencil } = options;
186
+ const depthParams = this.initDepthDrawParams({ depth });
187
+ const depthEnabled = !!(depthParams && depthParams.enable);
188
+ const cullParams = this.initCullDrawParams({ cull });
189
+ const cullEnabled = !!(cullParams && cullParams.enable);
190
+ const blendParams = this.getBlendDrawParams({ blend });
191
+ const blendEnabled = !!(blendParams && blendParams.enable);
192
+ const stencilParams = this.getStencilDrawParams({ stencil });
193
+ const stencilEnabled = !!(stencilParams && stencilParams.enable);
194
+ const pipeline = this.device.createRenderPipeline({
195
+ inputLayout: this.inputLayout,
196
+ program: this.program,
197
+ topology: import_constants.primitiveMap[primitive],
198
+ colorAttachmentFormats: [import_g_device_api.Format.U8_RGBA_RT],
199
+ depthStencilAttachmentFormat: import_g_device_api.Format.D24_S8,
200
+ megaStateDescriptor: {
201
+ attachmentsState: [
202
+ pick ? {
203
+ channelWriteMask: import_g_device_api.ChannelWriteMask.ALL,
204
+ rgbBlendState: {
205
+ blendMode: import_g_device_api.BlendMode.ADD,
206
+ blendSrcFactor: import_g_device_api.BlendFactor.ONE,
207
+ blendDstFactor: import_g_device_api.BlendFactor.ZERO
208
+ },
209
+ alphaBlendState: {
210
+ blendMode: import_g_device_api.BlendMode.ADD,
211
+ blendSrcFactor: import_g_device_api.BlendFactor.ONE,
212
+ blendDstFactor: import_g_device_api.BlendFactor.ZERO
213
+ }
214
+ } : {
215
+ channelWriteMask: stencilEnabled && stencilParams.opFront.zpass === import_g_device_api.StencilOp.REPLACE ? import_g_device_api.ChannelWriteMask.NONE : import_g_device_api.ChannelWriteMask.ALL,
216
+ rgbBlendState: {
217
+ blendMode: blendEnabled && blendParams.equation.rgb || import_g_device_api.BlendMode.ADD,
218
+ blendSrcFactor: blendEnabled && blendParams.func.srcRGB || import_g_device_api.BlendFactor.SRC_ALPHA,
219
+ blendDstFactor: blendEnabled && blendParams.func.dstRGB || import_g_device_api.BlendFactor.ONE_MINUS_SRC_ALPHA
220
+ },
221
+ alphaBlendState: {
222
+ blendMode: blendEnabled && blendParams.equation.alpha || import_g_device_api.BlendMode.ADD,
223
+ blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || import_g_device_api.BlendFactor.ONE,
224
+ blendDstFactor: blendEnabled && blendParams.func.dstAlpha || import_g_device_api.BlendFactor.ONE
225
+ }
226
+ }
227
+ ],
228
+ blendConstant: blendEnabled ? import_g_device_api.TransparentBlack : void 0,
229
+ depthWrite: depthEnabled,
230
+ depthCompare: depthEnabled && depthParams.func || import_g_device_api.CompareFunction.LESS,
231
+ cullMode: cullEnabled && cullParams.face || import_g_device_api.CullMode.NONE,
232
+ stencilWrite: stencilEnabled,
233
+ stencilFront: {
234
+ compare: stencilEnabled ? stencilParams.func.cmp : import_g_device_api.CompareFunction.ALWAYS,
235
+ passOp: stencilParams.opFront.zpass,
236
+ failOp: stencilParams.opFront.fail,
237
+ depthFailOp: stencilParams.opFront.zfail,
238
+ mask: stencilParams.opFront.mask
239
+ },
240
+ stencilBack: {
241
+ compare: stencilEnabled ? stencilParams.func.cmp : import_g_device_api.CompareFunction.ALWAYS,
242
+ passOp: stencilParams.opBack.zpass,
243
+ failOp: stencilParams.opBack.fail,
244
+ depthFailOp: stencilParams.opBack.zfail,
245
+ mask: stencilParams.opBack.mask
246
+ }
247
+ }
248
+ });
249
+ if (stencilEnabled && !isNil((_a = stencil == null ? void 0 : stencil.func) == null ? void 0 : _a.ref)) {
250
+ pipeline.stencilFuncReference = stencil.func.ref;
251
+ }
252
+ return pipeline;
253
+ }
254
+ updateAttributesAndElements() {
255
+ }
256
+ /**
257
+ * No need to implement this method, you should update data on `Attribute` like this:
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * attribute.updateBuffer({
262
+ * data: [],
263
+ * offset: 0,
264
+ * });
265
+ * ```
266
+ */
267
+ updateAttributes() {
268
+ }
269
+ addUniforms(uniforms) {
270
+ this.uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(uniforms));
271
+ }
272
+ draw(options, pick) {
273
+ const mergedOptions = __spreadValues(__spreadValues({}, this.options), options);
274
+ const {
275
+ count = 0,
276
+ instances,
277
+ elements,
278
+ uniforms = {},
279
+ uniformBuffers,
280
+ textures
281
+ } = mergedOptions;
282
+ this.uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(uniforms));
283
+ const { renderPass, currentFramebuffer, width, height } = this.service;
284
+ const pipelineKey = this.getPipelineKey(mergedOptions, pick);
285
+ let cachedPipeline = this.pipelineCache.get(pipelineKey);
286
+ if (!cachedPipeline) {
287
+ cachedPipeline = this.createPipeline(mergedOptions, pick);
288
+ this.pipelineCache.set(pipelineKey, cachedPipeline);
289
+ }
290
+ this.pipeline = cachedPipeline;
291
+ this.currentPipelineKey = pipelineKey;
292
+ const device = this.service["device"];
293
+ const tmpHeight = device.swapChainHeight;
294
+ device.swapChainHeight = (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height;
295
+ renderPass.setViewport(
296
+ 0,
297
+ 0,
298
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["width"]) || width,
299
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height
300
+ );
301
+ device.swapChainHeight = tmpHeight;
302
+ renderPass.setPipeline(this.pipeline);
303
+ const extendedPipeline = this.pipeline;
304
+ if (!isNil(extendedPipeline.stencilFuncReference)) {
305
+ renderPass.setStencilReference(extendedPipeline.stencilFuncReference);
306
+ }
307
+ renderPass.setVertexInput(
308
+ this.inputLayout,
309
+ this.vertexBuffers.map((buffer) => ({
310
+ buffer
311
+ })),
312
+ elements ? {
313
+ buffer: this.indexBuffer,
314
+ offset: 0
315
+ } : null
316
+ );
317
+ if (uniformBuffers) {
318
+ this.bindings = device.createBindings({
319
+ pipeline: this.pipeline,
320
+ uniformBufferBindings: uniformBuffers.map((uniformBuffer, i) => {
321
+ const buffer = uniformBuffer;
322
+ return {
323
+ binding: i,
324
+ buffer: buffer.get(),
325
+ size: buffer["size"]
326
+ };
327
+ }),
328
+ samplerBindings: textures == null ? void 0 : textures.map((t) => ({
329
+ texture: t["texture"],
330
+ sampler: t["sampler"]
331
+ }))
332
+ });
333
+ }
334
+ if (this.bindings) {
335
+ renderPass.setBindings(this.bindings);
336
+ Object.keys(this.uniforms).forEach((uniformName) => {
337
+ const uniform = this.uniforms[uniformName];
338
+ if (uniform instanceof import_DeviceTexture2D.default) {
339
+ this.uniforms[uniformName] = uniform.get();
340
+ } else if (uniform instanceof import_DeviceFramebuffer.default) {
341
+ const renderTarget = uniform.get();
342
+ this.uniforms[uniformName] = renderTarget.texture;
343
+ }
344
+ });
345
+ this.program.setUniformsLegacy(this.uniforms);
346
+ }
347
+ if (elements) {
348
+ const indexCount = elements["count"];
349
+ if (indexCount === 0) {
350
+ renderPass.draw(count, instances);
351
+ } else {
352
+ renderPass.drawIndexed(indexCount, instances);
353
+ }
354
+ } else {
355
+ renderPass.draw(count, instances);
356
+ }
357
+ }
358
+ destroy() {
359
+ var _a, _b, _c;
360
+ (_a = this.vertexBuffers) == null ? void 0 : _a.forEach((buffer) => buffer.destroy());
361
+ (_b = this.indexBuffer) == null ? void 0 : _b.destroy();
362
+ (_c = this.bindings) == null ? void 0 : _c.destroy();
363
+ this.pipelineCache.forEach((pipeline) => pipeline.destroy());
364
+ this.pipelineCache.clear();
365
+ this.destroyed = true;
366
+ }
367
+ initDepthDrawParams({ depth }) {
368
+ if (depth) {
369
+ return {
370
+ enable: depth.enable === void 0 ? true : !!depth.enable,
371
+ mask: depth.mask === void 0 ? true : !!depth.mask,
372
+ func: import_constants.depthFuncMap[depth.func || import_l7_core.gl.LESS],
373
+ range: depth.range || [0, 1]
374
+ };
375
+ }
376
+ }
377
+ getBlendDrawParams({ blend }) {
378
+ const { enable, func, equation, color = [0, 0, 0, 0] } = blend || {};
379
+ return {
380
+ enable: !!enable,
381
+ func: {
382
+ srcRGB: import_constants.blendFuncMap[func && func.srcRGB || import_l7_core.gl.SRC_ALPHA],
383
+ srcAlpha: import_constants.blendFuncMap[func && func.srcAlpha || import_l7_core.gl.SRC_ALPHA],
384
+ dstRGB: import_constants.blendFuncMap[func && func.dstRGB || import_l7_core.gl.ONE_MINUS_SRC_ALPHA],
385
+ dstAlpha: import_constants.blendFuncMap[func && func.dstAlpha || import_l7_core.gl.ONE_MINUS_SRC_ALPHA]
386
+ },
387
+ equation: {
388
+ rgb: import_constants.blendEquationMap[equation && equation.rgb || import_l7_core.gl.FUNC_ADD],
389
+ alpha: import_constants.blendEquationMap[equation && equation.alpha || import_l7_core.gl.FUNC_ADD]
390
+ },
391
+ color
392
+ };
393
+ }
394
+ /**
395
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
396
+ */
397
+ getStencilDrawParams({ stencil }) {
398
+ const {
399
+ enable,
400
+ mask = 4294967295,
401
+ func = {
402
+ cmp: import_l7_core.gl.ALWAYS,
403
+ ref: 0,
404
+ mask: 4294967295
405
+ },
406
+ opFront = {
407
+ fail: import_l7_core.gl.KEEP,
408
+ zfail: import_l7_core.gl.KEEP,
409
+ zpass: import_l7_core.gl.KEEP
410
+ },
411
+ opBack = {
412
+ fail: import_l7_core.gl.KEEP,
413
+ zfail: import_l7_core.gl.KEEP,
414
+ zpass: import_l7_core.gl.KEEP
415
+ }
416
+ } = stencil || {};
417
+ return {
418
+ enable: !!enable,
419
+ mask,
420
+ func: __spreadProps(__spreadValues({}, func), {
421
+ cmp: import_constants.stencilFuncMap[func.cmp]
422
+ }),
423
+ opFront: {
424
+ fail: import_constants.stencilOpMap[opFront.fail],
425
+ zfail: import_constants.stencilOpMap[opFront.zfail],
426
+ zpass: import_constants.stencilOpMap[opFront.zpass],
427
+ mask: func.mask
428
+ },
429
+ opBack: {
430
+ fail: import_constants.stencilOpMap[opBack.fail],
431
+ zfail: import_constants.stencilOpMap[opBack.zfail],
432
+ zpass: import_constants.stencilOpMap[opBack.zpass],
433
+ mask: func.mask
434
+ }
435
+ };
436
+ }
437
+ /**
438
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
439
+ */
440
+ initCullDrawParams({ cull }) {
441
+ if (cull) {
442
+ const { enable, face = import_l7_core.gl.BACK } = cull;
443
+ return {
444
+ enable: !!enable,
445
+ face: import_constants.cullFaceMap[face]
446
+ };
447
+ }
448
+ }
449
+ /**
450
+ * 考虑结构体命名, eg:
451
+ * a: { b: 1 } -> 'a.b'
452
+ * a: [ { b: 1 } ] -> 'a[0].b'
453
+ */
454
+ extractUniforms(uniforms) {
455
+ const extractedUniforms = {};
456
+ Object.keys(uniforms).forEach((uniformName) => {
457
+ this.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, "");
458
+ });
459
+ return extractedUniforms;
460
+ }
461
+ extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
462
+ const isPrimitiveType = uniformValue === null || typeof uniformValue === "string" || // 包括空字符串
463
+ typeof uniformValue === "number" || typeof uniformValue === "boolean" || Array.isArray(uniformValue) && typeof uniformValue[0] === "number" || isTypedArray(uniformValue);
464
+ if (isPrimitiveType || uniformValue !== null && typeof uniformValue === "object" && "resize" in uniformValue) {
465
+ uniforms[`${prefix && prefix + "."}${uniformName}`] = uniformValue;
466
+ return;
467
+ }
468
+ if (isPlainObject(uniformValue)) {
469
+ const obj = uniformValue;
470
+ Object.keys(obj).forEach((childName) => {
471
+ this.extractUniformsRecursively(
472
+ childName,
473
+ obj[childName],
474
+ uniforms,
475
+ `${prefix && prefix + "."}${uniformName}`
476
+ );
477
+ });
478
+ }
479
+ if (Array.isArray(uniformValue)) {
480
+ uniformValue.forEach((child, idx) => {
481
+ if (isPlainObject(child)) {
482
+ const childObj = child;
483
+ Object.keys(childObj).forEach((childName) => {
484
+ this.extractUniformsRecursively(
485
+ childName,
486
+ childObj[childName],
487
+ uniforms,
488
+ `${prefix && prefix + "."}${uniformName}[${idx}]`
489
+ );
490
+ });
491
+ }
492
+ });
493
+ }
494
+ }
495
+ };
@@ -0,0 +1,23 @@
1
+ import type { Device, Texture } from '@antv/g-device-api';
2
+ import type { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
3
+ export declare function isTexture2D(t: any): t is ITexture2D;
4
+ export default class DeviceTexture2D implements ITexture2D {
5
+ private device;
6
+ private options;
7
+ private texture;
8
+ private sampler;
9
+ private width;
10
+ private height;
11
+ private isDestroy;
12
+ constructor(device: Device, options: ITexture2DInitializationOptions);
13
+ private createTexture;
14
+ get(): Texture;
15
+ update(props: any): void;
16
+ bind(): void;
17
+ resize({ width, height }: {
18
+ width: number;
19
+ height: number;
20
+ }): void;
21
+ getSize(): [number, number];
22
+ destroy(): void;
23
+ }
@@ -0,0 +1,151 @@
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/DeviceTexture2D.ts
20
+ var DeviceTexture2D_exports = {};
21
+ __export(DeviceTexture2D_exports, {
22
+ default: () => DeviceTexture2D,
23
+ isTexture2D: () => isTexture2D
24
+ });
25
+ module.exports = __toCommonJS(DeviceTexture2D_exports);
26
+ var import_g_device_api = require("@antv/g-device-api");
27
+ var import_l7_core = require("@antv/l7-core");
28
+ var import_constants = require("./constants");
29
+ var import_typedarray = require("./utils/typedarray");
30
+ function isTexture2D(t) {
31
+ return !!(t && t["texture"]);
32
+ }
33
+ var DeviceTexture2D = class {
34
+ constructor(device, options) {
35
+ this.device = device;
36
+ this.options = options;
37
+ this.isDestroy = false;
38
+ const {
39
+ wrapS = import_l7_core.gl.CLAMP_TO_EDGE,
40
+ wrapT = import_l7_core.gl.CLAMP_TO_EDGE,
41
+ aniso,
42
+ mag = import_l7_core.gl.NEAREST,
43
+ min = import_l7_core.gl.NEAREST
44
+ } = options;
45
+ this.createTexture(options);
46
+ this.sampler = device.createSampler({
47
+ addressModeU: import_constants.wrapModeMap[wrapS],
48
+ addressModeV: import_constants.wrapModeMap[wrapT],
49
+ minFilter: min === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
50
+ magFilter: mag === import_l7_core.gl.NEAREST ? import_g_device_api.FilterMode.POINT : import_g_device_api.FilterMode.BILINEAR,
51
+ mipmapFilter: import_g_device_api.MipmapFilterMode.NO_MIP,
52
+ // lodMinClamp: 0,
53
+ // lodMaxClamp: 0,
54
+ maxAnisotropy: aniso
55
+ });
56
+ }
57
+ createTexture(options) {
58
+ const {
59
+ type = import_l7_core.gl.UNSIGNED_BYTE,
60
+ width,
61
+ height,
62
+ flipY = false,
63
+ format = import_l7_core.gl.RGBA,
64
+ alignment = 1,
65
+ usage = import_l7_core.TextureUsage.SAMPLED,
66
+ // premultiplyAlpha = false,
67
+ unorm = false,
68
+ // colorSpace = gl.BROWSER_DEFAULT_WEBGL,
69
+ // x = 0,
70
+ // y = 0,
71
+ // copy = false,
72
+ label
73
+ } = options;
74
+ let { data } = options;
75
+ this.width = width;
76
+ this.height = height;
77
+ let pixelFormat = import_g_device_api.Format.U8_RGBA_RT;
78
+ if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.RGBA) {
79
+ pixelFormat = unorm ? import_g_device_api.Format.U8_RGBA_NORM : import_g_device_api.Format.U8_RGBA_RT;
80
+ } else if (type === import_l7_core.gl.UNSIGNED_BYTE && format === import_l7_core.gl.LUMINANCE) {
81
+ pixelFormat = import_g_device_api.Format.U8_LUMINANCE;
82
+ } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.LUMINANCE) {
83
+ pixelFormat = import_g_device_api.Format.F32_LUMINANCE;
84
+ } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGB) {
85
+ if (this.device.queryVendorInfo().platformString === "WebGPU") {
86
+ if (data) {
87
+ data = (0, import_typedarray.extend3ChannelsTo4)(data, 0);
88
+ }
89
+ pixelFormat = import_g_device_api.Format.F32_RGBA;
90
+ } else {
91
+ pixelFormat = import_g_device_api.Format.F32_RGB;
92
+ }
93
+ } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RGBA) {
94
+ pixelFormat = import_g_device_api.Format.F32_RGBA;
95
+ } else if (type === import_l7_core.gl.FLOAT && format === import_l7_core.gl.RED) {
96
+ pixelFormat = import_g_device_api.Format.F32_R;
97
+ } else {
98
+ throw new Error(`create texture error, type: ${type}, format: ${format}`);
99
+ }
100
+ this.texture = this.device.createTexture({
101
+ format: pixelFormat,
102
+ width,
103
+ height,
104
+ usage: usage === import_l7_core.TextureUsage.SAMPLED ? import_g_device_api.TextureUsage.SAMPLED : import_g_device_api.TextureUsage.RENDER_TARGET,
105
+ pixelStore: {
106
+ unpackFlipY: flipY,
107
+ packAlignment: alignment
108
+ },
109
+ // mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
110
+ mipLevelCount: 1
111
+ });
112
+ if (label) {
113
+ this.device.setResourceName(this.texture, label);
114
+ }
115
+ if (data) {
116
+ this.texture.setImageData([data]);
117
+ }
118
+ }
119
+ get() {
120
+ return this.texture;
121
+ }
122
+ update(props) {
123
+ const { data } = props;
124
+ this.texture.setImageData([data]);
125
+ }
126
+ bind() {
127
+ }
128
+ resize({ width, height }) {
129
+ if (this.width !== width || this.height !== height) {
130
+ this.destroy();
131
+ }
132
+ this.options.width = width;
133
+ this.options.height = height;
134
+ this.createTexture(this.options);
135
+ this.isDestroy = false;
136
+ }
137
+ getSize() {
138
+ return [this.width, this.height];
139
+ }
140
+ destroy() {
141
+ var _a;
142
+ if (!this.isDestroy && !this.texture.destroyed) {
143
+ (_a = this.texture) == null ? void 0 : _a.destroy();
144
+ }
145
+ this.isDestroy = true;
146
+ }
147
+ };
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ isTexture2D
151
+ });