@antv/l7-renderer 2.21.0 → 2.21.2

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 (53) hide show
  1. package/es/device/DeviceAttribute.js +26 -32
  2. package/es/device/DeviceBuffer.js +31 -49
  3. package/es/device/DeviceCache.js +136 -170
  4. package/es/device/DeviceElements.js +32 -38
  5. package/es/device/DeviceFramebuffer.js +76 -104
  6. package/es/device/DeviceModel.js +358 -384
  7. package/es/device/DeviceTexture2D.js +103 -122
  8. package/es/device/constants.js +117 -34
  9. package/es/device/index.js +254 -381
  10. package/es/device/utils/HashMap.js +71 -138
  11. package/es/device/utils/pipeline.js +6 -1
  12. package/es/device/utils/typedarray.js +23 -24
  13. package/es/device/utils/webgl.js +7 -6
  14. package/es/index.js +5 -4
  15. package/es/regl/ReglAttribute.js +17 -33
  16. package/es/regl/ReglBuffer.js +25 -40
  17. package/es/regl/ReglElements.js +21 -36
  18. package/es/regl/ReglFramebuffer.js +24 -44
  19. package/es/regl/ReglModel.js +266 -306
  20. package/es/regl/ReglRenderbuffer.js +19 -36
  21. package/es/regl/ReglTexture2D.js +72 -103
  22. package/es/regl/constants.js +133 -21
  23. package/es/regl/index.js +205 -290
  24. package/lib/device/DeviceAttribute.d.ts +13 -0
  25. package/lib/device/DeviceBuffer.d.ts +18 -0
  26. package/lib/device/DeviceCache.d.ts +14 -0
  27. package/lib/device/DeviceElements.d.ts +13 -0
  28. package/lib/device/DeviceFramebuffer.d.ts +24 -0
  29. package/lib/device/DeviceModel.d.ts +53 -0
  30. package/lib/device/DeviceModel.js +22 -15
  31. package/lib/device/DeviceTexture2D.d.ts +23 -0
  32. package/lib/device/constants.d.ts +35 -0
  33. package/lib/device/index.d.ts +68 -0
  34. package/lib/device/index.js +58 -36
  35. package/lib/device/utils/HashMap.d.ts +24 -0
  36. package/lib/device/utils/pipeline.d.ts +1 -0
  37. package/lib/device/utils/typedarray.d.ts +7 -0
  38. package/lib/device/utils/webgl.d.ts +1 -0
  39. package/lib/index.d.ts +6 -0
  40. package/lib/regl/ReglAttribute.d.ts +16 -0
  41. package/lib/regl/ReglBuffer.d.ts +17 -0
  42. package/lib/regl/ReglElements.d.ts +14 -0
  43. package/lib/regl/ReglFramebuffer.d.ts +16 -0
  44. package/lib/regl/ReglModel.d.ts +46 -0
  45. package/lib/regl/ReglModel.js +21 -11
  46. package/lib/regl/ReglRenderbuffer.d.ts +16 -0
  47. package/lib/regl/ReglTexture2D.d.ts +22 -0
  48. package/lib/regl/constants.d.ts +43 -0
  49. package/lib/regl/index.d.ts +56 -0
  50. package/lib/regl/index.js +70 -48
  51. package/package.json +14 -18
  52. package/CHANGELOG.md +0 -350
  53. package/LICENSE.md +0 -21
