@antv/l7-renderer 2.20.12 → 2.20.14

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.
@@ -0,0 +1,12 @@
1
+ import type { Bindings, BindingsDescriptor, Device, InputLayout, InputLayoutDescriptor, RenderPipeline, RenderPipelineDescriptor } from '@antv/g-device-api';
2
+ export declare class RenderCache {
3
+ private device;
4
+ constructor(device: Device);
5
+ private bindingsCache;
6
+ private renderPipelinesCache;
7
+ private inputLayoutsCache;
8
+ createBindings(descriptor: BindingsDescriptor): Bindings;
9
+ createRenderPipeline(descriptor: RenderPipelineDescriptor): RenderPipeline;
10
+ createInputLayout(descriptor: InputLayoutDescriptor): InputLayout;
11
+ destroy(): void;
12
+ }
@@ -0,0 +1,197 @@
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";
9
+ function blendStateHash(hash, a) {
10
+ hash = hashCodeNumberUpdate(hash, a.blendMode);
11
+ hash = hashCodeNumberUpdate(hash, a.blendSrcFactor);
12
+ hash = hashCodeNumberUpdate(hash, a.blendDstFactor);
13
+ return hash;
14
+ }
15
+ function attachmentStateHash(hash, a) {
16
+ hash = blendStateHash(hash, a.rgbBlendState);
17
+ hash = blendStateHash(hash, a.alphaBlendState);
18
+ hash = hashCodeNumberUpdate(hash, a.channelWriteMask);
19
+ return hash;
20
+ }
21
+ function colorHash(hash, a) {
22
+ hash = hashCodeNumberUpdate(hash, a.r << 24 | a.g << 16 | a.b << 8 | a.a);
23
+ return hash;
24
+ }
25
+ 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]);
28
+ hash = colorHash(hash, a.blendConstant || TransparentBlack);
29
+ hash = hashCodeNumberUpdate(hash, a.depthCompare);
30
+ 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);
39
+ hash = hashCodeNumberUpdate(hash, a.stencilWrite ? 1 : 0);
40
+ hash = hashCodeNumberUpdate(hash, a.cullMode);
41
+ hash = hashCodeNumberUpdate(hash, a.frontFace ? 1 : 0);
42
+ hash = hashCodeNumberUpdate(hash, a.polygonOffset ? 1 : 0);
43
+ return hash;
44
+ }
45
+ function renderPipelineDescriptorHash(a) {
46
+ var hash = 0;
47
+ hash = hashCodeNumberUpdate(hash, a.program.id);
48
+ if (a.inputLayout !== null) hash = hashCodeNumberUpdate(hash, a.inputLayout.id);
49
+ hash = megaStateDescriptorHash(hash, a.megaStateDescriptor);
50
+ for (var i = 0; i < a.colorAttachmentFormats.length; i++) hash = hashCodeNumberUpdate(hash, a.colorAttachmentFormats[i] || 0);
51
+ hash = hashCodeNumberUpdate(hash, a.depthStencilAttachmentFormat || 0);
52
+ return hashCodeNumberFinish(hash);
53
+ }
54
+ function bindingsDescriptorHash(a) {
55
+ var hash = 0;
56
+ 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);
60
+ }
61
+ }
62
+ 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);
70
+ }
71
+ }
72
+ }
73
+ 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);
81
+ }
82
+ }
83
+ }
84
+ 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);
90
+ }
91
+ }
92
+ }
93
+ return hashCodeNumberFinish(hash);
94
+ }
95
+ export var RenderCache = /*#__PURE__*/function () {
96
+ function RenderCache(device) {
97
+ _classCallCheck(this, RenderCache);
98
+ _defineProperty(this, "bindingsCache", new HashMap(bindingsDescriptorEquals, bindingsDescriptorHash));
99
+ _defineProperty(this, "renderPipelinesCache", new HashMap(renderPipelineDescriptorEquals, renderPipelineDescriptorHash));
100
+ _defineProperty(this, "inputLayoutsCache", new HashMap(inputLayoutDescriptorEquals, nullHashFunc));
101
+ this.device = device;
102
+ }
103
+ _createClass(RenderCache, [{
104
+ key: "createBindings",
105
+ value: function createBindings(descriptor) {
106
+ var bindings = this.bindingsCache.get(descriptor);
107
+ if (bindings === null) {
108
+ var _descriptorCopy$unifo;
109
+ var descriptorCopy = bindingsDescriptorCopy(descriptor);
110
+ descriptorCopy.uniformBufferBindings = (_descriptorCopy$unifo = descriptorCopy.uniformBufferBindings) === null || _descriptorCopy$unifo === void 0 ? void 0 : _descriptorCopy$unifo.filter(function (_ref) {
111
+ var size = _ref.size;
112
+ return size && size > 0;
113
+ });
114
+ bindings = this.device.createBindings(descriptorCopy);
115
+ this.bindingsCache.add(descriptorCopy, bindings);
116
+ }
117
+ return bindings;
118
+ }
119
+ }, {
120
+ key: "createRenderPipeline",
121
+ value: function createRenderPipeline(descriptor) {
122
+ var renderPipeline = this.renderPipelinesCache.get(descriptor);
123
+ if (renderPipeline === null) {
124
+ var descriptorCopy = renderPipelineDescriptorCopy(descriptor);
125
+ descriptorCopy.colorAttachmentFormats = descriptorCopy.colorAttachmentFormats.filter(function (f) {
126
+ return f;
127
+ });
128
+ renderPipeline = this.device.createRenderPipeline(descriptorCopy);
129
+ this.renderPipelinesCache.add(descriptorCopy, renderPipeline);
130
+ }
131
+ return renderPipeline;
132
+ }
133
+ }, {
134
+ key: "createInputLayout",
135
+ value: function createInputLayout(descriptor) {
136
+ // remove hollows
137
+ descriptor.vertexBufferDescriptors = descriptor.vertexBufferDescriptors.filter(function (d) {
138
+ return !!d;
139
+ });
140
+ var inputLayout = this.inputLayoutsCache.get(descriptor);
141
+ if (inputLayout === null) {
142
+ var descriptorCopy = inputLayoutDescriptorCopy(descriptor);
143
+ inputLayout = this.device.createInputLayout(descriptorCopy);
144
+ this.inputLayoutsCache.add(descriptorCopy, inputLayout);
145
+ }
146
+ return inputLayout;
147
+ }
148
+ }, {
149
+ key: "destroy",
150
+ value: function destroy() {
151
+ var _iterator = _createForOfIteratorHelper(this.bindingsCache.values()),
152
+ _step;
153
+ try {
154
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
155
+ var bindings = _step.value;
156
+ bindings.destroy();
157
+ }
158
+ } catch (err) {
159
+ _iterator.e(err);
160
+ } finally {
161
+ _iterator.f();
162
+ }
163
+ var _iterator2 = _createForOfIteratorHelper(this.renderPipelinesCache.values()),
164
+ _step2;
165
+ try {
166
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
167
+ var renderPipeline = _step2.value;
168
+ renderPipeline.destroy();
169
+ }
170
+ } catch (err) {
171
+ _iterator2.e(err);
172
+ } finally {
173
+ _iterator2.f();
174
+ }
175
+ var _iterator3 = _createForOfIteratorHelper(this.inputLayoutsCache.values()),
176
+ _step3;
177
+ try {
178
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
179
+ var inputLayout = _step3.value;
180
+ inputLayout.destroy();
181
+ }
182
+ // for (const program of this.programCache.values()) program.destroy();
183
+ // for (const sampler of this.samplerCache.values()) sampler.destroy();
184
+ } catch (err) {
185
+ _iterator3.e(err);
186
+ } finally {
187
+ _iterator3.f();
188
+ }
189
+ this.bindingsCache.clear();
190
+ this.renderPipelinesCache.clear();
191
+ this.inputLayoutsCache.clear();
192
+ // this.programCache.clear();
193
+ // this.samplerCache.clear();
194
+ }
195
+ }]);
196
+ return RenderCache;
197
+ }();
@@ -17,12 +17,19 @@ var DeviceFramebuffer = /*#__PURE__*/function () {
17
17
  _createClass(DeviceFramebuffer, [{
18
18
  key: "createColorRenderTarget",
19
19
  value: function createColorRenderTarget() {
20
+ var resize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20
21
  var _this$options = this.options,
21
22
  width = _this$options.width,
22
23
  height = _this$options.height,
23
24
  color = _this$options.color;
24
25
  if (color) {
25
26
  if (isTexture2D(color)) {
27
+ if (resize) {
28
+ color.resize({
29
+ width: width,
30
+ height: height
31
+ });
32
+ }
26
33
  this.colorTexture = color.get();
27
34
  this.colorRenderTarget = this.device.createRenderTargetFromTexture(this.colorTexture);
28
35
  this.width = color['width'];
@@ -43,6 +50,7 @@ var DeviceFramebuffer = /*#__PURE__*/function () {
43
50
  }, {
44
51
  key: "createDepthRenderTarget",
45
52
  value: function createDepthRenderTarget() {
53
+ var resize = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
46
54
  var _this$options2 = this.options,
47
55
  width = _this$options2.width,
48
56
  height = _this$options2.height,
@@ -50,6 +58,12 @@ var DeviceFramebuffer = /*#__PURE__*/function () {
50
58
  // TODO: avoid creating depth texture if not needed
51
59
  if (depth) {
52
60
  if (isTexture2D(depth)) {
61
+ if (resize) {
62
+ depth.resize({
63
+ width: width,
64
+ height: height
65
+ });
66
+ }
53
67
  this.depthTexture = depth.get();
54
68
  this.depthRenderTarget = this.device.createRenderTargetFromTexture(this.depthTexture);
55
69
  this.width = depth['width'];
@@ -86,10 +100,15 @@ var DeviceFramebuffer = /*#__PURE__*/function () {
86
100
  height = _ref.height;
87
101
  if (this.width !== width || this.height !== height) {
88
102
  this.destroy();
103
+ // Prevent double free texture.
104
+ // @ts-ignore
105
+ this.colorTexture.destroyed = true;
106
+ // @ts-ignore
107
+ this.depthTexture.destroyed = true;
89
108
  this.options.width = width;
90
109
  this.options.height = height;
91
- this.createColorRenderTarget();
92
- this.createDepthRenderTarget();
110
+ this.createColorRenderTarget(true);
111
+ this.createDepthRenderTarget(true);
93
112
  }
94
113
  }
95
114
  }]);
@@ -2,7 +2,7 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/esm/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
5
- import { BlendFactor, BlendMode, ChannelWriteMask, CompareFunction, CullMode, Format, StencilOp, TransparentBlack, VertexStepMode } from '@antv/g-device-api';
5
+ import { BlendFactor, BlendMode, ChannelWriteMask, CompareFunction, CullMode, Format, StencilOp, TransparentBlack, VertexStepMode, ViewportOrigin } from '@antv/g-device-api';
6
6
  import { gl } from '@antv/l7-core';
7
7
  import { lodashUtil } from '@antv/l7-utils';
8
8
  import DeviceFramebuffer from "./DeviceFramebuffer";
@@ -25,14 +25,19 @@ var DeviceModel = /*#__PURE__*/function () {
25
25
  attributes = options.attributes,
26
26
  uniforms = options.uniforms,
27
27
  count = options.count,
28
- elements = options.elements;
28
+ elements = options.elements,
29
+ diagnosticDerivativeUniformityEnabled = options.diagnosticDerivativeUniformityEnabled;
29
30
  this.options = options;
31
+ var diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? '' : this.service['viewportOrigin'] === ViewportOrigin.UPPER_LEFT ? 'diagnostic(off,derivative_uniformity);' : '';
30
32
  var program = device.createProgram({
31
33
  vertex: {
32
34
  glsl: vs
33
35
  },
34
36
  fragment: {
35
- glsl: fs
37
+ glsl: fs,
38
+ postprocess: function postprocess(fs) {
39
+ return diagnosticDerivativeUniformityHeader + fs;
40
+ }
36
41
  }
37
42
  });
38
43
  this.program = program;
@@ -78,7 +83,9 @@ var DeviceModel = /*#__PURE__*/function () {
78
83
  if (elements) {
79
84
  this.indexBuffer = elements.get();
80
85
  }
81
- var inputLayout = device.createInputLayout({
86
+
87
+ // const inputLayout = device.createInputLayout({
88
+ var inputLayout = service.renderCache.createInputLayout({
82
89
  vertexBufferDescriptors: vertexBufferDescriptors,
83
90
  indexBufferFormat: elements ? Format.U32_R : null,
84
91
  program: program
@@ -112,7 +119,9 @@ var DeviceModel = /*#__PURE__*/function () {
112
119
  stencil: stencil
113
120
  });
114
121
  var stencilEnabled = !!(stencilParams && stencilParams.enable);
115
- return this.device.createRenderPipeline({
122
+
123
+ // return this.device.createRenderPipeline({
124
+ return this.service.renderCache.createRenderPipeline({
116
125
  inputLayout: this.inputLayout,
117
126
  program: this.program,
118
127
  topology: primitiveMap[primitive],
@@ -151,11 +160,17 @@ var DeviceModel = /*#__PURE__*/function () {
151
160
  stencilWrite: stencilEnabled,
152
161
  stencilFront: {
153
162
  compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
154
- passOp: stencilParams.opFront.zpass
163
+ passOp: stencilParams.opFront.zpass,
164
+ failOp: stencilParams.opFront.fail,
165
+ depthFailOp: stencilParams.opFront.zfail,
166
+ mask: stencilParams.opFront.mask
155
167
  },
156
168
  stencilBack: {
157
169
  compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
158
- passOp: stencilParams.opBack.zpass
170
+ passOp: stencilParams.opBack.zpass,
171
+ failOp: stencilParams.opBack.fail,
172
+ depthFailOp: stencilParams.opBack.zfail,
173
+ mask: stencilParams.opBack.mask
159
174
  }
160
175
  }
161
176
  });
@@ -201,11 +216,22 @@ var DeviceModel = /*#__PURE__*/function () {
201
216
  renderPass = _this$service.renderPass,
202
217
  currentFramebuffer = _this$service.currentFramebuffer,
203
218
  width = _this$service.width,
204
- height = _this$service.height;
219
+ height = _this$service.height,
220
+ renderCache = _this$service.renderCache;
205
221
 
206
222
  // TODO: Recreate pipeline only when blend / cull changed.
207
223
  this.pipeline = this.createPipeline(mergedOptions, pick);
224
+
225
+ // const height = this.device['swapChainHeight'];
226
+ var device = this.service['device'];
227
+ // @ts-ignore
228
+ var tmpHeight = device['swapChainHeight'];
229
+ // @ts-ignore
230
+ device['swapChainHeight'] = (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['height']) || height;
208
231
  renderPass.setViewport(0, 0, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['width']) || width, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['height']) || height);
232
+
233
+ // @ts-ignore
234
+ device['swapChainHeight'] = tmpHeight;
209
235
  renderPass.setPipeline(this.pipeline);
210
236
  renderPass.setStencilReference(1);
211
237
  renderPass.setVertexInput(this.inputLayout, this.vertexBuffers.map(function (buffer) {
@@ -217,7 +243,8 @@ var DeviceModel = /*#__PURE__*/function () {
217
243
  offset: 0
218
244
  } : null);
219
245
  if (uniformBuffers) {
220
- this.bindings = this.device.createBindings({
246
+ // this.bindings = device.createBindings({
247
+ this.bindings = renderCache.createBindings({
221
248
  pipeline: this.pipeline,
222
249
  uniformBufferBindings: uniformBuffers.map(function (uniformBuffer, i) {
223
250
  var buffer = uniformBuffer;
@@ -352,12 +379,14 @@ var DeviceModel = /*#__PURE__*/function () {
352
379
  opFront: {
353
380
  fail: stencilOpMap[opFront.fail],
354
381
  zfail: stencilOpMap[opFront.zfail],
355
- zpass: stencilOpMap[opFront.zpass]
382
+ zpass: stencilOpMap[opFront.zpass],
383
+ mask: func.mask
356
384
  },
357
385
  opBack: {
358
386
  fail: stencilOpMap[opBack.fail],
359
387
  zfail: stencilOpMap[opBack.zfail],
360
- zpass: stencilOpMap[opBack.zpass]
388
+ zpass: stencilOpMap[opBack.zpass],
389
+ mask: func.mask
361
390
  }
362
391
  };
363
392
  }
@@ -2,12 +2,15 @@ import type { Device, Texture } from '@antv/g-device-api';
2
2
  import type { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
3
3
  export declare function isTexture2D(t: any): t is ITexture2D;
4
4
  export default class DeviceTexture2D implements ITexture2D {
5
+ private device;
6
+ private options;
5
7
  private texture;
6
8
  private sampler;
7
9
  private width;
8
10
  private height;
9
11
  private isDestroy;
10
12
  constructor(device: Device, options: ITexture2DInitializationOptions);
13
+ private createTexture;
11
14
  get(): Texture;
12
15
  update(props: any): void;
13
16
  bind(): void;
@@ -11,62 +11,20 @@ var DeviceTexture2D = /*#__PURE__*/function () {
11
11
  function DeviceTexture2D(device, options) {
12
12
  _classCallCheck(this, DeviceTexture2D);
13
13
  _defineProperty(this, "isDestroy", false);
14
- var data = options.data,
15
- _options$type = options.type,
16
- type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
17
- width = options.width,
18
- height = options.height,
19
- _options$flipY = options.flipY,
20
- flipY = _options$flipY === void 0 ? false : _options$flipY,
21
- _options$format = options.format,
22
- format = _options$format === void 0 ? gl.RGBA : _options$format,
23
- _options$wrapS = options.wrapS,
14
+ this.device = device;
15
+ this.options = options;
16
+ var _options$wrapS = options.wrapS,
24
17
  wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
25
18
  _options$wrapT = options.wrapT,
26
19
  wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
27
- _options$aniso = options.aniso,
28
- aniso = _options$aniso === void 0 ? 0 : _options$aniso,
29
- _options$alignment = options.alignment,
30
- alignment = _options$alignment === void 0 ? 1 : _options$alignment,
31
- _options$usage = options.usage,
32
- usage = _options$usage === void 0 ? TextureUsage.SAMPLED : _options$usage,
20
+ aniso = options.aniso,
33
21
  _options$mipmap = options.mipmap,
34
22
  mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
35
23
  _options$mag = options.mag,
36
24
  mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
37
25
  _options$min = options.min,
38
26
  min = _options$min === void 0 ? gl.NEAREST : _options$min;
39
- this.width = width;
40
- this.height = height;
41
- var pixelFormat = Format.U8_RGBA_RT;
42
- if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
43
- pixelFormat = Format.U8_RGBA_RT;
44
- } else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
45
- pixelFormat = Format.U8_LUMINANCE;
46
- } else if (type === gl.FLOAT && format === gl.RGB) {
47
- pixelFormat = Format.F32_RGB;
48
- } else if (type === gl.FLOAT && format === gl.RGBA) {
49
- pixelFormat = Format.F32_RGBA;
50
- } else if (type === gl.FLOAT && format === gl.RED) {
51
- pixelFormat = Format.F32_R;
52
- } else {
53
- throw new Error("create texture error, type: ".concat(type, ", format: ").concat(format));
54
- }
55
- this.texture = device.createTexture({
56
- format: pixelFormat,
57
- width: width,
58
- height: height,
59
- usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
60
- pixelStore: {
61
- unpackFlipY: flipY,
62
- packAlignment: alignment
63
- },
64
- mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0
65
- });
66
- if (data) {
67
- // @ts-ignore
68
- this.texture.setImageData([data]);
69
- }
27
+ this.createTexture(options);
70
28
  this.sampler = device.createSampler({
71
29
  addressModeU: wrapModeMap[wrapS],
72
30
  addressModeV: wrapModeMap[wrapT],
@@ -79,6 +37,62 @@ var DeviceTexture2D = /*#__PURE__*/function () {
79
37
  });
80
38
  }
81
39
  _createClass(DeviceTexture2D, [{
40
+ key: "createTexture",
41
+ value: function createTexture(options) {
42
+ var data = options.data,
43
+ _options$type = options.type,
44
+ type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
45
+ width = options.width,
46
+ height = options.height,
47
+ _options$flipY = options.flipY,
48
+ flipY = _options$flipY === void 0 ? false : _options$flipY,
49
+ _options$format = options.format,
50
+ format = _options$format === void 0 ? gl.RGBA : _options$format,
51
+ aniso = options.aniso,
52
+ _options$alignment = options.alignment,
53
+ alignment = _options$alignment === void 0 ? 1 : _options$alignment,
54
+ _options$usage = options.usage,
55
+ usage = _options$usage === void 0 ? TextureUsage.SAMPLED : _options$usage,
56
+ _options$unorm = options.unorm,
57
+ unorm = _options$unorm === void 0 ? false : _options$unorm,
58
+ label = options.label;
59
+ this.width = width;
60
+ this.height = height;
61
+ var pixelFormat = Format.U8_RGBA_RT;
62
+ if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
63
+ pixelFormat = unorm ? Format.U8_RGBA_NORM : Format.U8_RGBA_RT;
64
+ } else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
65
+ pixelFormat = Format.U8_LUMINANCE;
66
+ } else if (type === gl.FLOAT && format === gl.RGB) {
67
+ pixelFormat = Format.F32_RGB;
68
+ } else if (type === gl.FLOAT && format === gl.RGBA) {
69
+ pixelFormat = Format.F32_RGBA;
70
+ } else if (type === gl.FLOAT && format === gl.RED) {
71
+ pixelFormat = Format.F32_R;
72
+ } else {
73
+ throw new Error("create texture error, type: ".concat(type, ", format: ").concat(format));
74
+ }
75
+ this.texture = this.device.createTexture({
76
+ format: pixelFormat,
77
+ width: width,
78
+ height: height,
79
+ usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
80
+ pixelStore: {
81
+ unpackFlipY: flipY,
82
+ packAlignment: alignment
83
+ },
84
+ // mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
85
+ mipLevelCount: 1
86
+ });
87
+ if (label) {
88
+ this.device.setResourceName(this.texture, label);
89
+ }
90
+ if (data) {
91
+ // @ts-ignore
92
+ this.texture.setImageData([data]);
93
+ }
94
+ }
95
+ }, {
82
96
  key: "get",
83
97
  value: function get() {
84
98
  return this.texture;
@@ -99,9 +113,13 @@ var DeviceTexture2D = /*#__PURE__*/function () {
99
113
  value: function resize(_ref) {
100
114
  var width = _ref.width,
101
115
  height = _ref.height;
102
- // this.texture.resize(width, height);
103
- this.width = width;
104
- this.height = height;
116
+ if (this.width !== width || this.height !== height) {
117
+ this.destroy();
118
+ }
119
+ this.options.width = width;
120
+ this.options.height = height;
121
+ this.createTexture(this.options);
122
+ this.isDestroy = false;
105
123
  }
106
124
  }, {
107
125
  key: "getSize",
@@ -111,7 +129,8 @@ var DeviceTexture2D = /*#__PURE__*/function () {
111
129
  }, {
112
130
  key: "destroy",
113
131
  value: function destroy() {
114
- if (!this.isDestroy) {
132
+ // @ts-ignore
133
+ if (!this.isDestroy && !this.texture.destroyed) {
115
134
  var _this$texture;
116
135
  (_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
117
136
  }
@@ -1,6 +1,7 @@
1
1
  import type { RenderPass, RenderTarget, SwapChain } from '@antv/g-device-api';
2
2
  import type { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
3
3
  import 'reflect-metadata';
4
+ import { RenderCache } from './DeviceCache';
4
5
  import DeviceFramebuffer from './DeviceFramebuffer';
5
6
  /**
6
7
  * Device API renderer
@@ -19,14 +20,18 @@ export default class DeviceRendererService implements IRendererService {
19
20
  * Current render pass.
20
21
  */
21
22
  renderPass: RenderPass;
23
+ preRenderPass: RenderPass;
22
24
  mainColorRT: RenderTarget;
23
25
  mainDepthRT: RenderTarget;
26
+ renderCache: RenderCache;
24
27
  /**
25
28
  * Current FBO.
26
29
  */
27
30
  currentFramebuffer: DeviceFramebuffer | null;
28
31
  queryVerdorInfo: () => string;
32
+ private viewportOrigin;
29
33
  init(canvas: HTMLCanvasElement, cfg: IRenderConfig): Promise<void>;
34
+ private createMainColorDepthRT;
30
35
  beginFrame(): void;
31
36
  endFrame(): void;
32
37
  getPointSizeRange(): any;
@@ -38,6 +43,7 @@ export default class DeviceRendererService implements IRendererService {
38
43
  createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
39
44
  createFramebuffer: (options: IFramebufferInitializationOptions) => DeviceFramebuffer;
40
45
  useFramebuffer: (framebuffer: IFramebuffer | null, drawCommands: () => void) => void;
46
+ useFramebufferAsync: (framebuffer: IFramebuffer | null, drawCommands: () => Promise<void>) => Promise<void>;
41
47
  clear: (options: IClearOptions) => void;
42
48
  viewport: ({ width, height, }: {
43
49
  x: number;
@@ -46,6 +52,7 @@ export default class DeviceRendererService implements IRendererService {
46
52
  height: number;
47
53
  }) => void;
48
54
  readPixels: (options: IReadPixelsOptions) => Uint8Array;
55
+ readPixelsAsync: (options: IReadPixelsOptions) => Promise<Uint8Array>;
49
56
  getViewportSize: () => {
50
57
  width: number;
51
58
  height: number;