@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,80 +1,110 @@
1
- import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
- import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/esm/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- import { BlendFactor, BlendMode, ChannelWriteMask, CompareFunction, CullMode, Format, StencilOp, TransparentBlack, VertexStepMode, ViewportOrigin } from '@antv/g-device-api';
6
- import { gl } from '@antv/l7-core';
7
- import { lodashUtil } from '@antv/l7-utils';
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";
8
36
  import DeviceFramebuffer from "./DeviceFramebuffer";
9
37
  import DeviceTexture2D from "./DeviceTexture2D";
10
- import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, sizeFormatMap, stencilFuncMap, stencilOpMap } from "./constants";
11
- var isPlainObject = lodashUtil.isPlainObject,
12
- isTypedArray = lodashUtil.isTypedArray;
13
- var DeviceModel = /*#__PURE__*/function () {
14
- function DeviceModel(device, options, service) {
15
- var _this = this;
16
- _classCallCheck(this, DeviceModel);
17
- _defineProperty(this, "destroyed", false);
18
- _defineProperty(this, "uniforms", {});
19
- _defineProperty(this, "vertexBuffers", []);
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 } = lodashUtil;
49
+ var DeviceModel = class {
50
+ constructor(device, options, service) {
20
51
  this.device = device;
21
52
  this.options = options;
22
53
  this.service = service;
23
- var vs = options.vs,
24
- fs = options.fs,
25
- attributes = options.attributes,
26
- uniforms = options.uniforms,
27
- count = options.count,
28
- elements = options.elements,
29
- diagnosticDerivativeUniformityEnabled = options.diagnosticDerivativeUniformityEnabled;
54
+ this.destroyed = false;
55
+ this.uniforms = {};
56
+ this.vertexBuffers = [];
57
+ const {
58
+ vs,
59
+ fs,
60
+ attributes,
61
+ uniforms,
62
+ count,
63
+ elements,
64
+ diagnosticDerivativeUniformityEnabled
65
+ } = options;
30
66
  this.options = options;
31
- var diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? '' : this.service['viewportOrigin'] === ViewportOrigin.UPPER_LEFT ? 'diagnostic(off,derivative_uniformity);' : '';
67
+ const diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? "" : this.service["viewportOrigin"] === ViewportOrigin.UPPER_LEFT ? "diagnostic(off,derivative_uniformity);" : "";
32
68
  this.program = service.renderCache.createProgram({
33
69
  vertex: {
34
70
  glsl: vs
35
71
  },
36
72
  fragment: {
37
73
  glsl: fs,
38
- postprocess: function postprocess(fs) {
39
- return diagnosticDerivativeUniformityHeader + fs;
40
- }
74
+ postprocess: (fs2) => diagnosticDerivativeUniformityHeader + fs2
41
75
  }
42
76
  });
43
77
  if (uniforms) {
44
78
  this.uniforms = this.extractUniforms(uniforms);
45
79
  }
46
- var vertexBufferDescriptors = [];
47
-
48
- // Infer count from data if not provided.
49
- var inferredCount = 0;
50
- Object.keys(attributes).forEach(function (name) {
51
- var attribute = attributes[name];
52
- var buffer = attribute.get();
53
- // Bind at each frame.
54
- _this.vertexBuffers.push(buffer.get());
55
- var _attribute$attribute = attribute['attribute'],
56
- _attribute$attribute$ = _attribute$attribute.offset,
57
- offset = _attribute$attribute$ === void 0 ? 0 : _attribute$attribute$,
58
- _attribute$attribute$2 = _attribute$attribute.stride,
59
- stride = _attribute$attribute$2 === void 0 ? 0 : _attribute$attribute$2,
60
- _attribute$attribute$3 = _attribute$attribute.size,
61
- size = _attribute$attribute$3 === void 0 ? 1 : _attribute$attribute$3,
62
- _attribute$attribute$4 = _attribute$attribute.divisor,
63
- divisor = _attribute$attribute$4 === void 0 ? 0 : _attribute$attribute$4,
64
- _attribute$attribute$5 = _attribute$attribute.shaderLocation,
65
- shaderLocation = _attribute$attribute$5 === void 0 ? 0 : _attribute$attribute$5;
80
+ const vertexBufferDescriptors = [];
81
+ let inferredCount = 0;
82
+ Object.keys(attributes).forEach((name) => {
83
+ const attribute = attributes[name];
84
+ const buffer = attribute.get();
85
+ this.vertexBuffers.push(buffer.get());
86
+ const {
87
+ offset = 0,
88
+ stride = 0,
89
+ // TODO: normalized
90
+ size = 1,
91
+ divisor = 0,
92
+ shaderLocation = 0
93
+ } = attribute["attribute"];
66
94
  vertexBufferDescriptors.push({
67
95
  arrayStride: stride || size * 4,
68
96
  // TODO: L7 hasn't use instanced array for now.
69
97
  stepMode: VertexStepMode.VERTEX,
70
- attributes: [{
71
- format: sizeFormatMap[size],
72
- shaderLocation: shaderLocation,
73
- offset: offset,
74
- divisor: divisor
75
- }]
98
+ attributes: [
99
+ {
100
+ format: sizeFormatMap[size],
101
+ shaderLocation,
102
+ offset,
103
+ divisor
104
+ }
105
+ ]
76
106
  });
77
- inferredCount = buffer['size'] / size;
107
+ inferredCount = buffer["size"] / size;
78
108
  });
79
109
  if (!count) {
80
110
  this.options.count = inferredCount;
@@ -82,49 +112,34 @@ var DeviceModel = /*#__PURE__*/function () {
82
112
  if (elements) {
83
113
  this.indexBuffer = elements.get();
84
114
  }
85
- var inputLayout = service.renderCache.createInputLayout({
86
- vertexBufferDescriptors: vertexBufferDescriptors,
115
+ const inputLayout = service.renderCache.createInputLayout({
116
+ vertexBufferDescriptors,
87
117
  indexBufferFormat: elements ? Format.U32_R : null,
88
118
  program: this.program
89
119
  });
90
120
  this.inputLayout = inputLayout;
91
121
  this.pipeline = this.createPipeline(options);
92
122
  }
93
- _createClass(DeviceModel, [{
94
- key: "createPipeline",
95
- value: function createPipeline(options, pick) {
96
- var _options$primitive = options.primitive,
97
- primitive = _options$primitive === void 0 ? gl.TRIANGLES : _options$primitive,
98
- depth = options.depth,
99
- cull = options.cull,
100
- blend = options.blend,
101
- stencil = options.stencil;
102
- var depthParams = this.initDepthDrawParams({
103
- depth: depth
104
- });
105
- var depthEnabled = !!(depthParams && depthParams.enable);
106
- var cullParams = this.initCullDrawParams({
107
- cull: cull
108
- });
109
- var cullEnabled = !!(cullParams && cullParams.enable);
110
- // Disable blend when picking.
111
- var blendParams = this.getBlendDrawParams({
112
- blend: blend
113
- });
114
- var blendEnabled = !!(blendParams && blendParams.enable);
115
- var stencilParams = this.getStencilDrawParams({
116
- stencil: stencil
117
- });
118
- var stencilEnabled = !!(stencilParams && stencilParams.enable);
119
- return this.device.createRenderPipeline({
120
- // return this.service.renderCache.createRenderPipeline({
121
- inputLayout: this.inputLayout,
122
- program: this.program,
123
- topology: primitiveMap[primitive],
124
- colorAttachmentFormats: [Format.U8_RGBA_RT],
125
- depthStencilAttachmentFormat: Format.D24_S8,
126
- megaStateDescriptor: {
127
- attachmentsState: [pick ? {
123
+ createPipeline(options, pick) {
124
+ const { primitive = gl.TRIANGLES, depth, cull, blend, stencil } = options;
125
+ const depthParams = this.initDepthDrawParams({ depth });
126
+ const depthEnabled = !!(depthParams && depthParams.enable);
127
+ const cullParams = this.initCullDrawParams({ cull });
128
+ const cullEnabled = !!(cullParams && cullParams.enable);
129
+ const blendParams = this.getBlendDrawParams({ blend });
130
+ const blendEnabled = !!(blendParams && blendParams.enable);
131
+ const stencilParams = this.getStencilDrawParams({ stencil });
132
+ const stencilEnabled = !!(stencilParams && stencilParams.enable);
133
+ return this.device.createRenderPipeline({
134
+ // return this.service.renderCache.createRenderPipeline({
135
+ inputLayout: this.inputLayout,
136
+ program: this.program,
137
+ topology: primitiveMap[primitive],
138
+ colorAttachmentFormats: [Format.U8_RGBA_RT],
139
+ depthStencilAttachmentFormat: Format.D24_S8,
140
+ megaStateDescriptor: {
141
+ attachmentsState: [
142
+ pick ? {
128
143
  channelWriteMask: ChannelWriteMask.ALL,
129
144
  rgbBlendState: {
130
145
  blendMode: BlendMode.ADD,
@@ -148,317 +163,276 @@ var DeviceModel = /*#__PURE__*/function () {
148
163
  blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || BlendFactor.ONE,
149
164
  blendDstFactor: blendEnabled && blendParams.func.dstAlpha || BlendFactor.ONE
150
165
  }
151
- }],
152
- blendConstant: blendEnabled ? TransparentBlack : undefined,
153
- depthWrite: depthEnabled,
154
- depthCompare: depthEnabled && depthParams.func || CompareFunction.LESS,
155
- cullMode: cullEnabled && cullParams.face || CullMode.NONE,
156
- stencilWrite: stencilEnabled,
157
- stencilFront: {
158
- compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
159
- passOp: stencilParams.opFront.zpass,
160
- failOp: stencilParams.opFront.fail,
161
- depthFailOp: stencilParams.opFront.zfail,
162
- mask: stencilParams.opFront.mask
163
- },
164
- stencilBack: {
165
- compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
166
- passOp: stencilParams.opBack.zpass,
167
- failOp: stencilParams.opBack.fail,
168
- depthFailOp: stencilParams.opBack.zfail,
169
- mask: stencilParams.opBack.mask
170
166
  }
167
+ ],
168
+ blendConstant: blendEnabled ? TransparentBlack : void 0,
169
+ depthWrite: depthEnabled,
170
+ depthCompare: depthEnabled && depthParams.func || CompareFunction.LESS,
171
+ cullMode: cullEnabled && cullParams.face || CullMode.NONE,
172
+ stencilWrite: stencilEnabled,
173
+ stencilFront: {
174
+ compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
175
+ passOp: stencilParams.opFront.zpass,
176
+ failOp: stencilParams.opFront.fail,
177
+ depthFailOp: stencilParams.opFront.zfail,
178
+ mask: stencilParams.opFront.mask
179
+ },
180
+ stencilBack: {
181
+ compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
182
+ passOp: stencilParams.opBack.zpass,
183
+ failOp: stencilParams.opBack.fail,
184
+ depthFailOp: stencilParams.opBack.zfail,
185
+ mask: stencilParams.opBack.mask
171
186
  }
172
- });
173
- }
174
- }, {
175
- key: "updateAttributesAndElements",
176
- value: function updateAttributesAndElements() {}
177
-
178
- /**
179
- * No need to implement this method, you should update data on `Attribute` like this:
180
- *
181
- * @example
182
- * ```ts
183
- * attribute.updateBuffer({
184
- * data: [],
185
- * offset: 0,
186
- * });
187
- * ```
188
- */
189
- }, {
190
- key: "updateAttributes",
191
- value: function updateAttributes() {}
192
- }, {
193
- key: "addUniforms",
194
- value: function addUniforms(uniforms) {
195
- this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
196
- }
197
- }, {
198
- key: "draw",
199
- value: function draw(options, pick) {
200
- var _this2 = this;
201
- var mergedOptions = _objectSpread(_objectSpread({}, this.options), options);
202
- var _mergedOptions$count = mergedOptions.count,
203
- count = _mergedOptions$count === void 0 ? 0 : _mergedOptions$count,
204
- instances = mergedOptions.instances,
205
- elements = mergedOptions.elements,
206
- _mergedOptions$unifor = mergedOptions.uniforms,
207
- uniforms = _mergedOptions$unifor === void 0 ? {} : _mergedOptions$unifor,
208
- uniformBuffers = mergedOptions.uniformBuffers,
209
- textures = mergedOptions.textures;
210
- this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
211
- var _this$service = this.service,
212
- renderPass = _this$service.renderPass,
213
- currentFramebuffer = _this$service.currentFramebuffer,
214
- width = _this$service.width,
215
- height = _this$service.height,
216
- renderCache = _this$service.renderCache;
217
-
218
- // TODO: Recreate pipeline only when blend / cull changed.
219
- this.pipeline = this.createPipeline(mergedOptions, pick);
220
-
221
- // const height = this.device['swapChainHeight'];
222
- var device = this.service['device'];
223
- // @ts-ignore
224
- var tmpHeight = device['swapChainHeight'];
225
- // @ts-ignore
226
- device['swapChainHeight'] = (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['height']) || height;
227
- renderPass.setViewport(0, 0, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['width']) || width, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['height']) || height);
228
-
229
- // @ts-ignore
230
- device['swapChainHeight'] = tmpHeight;
231
- renderPass.setPipeline(this.pipeline);
232
- renderPass.setStencilReference(1);
233
- renderPass.setVertexInput(this.inputLayout, this.vertexBuffers.map(function (buffer) {
234
- return {
235
- buffer: buffer
236
- };
237
- }), elements ? {
187
+ }
188
+ });
189
+ }
190
+ updateAttributesAndElements() {
191
+ }
192
+ /**
193
+ * No need to implement this method, you should update data on `Attribute` like this:
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * attribute.updateBuffer({
198
+ * data: [],
199
+ * offset: 0,
200
+ * });
201
+ * ```
202
+ */
203
+ updateAttributes() {
204
+ }
205
+ addUniforms(uniforms) {
206
+ this.uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(uniforms));
207
+ }
208
+ draw(options, pick) {
209
+ const mergedOptions = __spreadValues(__spreadValues({}, this.options), options);
210
+ const {
211
+ count = 0,
212
+ instances,
213
+ elements,
214
+ uniforms = {},
215
+ uniformBuffers,
216
+ textures
217
+ } = mergedOptions;
218
+ this.uniforms = __spreadValues(__spreadValues({}, this.uniforms), this.extractUniforms(uniforms));
219
+ const { renderPass, currentFramebuffer, width, height, renderCache } = this.service;
220
+ this.pipeline = this.createPipeline(mergedOptions, pick);
221
+ const device = this.service["device"];
222
+ const tmpHeight = device["swapChainHeight"];
223
+ device["swapChainHeight"] = (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height;
224
+ renderPass.setViewport(
225
+ 0,
226
+ 0,
227
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["width"]) || width,
228
+ (currentFramebuffer == null ? void 0 : currentFramebuffer["height"]) || height
229
+ );
230
+ device["swapChainHeight"] = tmpHeight;
231
+ renderPass.setPipeline(this.pipeline);
232
+ renderPass.setStencilReference(1);
233
+ renderPass.setVertexInput(
234
+ this.inputLayout,
235
+ this.vertexBuffers.map((buffer) => ({
236
+ buffer
237
+ })),
238
+ elements ? {
238
239
  buffer: this.indexBuffer,
239
240
  offset: 0
240
- } : null);
241
- if (uniformBuffers) {
242
- // this.bindings = device.createBindings({
243
- this.bindings = renderCache.createBindings({
244
- pipeline: this.pipeline,
245
- uniformBufferBindings: uniformBuffers.map(function (uniformBuffer, i) {
246
- var buffer = uniformBuffer;
247
- return {
248
- binding: i,
249
- buffer: buffer.get(),
250
- size: buffer['size']
251
- };
252
- }),
253
- samplerBindings: textures === null || textures === void 0 ? void 0 : textures.map(function (t) {
254
- return {
255
- texture: t['texture'],
256
- sampler: t['sampler']
257
- };
258
- })
259
- });
260
- }
261
- if (this.bindings) {
262
- renderPass.setBindings(this.bindings);
263
- // Compatible to WebGL1.
264
- Object.keys(this.uniforms).forEach(function (uniformName) {
265
- var uniform = _this2.uniforms[uniformName];
266
- if (uniform instanceof DeviceTexture2D) {
267
- // @ts-ignore
268
- _this2.uniforms[uniformName] = uniform.get();
269
- } else if (uniform instanceof DeviceFramebuffer) {
270
- // @ts-ignore
271
- _this2.uniforms[uniformName] = uniform.get()['texture'];
272
- }
273
- });
274
- this.program.setUniformsLegacy(this.uniforms);
275
- }
276
- if (elements) {
277
- var indexCount = elements['count'];
278
- if (indexCount === 0) {
279
- renderPass.draw(count, instances);
280
- } else {
281
- renderPass.drawIndexed(indexCount, instances);
282
- }
283
- } else {
284
- renderPass.draw(count, instances);
285
- }
241
+ } : null
242
+ );
243
+ if (uniformBuffers) {
244
+ this.bindings = renderCache.createBindings({
245
+ pipeline: this.pipeline,
246
+ uniformBufferBindings: uniformBuffers.map((uniformBuffer, i) => {
247
+ const buffer = uniformBuffer;
248
+ return {
249
+ binding: i,
250
+ buffer: buffer.get(),
251
+ size: buffer["size"]
252
+ };
253
+ }),
254
+ samplerBindings: textures == null ? void 0 : textures.map((t) => ({
255
+ texture: t["texture"],
256
+ sampler: t["sampler"]
257
+ }))
258
+ });
286
259
  }
287
- }, {
288
- key: "destroy",
289
- value: function destroy() {
290
- var _this$vertexBuffers, _this$indexBuffer, _this$bindings;
291
- this.program.destroy();
292
- (_this$vertexBuffers = this.vertexBuffers) === null || _this$vertexBuffers === void 0 || _this$vertexBuffers.forEach(function (buffer) {
293
- return buffer.destroy();
260
+ if (this.bindings) {
261
+ renderPass.setBindings(this.bindings);
262
+ Object.keys(this.uniforms).forEach((uniformName) => {
263
+ const uniform = this.uniforms[uniformName];
264
+ if (uniform instanceof DeviceTexture2D) {
265
+ this.uniforms[uniformName] = uniform.get();
266
+ } else if (uniform instanceof DeviceFramebuffer) {
267
+ this.uniforms[uniformName] = uniform.get()["texture"];
268
+ }
294
269
  });
295
- (_this$indexBuffer = this.indexBuffer) === null || _this$indexBuffer === void 0 || _this$indexBuffer.destroy();
296
- (_this$bindings = this.bindings) === null || _this$bindings === void 0 || _this$bindings.destroy();
297
- this.inputLayout.destroy();
298
- this.pipeline.destroy();
299
- this.destroyed = true;
270
+ this.program.setUniformsLegacy(this.uniforms);
300
271
  }
301
- }, {
302
- key: "initDepthDrawParams",
303
- value: function initDepthDrawParams(_ref) {
304
- var depth = _ref.depth;
305
- if (depth) {
306
- return {
307
- enable: depth.enable === undefined ? true : !!depth.enable,
308
- mask: depth.mask === undefined ? true : !!depth.mask,
309
- func: depthFuncMap[depth.func || gl.LESS],
310
- range: depth.range || [0, 1]
311
- };
272
+ if (elements) {
273
+ const indexCount = elements["count"];
274
+ if (indexCount === 0) {
275
+ renderPass.draw(count, instances);
276
+ } else {
277
+ renderPass.drawIndexed(indexCount, instances);
312
278
  }
279
+ } else {
280
+ renderPass.draw(count, instances);
313
281
  }
314
- }, {
315
- key: "getBlendDrawParams",
316
- value: function getBlendDrawParams(_ref2) {
317
- var blend = _ref2.blend;
318
- var _ref3 = blend || {},
319
- enable = _ref3.enable,
320
- func = _ref3.func,
321
- equation = _ref3.equation,
322
- _ref3$color = _ref3.color,
323
- color = _ref3$color === void 0 ? [0, 0, 0, 0] : _ref3$color;
282
+ }
283
+ destroy() {
284
+ var _a, _b, _c;
285
+ this.program.destroy();
286
+ (_a = this.vertexBuffers) == null ? void 0 : _a.forEach((buffer) => buffer.destroy());
287
+ (_b = this.indexBuffer) == null ? void 0 : _b.destroy();
288
+ (_c = this.bindings) == null ? void 0 : _c.destroy();
289
+ this.inputLayout.destroy();
290
+ this.pipeline.destroy();
291
+ this.destroyed = true;
292
+ }
293
+ initDepthDrawParams({
294
+ depth
295
+ }) {
296
+ if (depth) {
324
297
  return {
325
- enable: !!enable,
326
- func: {
327
- srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
328
- srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
329
- dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
330
- dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
331
- },
332
- equation: {
333
- rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
334
- alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
335
- },
336
- color: color
298
+ enable: depth.enable === void 0 ? true : !!depth.enable,
299
+ mask: depth.mask === void 0 ? true : !!depth.mask,
300
+ func: depthFuncMap[depth.func || gl.LESS],
301
+ range: depth.range || [0, 1]
337
302
  };
338
303
  }
339
-
340
- /**
341
- * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
342
- */
343
- }, {
344
- key: "getStencilDrawParams",
345
- value: function getStencilDrawParams(_ref4) {
346
- var stencil = _ref4.stencil;
347
- var _ref5 = stencil || {},
348
- enable = _ref5.enable,
349
- _ref5$mask = _ref5.mask,
350
- mask = _ref5$mask === void 0 ? 0xffffffff : _ref5$mask,
351
- _ref5$func = _ref5.func,
352
- func = _ref5$func === void 0 ? {
353
- cmp: gl.ALWAYS,
354
- ref: 0,
355
- mask: 0xffffffff
356
- } : _ref5$func,
357
- _ref5$opFront = _ref5.opFront,
358
- opFront = _ref5$opFront === void 0 ? {
359
- fail: gl.KEEP,
360
- zfail: gl.KEEP,
361
- zpass: gl.KEEP
362
- } : _ref5$opFront,
363
- _ref5$opBack = _ref5.opBack,
364
- opBack = _ref5$opBack === void 0 ? {
365
- fail: gl.KEEP,
366
- zfail: gl.KEEP,
367
- zpass: gl.KEEP
368
- } : _ref5$opBack;
304
+ }
305
+ getBlendDrawParams({
306
+ blend
307
+ }) {
308
+ const { enable, func, equation, color = [0, 0, 0, 0] } = blend || {};
309
+ return {
310
+ enable: !!enable,
311
+ func: {
312
+ srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
313
+ srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
314
+ dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
315
+ dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
316
+ },
317
+ equation: {
318
+ rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
319
+ alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
320
+ },
321
+ color
322
+ };
323
+ }
324
+ /**
325
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
326
+ */
327
+ getStencilDrawParams({
328
+ stencil
329
+ }) {
330
+ const {
331
+ enable,
332
+ mask = 4294967295,
333
+ func = {
334
+ cmp: gl.ALWAYS,
335
+ ref: 0,
336
+ mask: 4294967295
337
+ },
338
+ opFront = {
339
+ fail: gl.KEEP,
340
+ zfail: gl.KEEP,
341
+ zpass: gl.KEEP
342
+ },
343
+ opBack = {
344
+ fail: gl.KEEP,
345
+ zfail: gl.KEEP,
346
+ zpass: gl.KEEP
347
+ }
348
+ } = stencil || {};
349
+ return {
350
+ enable: !!enable,
351
+ mask,
352
+ func: __spreadProps(__spreadValues({}, func), {
353
+ cmp: stencilFuncMap[func.cmp]
354
+ }),
355
+ opFront: {
356
+ fail: stencilOpMap[opFront.fail],
357
+ zfail: stencilOpMap[opFront.zfail],
358
+ zpass: stencilOpMap[opFront.zpass],
359
+ mask: func.mask
360
+ },
361
+ opBack: {
362
+ fail: stencilOpMap[opBack.fail],
363
+ zfail: stencilOpMap[opBack.zfail],
364
+ zpass: stencilOpMap[opBack.zpass],
365
+ mask: func.mask
366
+ }
367
+ };
368
+ }
369
+ /**
370
+ * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
371
+ */
372
+ initCullDrawParams({
373
+ cull
374
+ }) {
375
+ if (cull) {
376
+ const { enable, face = gl.BACK } = cull;
369
377
  return {
370
378
  enable: !!enable,
371
- mask: mask,
372
- func: _objectSpread(_objectSpread({}, func), {}, {
373
- cmp: stencilFuncMap[func.cmp]
374
- }),
375
- opFront: {
376
- fail: stencilOpMap[opFront.fail],
377
- zfail: stencilOpMap[opFront.zfail],
378
- zpass: stencilOpMap[opFront.zpass],
379
- mask: func.mask
380
- },
381
- opBack: {
382
- fail: stencilOpMap[opBack.fail],
383
- zfail: stencilOpMap[opBack.zfail],
384
- zpass: stencilOpMap[opBack.zpass],
385
- mask: func.mask
386
- }
379
+ face: cullFaceMap[face]
387
380
  };
388
381
  }
389
-
390
- /**
391
- * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
392
- */
393
- }, {
394
- key: "initCullDrawParams",
395
- value: function initCullDrawParams(_ref6) {
396
- var cull = _ref6.cull;
397
- if (cull) {
398
- var enable = cull.enable,
399
- _cull$face = cull.face,
400
- face = _cull$face === void 0 ? gl.BACK : _cull$face;
401
- return {
402
- enable: !!enable,
403
- face: cullFaceMap[face]
404
- };
405
- }
382
+ }
383
+ /**
384
+ * 考虑结构体命名, eg:
385
+ * a: { b: 1 } -> 'a.b'
386
+ * a: [ { b: 1 } ] -> 'a[0].b'
387
+ */
388
+ extractUniforms(uniforms) {
389
+ const extractedUniforms = {};
390
+ Object.keys(uniforms).forEach((uniformName) => {
391
+ this.extractUniformsRecursively(
392
+ uniformName,
393
+ uniforms[uniformName],
394
+ extractedUniforms,
395
+ ""
396
+ );
397
+ });
398
+ return extractedUniforms;
399
+ }
400
+ extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
401
+ if (uniformValue === null || typeof uniformValue === "number" || // u_A: 1
402
+ typeof uniformValue === "boolean" || // u_A: false
403
+ Array.isArray(uniformValue) && typeof uniformValue[0] === "number" || // u_A: [1, 2, 3]
404
+ isTypedArray(uniformValue) || // u_A: Float32Array
405
+ // @ts-ignore
406
+ uniformValue === "" || "resize" in uniformValue) {
407
+ uniforms[`${prefix && prefix + "."}${uniformName}`] = uniformValue;
408
+ return;
406
409
  }
407
-
408
- /**
409
- * 考虑结构体命名, eg:
410
- * a: { b: 1 } -> 'a.b'
411
- * a: [ { b: 1 } ] -> 'a[0].b'
412
- */
413
- }, {
414
- key: "extractUniforms",
415
- value: function extractUniforms(uniforms) {
416
- var _this3 = this;
417
- var extractedUniforms = {};
418
- Object.keys(uniforms).forEach(function (uniformName) {
419
- _this3.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, '');
410
+ if (isPlainObject(uniformValue)) {
411
+ Object.keys(uniformValue).forEach((childName) => {
412
+ this.extractUniformsRecursively(
413
+ childName,
414
+ // @ts-ignore
415
+ uniformValue[childName],
416
+ uniforms,
417
+ `${prefix && prefix + "."}${uniformName}`
418
+ );
420
419
  });
421
- return extractedUniforms;
422
420
  }
423
- }, {
424
- key: "extractUniformsRecursively",
425
- value: function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
426
- var _this4 = this;
427
- if (uniformValue === null || typeof uniformValue === 'number' ||
428
- // u_A: 1
429
- typeof uniformValue === 'boolean' ||
430
- // u_A: false
431
- Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
432
- // u_A: [1, 2, 3]
433
- isTypedArray(uniformValue) ||
434
- // u_A: Float32Array
435
- // @ts-ignore
436
- uniformValue === '' || 'resize' in uniformValue) {
437
- uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
438
- return;
439
- }
440
-
441
- // u_Struct.a.b.c
442
- if (isPlainObject(uniformValue)) {
443
- Object.keys(uniformValue).forEach(function (childName) {
444
- _this4.extractUniformsRecursively(childName,
445
- // @ts-ignore
446
- uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
447
- });
448
- }
449
-
450
- // u_Struct[0].a
451
- if (Array.isArray(uniformValue)) {
452
- uniformValue.forEach(function (child, idx) {
453
- Object.keys(child).forEach(function (childName) {
454
- _this4.extractUniformsRecursively(childName,
421
+ if (Array.isArray(uniformValue)) {
422
+ uniformValue.forEach((child, idx) => {
423
+ Object.keys(child).forEach((childName) => {
424
+ this.extractUniformsRecursively(
425
+ childName,
455
426
  // @ts-ignore
456
- child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));
457
- });
427
+ child[childName],
428
+ uniforms,
429
+ `${prefix && prefix + "."}${uniformName}[${idx}]`
430
+ );
458
431
  });
459
- }
432
+ });
460
433
  }
461
- }]);
462
- return DeviceModel;
463
- }();
464
- export { DeviceModel as default };
434
+ }
435
+ };
436
+ export {
437
+ DeviceModel as default
438
+ };