@@ -1,18 +1,18 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- var DeviceAttribute = /*#__PURE__*/function () {
4
- function DeviceAttribute(device, options) {
5
- _classCallCheck(this, DeviceAttribute);
6
- var buffer = options.buffer,
7
- offset = options.offset,
8
- stride = options.stride,
9
- normalized = options.normalized,
10
- size = options.size,
11
- divisor = options.divisor,
12
- shaderLocation = options.shaderLocation;
1
+ // src/device/DeviceAttribute.ts
2
+ var DeviceAttribute = class {
3
+ constructor(device, options) {
4
+ const {
5
+ buffer,
6
+ offset,
7
+ stride,
8
+ normalized,
9
+ size,
10
+ divisor,
11
+ shaderLocation
12
+ } = options;
13
13
  this.buffer = buffer;
14
14
  this.attribute = {
15
- shaderLocation: shaderLocation,
15
+ shaderLocation,
16
16
  buffer: buffer.get(),
17
17
  offset: offset || 0,
18
18
  stride: stride || 0,
@@ -23,22 +23,16 @@ var DeviceAttribute = /*#__PURE__*/function () {
23
23
  this.attribute.size = size;
24
24
  }
25
25
  }
26
- _createClass(DeviceAttribute, [{
27
- key: "get",
28
- value: function get() {
29
- return this.buffer;
30
- }
31
- }, {
32
- key: "updateBuffer",
33
- value: function updateBuffer(options) {
34
- this.buffer.subData(options);
35
- }
36
- }, {
37
- key: "destroy",
38
- value: function destroy() {
39
- this.buffer.destroy();
40
- }
41
- }]);
42
- return DeviceAttribute;
43
- }();
44
- export { DeviceAttribute as default };
26
+ get() {
27
+ return this.buffer;
28
+ }
29
+ updateBuffer(options) {
30
+ this.buffer.subData(options);
31
+ }
32
+ destroy() {
33
+ this.buffer.destroy();
34
+ }
35
+ };
36
+ export {
37
+ DeviceAttribute as default
38
+ };
@@ -1,24 +1,13 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- import { BufferUsage } from '@antv/g-device-api';
5
- import { gl } from '@antv/l7-core';
1
+ // src/device/DeviceBuffer.ts
2
+ import { BufferUsage } from "@antv/g-device-api";
3
+ import { gl } from "@antv/l7-core";
6
4
  import { hintMap, typedArrayCtorMap } from "./constants";
7
5
  import { isTypedArray } from "./utils/typedarray";
8
-
9
- /**
10
- * Use Buffer from @antv/g-device-api
11
- */
12
- var DeviceBuffer = /*#__PURE__*/function () {
13
- function DeviceBuffer(device, options) {
14
- _classCallCheck(this, DeviceBuffer);
15
- _defineProperty(this, "isDestroyed", false);
16
- var data = options.data,
17
- usage = options.usage,
18
- type = options.type,
19
- isUBO = options.isUBO,
20
- label = options.label;
21
- var typed;
6
+ var DeviceBuffer = class {
7
+ constructor(device, options) {
8
+ this.isDestroyed = false;
9
+ const { data, usage, type, isUBO, label } = options;
10
+ let typed;
22
11
  if (isTypedArray(data)) {
23
12
  typed = data;
24
13
  } else {
@@ -26,8 +15,6 @@ var DeviceBuffer = /*#__PURE__*/function () {
26
15
  }
27
16
  this.type = type;
28
17
  this.size = typed.byteLength;
29
-
30
- // @see https://www.npmjs.com/package/@antv/g-device-api#createBuffer
31
18
  this.buffer = device.createBuffer({
32
19
  viewOrSize: typed,
33
20
  usage: isUBO ? BufferUsage.UNIFORM : BufferUsage.VERTEX,
@@ -37,33 +24,28 @@ var DeviceBuffer = /*#__PURE__*/function () {
37
24
  device.setResourceName(this.buffer, label);
38
25
  }
39
26
  }
40
- _createClass(DeviceBuffer, [{
41
- key: "get",
42
- value: function get() {
43
- return this.buffer;
44
- }
45
- }, {
46
- key: "destroy",
47
- value: function destroy() {
48
- if (!this.isDestroyed) {
49
- this.buffer.destroy();
50
- }
51
- this.isDestroyed = true;
27
+ get() {
28
+ return this.buffer;
29
+ }
30
+ destroy() {
31
+ if (!this.isDestroyed) {
32
+ this.buffer.destroy();
52
33
  }
53
- }, {
54
- key: "subData",
55
- value: function subData(_ref) {
56
- var data = _ref.data,
57
- offset = _ref.offset;
58
- var typed;
59
- if (isTypedArray(data)) {
60
- typed = data;
61
- } else {
62
- typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
63
- }
64
- this.buffer.setSubData(offset, new Uint8Array(typed.buffer));
34
+ this.isDestroyed = true;
35
+ }
36
+ subData({
37
+ data,
38
+ offset
39
+ }) {
40
+ let typed;
41
+ if (isTypedArray(data)) {
42
+ typed = data;
43
+ } else {
44
+ typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
65
45
  }
66
- }]);
67
- return DeviceBuffer;
68
- }();
69
- export { DeviceBuffer as default };
46
+ this.buffer.setSubData(offset, new Uint8Array(typed.buffer));
47
+ }
48
+ };
49
+ export {
50
+ DeviceBuffer as default
51
+ };
@@ -1,11 +1,19 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
- import { TransparentBlack, bindingsDescriptorCopy, bindingsDescriptorEquals, inputLayoutDescriptorCopy, inputLayoutDescriptorEquals, renderPipelineDescriptorCopy, renderPipelineDescriptorEquals } from '@antv/g-device-api';
8
- import { HashMap, hashCodeNumberFinish, hashCodeNumberUpdate, nullHashFunc } from "./utils/HashMap";
1
+ // src/device/DeviceCache.ts
2
+ import {
3
+ TransparentBlack,
4
+ bindingsDescriptorCopy,
5
+ bindingsDescriptorEquals,
6
+ inputLayoutDescriptorCopy,
7
+ inputLayoutDescriptorEquals,
8
+ renderPipelineDescriptorCopy,
9
+ renderPipelineDescriptorEquals
10
+ } from "@antv/g-device-api";
11
+ import {
12
+ HashMap,
13
+ hashCodeNumberFinish,
14
+ hashCodeNumberUpdate,
15
+ nullHashFunc
16
+ } from "./utils/HashMap";
9
17
  function blendStateHash(hash, a) {
10
18
  hash = hashCodeNumberUpdate(hash, a.blendMode);
11
19
  hash = hashCodeNumberUpdate(hash, a.blendSrcFactor);
@@ -19,23 +27,27 @@ function attachmentStateHash(hash, a) {
19
27
  return hash;
20
28
  }
21
29
  function colorHash(hash, a) {
22
- hash = hashCodeNumberUpdate(hash, a.r << 24 | a.g << 16 | a.b << 8 | a.a);
30
+ hash = hashCodeNumberUpdate(
31
+ hash,
32
+ a.r << 24 | a.g << 16 | a.b << 8 | a.a
33
+ );
23
34
  return hash;
24
35
  }
25
36
  function megaStateDescriptorHash(hash, a) {
26
- var _a$stencilFront, _a$stencilFront2, _a$stencilFront3, _a$stencilFront4, _a$stencilBack, _a$stencilBack2, _a$stencilBack3, _a$stencilBack4;
27
- for (var i = 0; i < a.attachmentsState.length; i++) hash = attachmentStateHash(hash, a.attachmentsState[i]);
37
+ var _a, _b, _c, _d, _e, _f, _g, _h;
38
+ for (let i = 0; i < a.attachmentsState.length; i++)
39
+ hash = attachmentStateHash(hash, a.attachmentsState[i]);
28
40
  hash = colorHash(hash, a.blendConstant || TransparentBlack);
29
41
  hash = hashCodeNumberUpdate(hash, a.depthCompare);
30
42
  hash = hashCodeNumberUpdate(hash, a.depthWrite ? 1 : 0);
31
- hash = hashCodeNumberUpdate(hash, (_a$stencilFront = a.stencilFront) === null || _a$stencilFront === void 0 ? void 0 : _a$stencilFront.compare);
32
- hash = hashCodeNumberUpdate(hash, (_a$stencilFront2 = a.stencilFront) === null || _a$stencilFront2 === void 0 ? void 0 : _a$stencilFront2.passOp);
33
- hash = hashCodeNumberUpdate(hash, (_a$stencilFront3 = a.stencilFront) === null || _a$stencilFront3 === void 0 ? void 0 : _a$stencilFront3.failOp);
34
- hash = hashCodeNumberUpdate(hash, (_a$stencilFront4 = a.stencilFront) === null || _a$stencilFront4 === void 0 ? void 0 : _a$stencilFront4.depthFailOp);
35
- hash = hashCodeNumberUpdate(hash, (_a$stencilBack = a.stencilBack) === null || _a$stencilBack === void 0 ? void 0 : _a$stencilBack.compare);
36
- hash = hashCodeNumberUpdate(hash, (_a$stencilBack2 = a.stencilBack) === null || _a$stencilBack2 === void 0 ? void 0 : _a$stencilBack2.passOp);
37
- hash = hashCodeNumberUpdate(hash, (_a$stencilBack3 = a.stencilBack) === null || _a$stencilBack3 === void 0 ? void 0 : _a$stencilBack3.failOp);
38
- hash = hashCodeNumberUpdate(hash, (_a$stencilBack4 = a.stencilBack) === null || _a$stencilBack4 === void 0 ? void 0 : _a$stencilBack4.depthFailOp);
43
+ hash = hashCodeNumberUpdate(hash, (_a = a.stencilFront) == null ? void 0 : _a.compare);
44
+ hash = hashCodeNumberUpdate(hash, (_b = a.stencilFront) == null ? void 0 : _b.passOp);
45
+ hash = hashCodeNumberUpdate(hash, (_c = a.stencilFront) == null ? void 0 : _c.failOp);
46
+ hash = hashCodeNumberUpdate(hash, (_d = a.stencilFront) == null ? void 0 : _d.depthFailOp);
47
+ hash = hashCodeNumberUpdate(hash, (_e = a.stencilBack) == null ? void 0 : _e.compare);
48
+ hash = hashCodeNumberUpdate(hash, (_f = a.stencilBack) == null ? void 0 : _f.passOp);
49
+ hash = hashCodeNumberUpdate(hash, (_g = a.stencilBack) == null ? void 0 : _g.failOp);
50
+ hash = hashCodeNumberUpdate(hash, (_h = a.stencilBack) == null ? void 0 : _h.depthFailOp);
39
51
  hash = hashCodeNumberUpdate(hash, a.stencilWrite ? 1 : 0);
40
52
  hash = hashCodeNumberUpdate(hash, a.cullMode);
41
53
  hash = hashCodeNumberUpdate(hash, a.frontFace ? 1 : 0);
@@ -43,193 +55,147 @@ function megaStateDescriptorHash(hash, a) {
43
55
  return hash;
44
56
  }
45
57
  function renderPipelineDescriptorHash(a) {
46
- var hash = 0;
58
+ let hash = 0;
47
59
  hash = hashCodeNumberUpdate(hash, a.program.id);
48
- if (a.inputLayout !== null) hash = hashCodeNumberUpdate(hash, a.inputLayout.id);
60
+ if (a.inputLayout !== null)
61
+ hash = hashCodeNumberUpdate(hash, a.inputLayout.id);
49
62
  hash = megaStateDescriptorHash(hash, a.megaStateDescriptor);
50
- for (var i = 0; i < a.colorAttachmentFormats.length; i++) hash = hashCodeNumberUpdate(hash, a.colorAttachmentFormats[i] || 0);
63
+ for (let i = 0; i < a.colorAttachmentFormats.length; i++)
64
+ hash = hashCodeNumberUpdate(hash, a.colorAttachmentFormats[i] || 0);
51
65
  hash = hashCodeNumberUpdate(hash, a.depthStencilAttachmentFormat || 0);
52
66
  return hashCodeNumberFinish(hash);
53
67
  }
54
68
  function bindingsDescriptorHash(a) {
55
- var hash = 0;
69
+ let hash = 0;
56
70
  if (a.samplerBindings) {
57
- for (var i = 0; i < a.samplerBindings.length; i++) {
58
- var binding = a.samplerBindings[i];
59
- if (binding !== null && binding.texture !== null) hash = hashCodeNumberUpdate(hash, binding.texture.id);
71
+ for (let i = 0; i < a.samplerBindings.length; i++) {
72
+ const binding = a.samplerBindings[i];
73
+ if (binding !== null && binding.texture !== null)
74
+ hash = hashCodeNumberUpdate(hash, binding.texture.id);
60
75
  }
61
76
  }
62
77
  if (a.uniformBufferBindings) {
63
- for (var _i = 0; _i < a.uniformBufferBindings.length; _i++) {
64
- var _binding = a.uniformBufferBindings[_i];
65
- if (_binding !== null && _binding.buffer !== null) {
66
- hash = hashCodeNumberUpdate(hash, _binding.buffer.id);
67
- hash = hashCodeNumberUpdate(hash, _binding.binding);
68
- hash = hashCodeNumberUpdate(hash, _binding.offset);
69
- hash = hashCodeNumberUpdate(hash, _binding.size);
78
+ for (let i = 0; i < a.uniformBufferBindings.length; i++) {
79
+ const binding = a.uniformBufferBindings[i];
80
+ if (binding !== null && binding.buffer !== null) {
81
+ hash = hashCodeNumberUpdate(hash, binding.buffer.id);
82
+ hash = hashCodeNumberUpdate(hash, binding.binding);
83
+ hash = hashCodeNumberUpdate(hash, binding.offset);
84
+ hash = hashCodeNumberUpdate(hash, binding.size);
70
85
  }
71
86
  }
72
87
  }
73
88
  if (a.storageBufferBindings) {
74
- for (var _i2 = 0; _i2 < a.storageBufferBindings.length; _i2++) {
75
- var _binding2 = a.storageBufferBindings[_i2];
76
- if (_binding2 !== null && _binding2.buffer !== null) {
77
- hash = hashCodeNumberUpdate(hash, _binding2.buffer.id);
78
- hash = hashCodeNumberUpdate(hash, _binding2.binding);
79
- hash = hashCodeNumberUpdate(hash, _binding2.offset);
80
- hash = hashCodeNumberUpdate(hash, _binding2.size);
89
+ for (let i = 0; i < a.storageBufferBindings.length; i++) {
90
+ const binding = a.storageBufferBindings[i];
91
+ if (binding !== null && binding.buffer !== null) {
92
+ hash = hashCodeNumberUpdate(hash, binding.buffer.id);
93
+ hash = hashCodeNumberUpdate(hash, binding.binding);
94
+ hash = hashCodeNumberUpdate(hash, binding.offset);
95
+ hash = hashCodeNumberUpdate(hash, binding.size);
81
96
  }
82
97
  }
83
98
  }
84
99
  if (a.storageTextureBindings) {
85
- for (var _i3 = 0; _i3 < a.storageTextureBindings.length; _i3++) {
86
- var _binding3 = a.storageTextureBindings[_i3];
87
- if (_binding3 !== null && _binding3.texture !== null) {
88
- hash = hashCodeNumberUpdate(hash, _binding3.texture.id);
89
- hash = hashCodeNumberUpdate(hash, _binding3.binding);
100
+ for (let i = 0; i < a.storageTextureBindings.length; i++) {
101
+ const binding = a.storageTextureBindings[i];
102
+ if (binding !== null && binding.texture !== null) {
103
+ hash = hashCodeNumberUpdate(hash, binding.texture.id);
104
+ hash = hashCodeNumberUpdate(hash, binding.binding);
90
105
  }
91
106
  }
92
107
  }
93
108
  return hashCodeNumberFinish(hash);
94
109
  }
95
110
  function programDescriptorEquals(a, b) {
96
- var _a$vertex, _b$vertex, _a$fragment, _b$fragment;
97
- return ((_a$vertex = a.vertex) === null || _a$vertex === void 0 ? void 0 : _a$vertex.glsl) === ((_b$vertex = b.vertex) === null || _b$vertex === void 0 ? void 0 : _b$vertex.glsl) && ((_a$fragment = a.fragment) === null || _a$fragment === void 0 ? void 0 : _a$fragment.glsl) === ((_b$fragment = b.fragment) === null || _b$fragment === void 0 ? void 0 : _b$fragment.glsl);
111
+ var _a, _b, _c, _d;
112
+ 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);
98
113
  }
99
114
  function programDescriptorCopy(a) {
100
- var _a$vertex2, _a$fragment2;
115
+ var _a, _b;
101
116
  return {
102
117
  vertex: {
103
- glsl: (_a$vertex2 = a.vertex) === null || _a$vertex2 === void 0 ? void 0 : _a$vertex2.glsl
118
+ glsl: (_a = a.vertex) == null ? void 0 : _a.glsl
104
119
  },
105
120
  fragment: {
106
- glsl: (_a$fragment2 = a.fragment) === null || _a$fragment2 === void 0 ? void 0 : _a$fragment2.glsl
121
+ glsl: (_b = a.fragment) == null ? void 0 : _b.glsl
107
122
  }
108
123
  };
109
124
  }
110
- export var RenderCache = /*#__PURE__*/function () {
111
- function RenderCache(device) {
112
- _classCallCheck(this, RenderCache);
113
- _defineProperty(this, "bindingsCache", new HashMap(bindingsDescriptorEquals, bindingsDescriptorHash));
114
- _defineProperty(this, "renderPipelinesCache", new HashMap(renderPipelineDescriptorEquals, renderPipelineDescriptorHash));
115
- _defineProperty(this, "inputLayoutsCache", new HashMap(inputLayoutDescriptorEquals, nullHashFunc));
116
- _defineProperty(this, "programCache", new HashMap(programDescriptorEquals, nullHashFunc));
125
+ var RenderCache = class {
126
+ constructor(device) {
117
127
  this.device = device;
128
+ this.bindingsCache = new HashMap(
129
+ bindingsDescriptorEquals,
130
+ bindingsDescriptorHash
131
+ );
132
+ this.renderPipelinesCache = new HashMap(renderPipelineDescriptorEquals, renderPipelineDescriptorHash);
133
+ this.inputLayoutsCache = new HashMap(
134
+ inputLayoutDescriptorEquals,
135
+ nullHashFunc
136
+ );
137
+ this.programCache = new HashMap(
138
+ programDescriptorEquals,
139
+ nullHashFunc
140
+ );
118
141
  }
119
- _createClass(RenderCache, [{
120
- key: "createBindings",
121
- value: function createBindings(descriptor) {
122
- var bindings = this.bindingsCache.get(descriptor);
123
- if (bindings === null) {
124
- var _descriptorCopy$unifo;
125
- var descriptorCopy = bindingsDescriptorCopy(descriptor);
126
- descriptorCopy.uniformBufferBindings = (_descriptorCopy$unifo = descriptorCopy.uniformBufferBindings) === null || _descriptorCopy$unifo === void 0 ? void 0 : _descriptorCopy$unifo.filter(function (_ref) {
127
- var size = _ref.size;
128
- return size && size > 0;
129
- });
130
- bindings = this.device.createBindings(descriptorCopy);
131
- this.bindingsCache.add(descriptorCopy, bindings);
132
- }
133
- return bindings;
134
- }
135
- }, {
136
- key: "createRenderPipeline",
137
- value: function createRenderPipeline(descriptor) {
138
- var renderPipeline = this.renderPipelinesCache.get(descriptor);
139
- if (renderPipeline === null) {
140
- var descriptorCopy = renderPipelineDescriptorCopy(descriptor);
141
- descriptorCopy.colorAttachmentFormats = descriptorCopy.colorAttachmentFormats.filter(function (f) {
142
- return f;
143
- });
144
- renderPipeline = this.device.createRenderPipeline(descriptorCopy);
145
- this.renderPipelinesCache.add(descriptorCopy, renderPipeline);
146
- }
147
- return renderPipeline;
142
+ createBindings(descriptor) {
143
+ var _a;
144
+ let bindings = this.bindingsCache.get(descriptor);
145
+ if (bindings === null) {
146
+ const descriptorCopy = bindingsDescriptorCopy(descriptor);
147
+ descriptorCopy.uniformBufferBindings = (_a = descriptorCopy.uniformBufferBindings) == null ? void 0 : _a.filter(
148
+ ({ size }) => size && size > 0
149
+ );
150
+ bindings = this.device.createBindings(descriptorCopy);
151
+ this.bindingsCache.add(descriptorCopy, bindings);
148
152
  }
149
- }, {
150
- key: "createInputLayout",
151
- value: function createInputLayout(descriptor) {
152
- // remove hollows
153
- descriptor.vertexBufferDescriptors = descriptor.vertexBufferDescriptors.filter(function (d) {
154
- return !!d;
155
- });
156
- var inputLayout = this.inputLayoutsCache.get(descriptor);
157
- if (inputLayout === null) {
158
- var descriptorCopy = inputLayoutDescriptorCopy(descriptor);
159
- inputLayout = this.device.createInputLayout(descriptorCopy);
160
- this.inputLayoutsCache.add(descriptorCopy, inputLayout);
161
- }
162
- return inputLayout;
153
+ return bindings;
154
+ }
155
+ createRenderPipeline(descriptor) {
156
+ let renderPipeline = this.renderPipelinesCache.get(descriptor);
157
+ if (renderPipeline === null) {
158
+ const descriptorCopy = renderPipelineDescriptorCopy(descriptor);
159
+ descriptorCopy.colorAttachmentFormats = descriptorCopy.colorAttachmentFormats.filter((f) => f);
160
+ renderPipeline = this.device.createRenderPipeline(descriptorCopy);
161
+ this.renderPipelinesCache.add(descriptorCopy, renderPipeline);
163
162
  }
164
- }, {
165
- key: "createProgram",
166
- value: function createProgram(descriptor) {
167
- var program = this.programCache.get(descriptor);
168
- if (program === null) {
169
- var descriptorCopy = programDescriptorCopy(descriptor);
170
- program = this.device.createProgram(descriptor);
171
- this.programCache.add(descriptorCopy, program);
172
- }
173
- return program;
163
+ return renderPipeline;
164
+ }
165
+ createInputLayout(descriptor) {
166
+ descriptor.vertexBufferDescriptors = descriptor.vertexBufferDescriptors.filter((d) => !!d);
167
+ let inputLayout = this.inputLayoutsCache.get(descriptor);
168
+ if (inputLayout === null) {
169
+ const descriptorCopy = inputLayoutDescriptorCopy(descriptor);
170
+ inputLayout = this.device.createInputLayout(descriptorCopy);
171
+ this.inputLayoutsCache.add(descriptorCopy, inputLayout);
174
172
  }
175
- }, {
176
- key: "destroy",
177
- value: function destroy() {
178
- var _iterator = _createForOfIteratorHelper(this.bindingsCache.values()),
179
- _step;
180
- try {
181
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
182
- var bindings = _step.value;
183
- bindings.destroy();
184
- }
185
- } catch (err) {
186
- _iterator.e(err);
187
- } finally {
188
- _iterator.f();
189
- }
190
- var _iterator2 = _createForOfIteratorHelper(this.renderPipelinesCache.values()),
191
- _step2;
192
- try {
193
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
194
- var renderPipeline = _step2.value;
195
- renderPipeline.destroy();
196
- }
197
- } catch (err) {
198
- _iterator2.e(err);
199
- } finally {
200
- _iterator2.f();
201
- }
202
- var _iterator3 = _createForOfIteratorHelper(this.inputLayoutsCache.values()),
203
- _step3;
204
- try {
205
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
206
- var inputLayout = _step3.value;
207
- inputLayout.destroy();
208
- }
209
- } catch (err) {
210
- _iterator3.e(err);
211
- } finally {
212
- _iterator3.f();
213
- }
214
- var _iterator4 = _createForOfIteratorHelper(this.programCache.values()),
215
- _step4;
216
- try {
217
- for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
218
- var program = _step4.value;
219
- program.destroy();
220
- }
221
- // for (const sampler of this.samplerCache.values()) sampler.destroy();
222
- } catch (err) {
223
- _iterator4.e(err);
224
- } finally {
225
- _iterator4.f();
226
- }
227
- this.bindingsCache.clear();
228
- this.renderPipelinesCache.clear();
229
- this.inputLayoutsCache.clear();
230
- this.programCache.clear();
231
- // this.samplerCache.clear();
173
+ return inputLayout;
174
+ }
175
+ createProgram(descriptor) {
176
+ let program = this.programCache.get(descriptor);
177
+ if (program === null) {
178
+ const descriptorCopy = programDescriptorCopy(descriptor);
179
+ program = this.device.createProgram(descriptor);
180
+ this.programCache.add(descriptorCopy, program);
232
181
  }
233
- }]);
234
- return RenderCache;
235
- }();
182
+ return program;
183
+ }
184
+ destroy() {
185
+ for (const bindings of this.bindingsCache.values())
186
+ bindings.destroy();
187
+ for (const renderPipeline of this.renderPipelinesCache.values())
188
+ renderPipeline.destroy();
189
+ for (const inputLayout of this.inputLayoutsCache.values())
190
+ inputLayout.destroy();
191
+ for (const program of this.programCache.values())
192
+ program.destroy();
193
+ this.bindingsCache.clear();
194
+ this.renderPipelinesCache.clear();
195
+ this.inputLayoutsCache.clear();
196
+ this.programCache.clear();
197
+ }
198
+ };
199
+ export {
200
+ RenderCache
201
+ };
@@ -1,21 +1,18 @@
1
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
2
- import _createClass from "@babel/runtime/helpers/esm/createClass";
3
- import { BufferUsage } from '@antv/g-device-api';
4
- import { gl } from '@antv/l7-core';
1
+ // src/device/DeviceElements.ts
2
+ import { BufferUsage } from "@antv/g-device-api";
3
+ import { gl } from "@antv/l7-core";
5
4
  import { typedArrayCtorMap } from "./constants";
6
5
  import { isTypedArray } from "./utils/typedarray";
7
- var DeviceElements = /*#__PURE__*/function () {
8
- function DeviceElements(device, options) {
9
- _classCallCheck(this, DeviceElements);
10
- var data = options.data,
11
- type = options.type,
12
- _options$count = options.count,
13
- count = _options$count === void 0 ? 0 : _options$count;
14
- var typed;
6
+ var DeviceElements = class {
7
+ constructor(device, options) {
8
+ const { data, type, count = 0 } = options;
9
+ let typed;
15
10
  if (isTypedArray(data)) {
16
11
  typed = data;
17
12
  } else {
18
- typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
13
+ typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](
14
+ data
15
+ );
19
16
  }
20
17
  this.type = type;
21
18
  this.count = count;
@@ -24,29 +21,26 @@ var DeviceElements = /*#__PURE__*/function () {
24
21
  usage: BufferUsage.INDEX
25
22
  });
26
23
  }
27
- _createClass(DeviceElements, [{
28
- key: "get",
29
- value: function get() {
30
- return this.indexBuffer;
31
- }
32
- }, {
33
- key: "subData",
34
- value: function subData(_ref) {
35
- var data = _ref.data;
36
- var typed;
37
- if (isTypedArray(data)) {
38
- typed = data;
39
- } else {
40
- typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
41
- }
42
- this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer));
43
- }
44
- }, {
45
- key: "destroy",
46
- value: function destroy() {
47
- this.indexBuffer.destroy();
24
+ get() {
25
+ return this.indexBuffer;
26
+ }
27
+ subData({
28
+ data
29
+ }) {
30
+ let typed;
31
+ if (isTypedArray(data)) {
32
+ typed = data;
33
+ } else {
34
+ typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](
35
+ data
36
+ );
48
37
  }
49
- }]);
50
- return DeviceElements;
51
- }();
52
- export { DeviceElements as default };
38
+ this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer));
39
+ }
40
+ destroy() {
41
+ this.indexBuffer.destroy();
42
+ }
43
+ };
44
+ export {
45
+ DeviceElements as default
46
+ };