@antv/l7-renderer 2.25.5 → 2.25.7

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