@antv/l7-renderer 2.20.13 → 2.20.15
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.
- package/es/device/DeviceCache.d.ts +14 -0
- package/es/device/DeviceCache.js +235 -0
- package/es/device/DeviceFramebuffer.js +21 -2
- package/es/device/DeviceModel.js +40 -15
- package/es/device/DeviceTexture2D.d.ts +3 -0
- package/es/device/DeviceTexture2D.js +80 -51
- package/es/device/index.d.ts +7 -0
- package/es/device/index.js +149 -41
- package/es/device/utils/HashMap.d.ts +24 -0
- package/es/device/utils/HashMap.js +153 -0
- package/es/device/utils/typedarray.d.ts +5 -0
- package/es/device/utils/typedarray.js +18 -0
- package/es/regl/index.d.ts +2 -0
- package/es/regl/index.js +49 -15
- package/lib/device/DeviceCache.js +212 -0
- package/lib/device/DeviceFramebuffer.js +12 -4
- package/lib/device/DeviceModel.js +36 -14
- package/lib/device/DeviceTexture2D.js +52 -24
- package/lib/device/index.js +88 -8
- package/lib/device/utils/HashMap.js +113 -0
- package/lib/device/utils/typedarray.js +15 -0
- package/lib/regl/index.js +8 -0
- package/package.json +6 -6
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Bindings, BindingsDescriptor, Device, InputLayout, InputLayoutDescriptor, Program, ProgramDescriptor, 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
|
+
private programCache;
|
|
9
|
+
createBindings(descriptor: BindingsDescriptor): Bindings;
|
|
10
|
+
createRenderPipeline(descriptor: RenderPipelineDescriptor): RenderPipeline;
|
|
11
|
+
createInputLayout(descriptor: InputLayoutDescriptor): InputLayout;
|
|
12
|
+
createProgram(descriptor: ProgramDescriptor): Program;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,235 @@
|
|
|
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
|
+
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);
|
|
98
|
+
}
|
|
99
|
+
function programDescriptorCopy(a) {
|
|
100
|
+
var _a$vertex2, _a$fragment2;
|
|
101
|
+
return {
|
|
102
|
+
vertex: {
|
|
103
|
+
glsl: (_a$vertex2 = a.vertex) === null || _a$vertex2 === void 0 ? void 0 : _a$vertex2.glsl
|
|
104
|
+
},
|
|
105
|
+
fragment: {
|
|
106
|
+
glsl: (_a$fragment2 = a.fragment) === null || _a$fragment2 === void 0 ? void 0 : _a$fragment2.glsl
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
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));
|
|
117
|
+
this.device = device;
|
|
118
|
+
}
|
|
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;
|
|
148
|
+
}
|
|
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;
|
|
163
|
+
}
|
|
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;
|
|
174
|
+
}
|
|
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();
|
|
232
|
+
}
|
|
233
|
+
}]);
|
|
234
|
+
return RenderCache;
|
|
235
|
+
}();
|
|
@@ -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
|
}]);
|
package/es/device/DeviceModel.js
CHANGED
|
@@ -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,17 +25,21 @@ 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;
|
|
30
|
-
var
|
|
31
|
+
var diagnosticDerivativeUniformityHeader = diagnosticDerivativeUniformityEnabled ? '' : this.service['viewportOrigin'] === ViewportOrigin.UPPER_LEFT ? 'diagnostic(off,derivative_uniformity);' : '';
|
|
32
|
+
this.program = service.renderCache.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
|
-
this.program = program;
|
|
39
43
|
if (uniforms) {
|
|
40
44
|
this.uniforms = this.extractUniforms(uniforms);
|
|
41
45
|
}
|
|
@@ -78,10 +82,10 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
78
82
|
if (elements) {
|
|
79
83
|
this.indexBuffer = elements.get();
|
|
80
84
|
}
|
|
81
|
-
var inputLayout =
|
|
85
|
+
var inputLayout = service.renderCache.createInputLayout({
|
|
82
86
|
vertexBufferDescriptors: vertexBufferDescriptors,
|
|
83
87
|
indexBufferFormat: elements ? Format.U32_R : null,
|
|
84
|
-
program: program
|
|
88
|
+
program: this.program
|
|
85
89
|
});
|
|
86
90
|
this.inputLayout = inputLayout;
|
|
87
91
|
this.pipeline = this.createPipeline(options);
|
|
@@ -113,6 +117,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
113
117
|
});
|
|
114
118
|
var stencilEnabled = !!(stencilParams && stencilParams.enable);
|
|
115
119
|
return this.device.createRenderPipeline({
|
|
120
|
+
// return this.service.renderCache.createRenderPipeline({
|
|
116
121
|
inputLayout: this.inputLayout,
|
|
117
122
|
program: this.program,
|
|
118
123
|
topology: primitiveMap[primitive],
|
|
@@ -151,11 +156,17 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
151
156
|
stencilWrite: stencilEnabled,
|
|
152
157
|
stencilFront: {
|
|
153
158
|
compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
|
|
154
|
-
passOp: stencilParams.opFront.zpass
|
|
159
|
+
passOp: stencilParams.opFront.zpass,
|
|
160
|
+
failOp: stencilParams.opFront.fail,
|
|
161
|
+
depthFailOp: stencilParams.opFront.zfail,
|
|
162
|
+
mask: stencilParams.opFront.mask
|
|
155
163
|
},
|
|
156
164
|
stencilBack: {
|
|
157
165
|
compare: stencilEnabled ? stencilParams.func.cmp : CompareFunction.ALWAYS,
|
|
158
|
-
passOp: stencilParams.opBack.zpass
|
|
166
|
+
passOp: stencilParams.opBack.zpass,
|
|
167
|
+
failOp: stencilParams.opBack.fail,
|
|
168
|
+
depthFailOp: stencilParams.opBack.zfail,
|
|
169
|
+
mask: stencilParams.opBack.mask
|
|
159
170
|
}
|
|
160
171
|
}
|
|
161
172
|
});
|
|
@@ -201,11 +212,22 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
201
212
|
renderPass = _this$service.renderPass,
|
|
202
213
|
currentFramebuffer = _this$service.currentFramebuffer,
|
|
203
214
|
width = _this$service.width,
|
|
204
|
-
height = _this$service.height
|
|
215
|
+
height = _this$service.height,
|
|
216
|
+
renderCache = _this$service.renderCache;
|
|
205
217
|
|
|
206
218
|
// TODO: Recreate pipeline only when blend / cull changed.
|
|
207
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;
|
|
208
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;
|
|
209
231
|
renderPass.setPipeline(this.pipeline);
|
|
210
232
|
renderPass.setStencilReference(1);
|
|
211
233
|
renderPass.setVertexInput(this.inputLayout, this.vertexBuffers.map(function (buffer) {
|
|
@@ -217,7 +239,8 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
217
239
|
offset: 0
|
|
218
240
|
} : null);
|
|
219
241
|
if (uniformBuffers) {
|
|
220
|
-
this.bindings =
|
|
242
|
+
// this.bindings = device.createBindings({
|
|
243
|
+
this.bindings = renderCache.createBindings({
|
|
221
244
|
pipeline: this.pipeline,
|
|
222
245
|
uniformBufferBindings: uniformBuffers.map(function (uniformBuffer, i) {
|
|
223
246
|
var buffer = uniformBuffer;
|
|
@@ -324,12 +347,12 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
324
347
|
var _ref5 = stencil || {},
|
|
325
348
|
enable = _ref5.enable,
|
|
326
349
|
_ref5$mask = _ref5.mask,
|
|
327
|
-
mask = _ref5$mask === void 0 ?
|
|
350
|
+
mask = _ref5$mask === void 0 ? 0xffffffff : _ref5$mask,
|
|
328
351
|
_ref5$func = _ref5.func,
|
|
329
352
|
func = _ref5$func === void 0 ? {
|
|
330
353
|
cmp: gl.ALWAYS,
|
|
331
354
|
ref: 0,
|
|
332
|
-
mask:
|
|
355
|
+
mask: 0xffffffff
|
|
333
356
|
} : _ref5$func,
|
|
334
357
|
_ref5$opFront = _ref5.opFront,
|
|
335
358
|
opFront = _ref5$opFront === void 0 ? {
|
|
@@ -352,12 +375,14 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
352
375
|
opFront: {
|
|
353
376
|
fail: stencilOpMap[opFront.fail],
|
|
354
377
|
zfail: stencilOpMap[opFront.zfail],
|
|
355
|
-
zpass: stencilOpMap[opFront.zpass]
|
|
378
|
+
zpass: stencilOpMap[opFront.zpass],
|
|
379
|
+
mask: func.mask
|
|
356
380
|
},
|
|
357
381
|
opBack: {
|
|
358
382
|
fail: stencilOpMap[opBack.fail],
|
|
359
383
|
zfail: stencilOpMap[opBack.zfail],
|
|
360
|
-
zpass: stencilOpMap[opBack.zpass]
|
|
384
|
+
zpass: stencilOpMap[opBack.zpass],
|
|
385
|
+
mask: func.mask
|
|
361
386
|
}
|
|
362
387
|
};
|
|
363
388
|
}
|
|
@@ -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;
|
|
@@ -4,6 +4,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
4
4
|
import { TextureUsage as DeviceTextureUsage, FilterMode, Format, MipmapFilterMode } from '@antv/g-device-api';
|
|
5
5
|
import { TextureUsage, gl } from '@antv/l7-core';
|
|
6
6
|
import { wrapModeMap } from "./constants";
|
|
7
|
+
import { extend3ChannelsTo4 } from "./utils/typedarray";
|
|
7
8
|
export function isTexture2D(t) {
|
|
8
9
|
return !!(t && t['texture']);
|
|
9
10
|
}
|
|
@@ -11,62 +12,20 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
11
12
|
function DeviceTexture2D(device, options) {
|
|
12
13
|
_classCallCheck(this, DeviceTexture2D);
|
|
13
14
|
_defineProperty(this, "isDestroy", false);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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,
|
|
15
|
+
this.device = device;
|
|
16
|
+
this.options = options;
|
|
17
|
+
var _options$wrapS = options.wrapS,
|
|
24
18
|
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
|
|
25
19
|
_options$wrapT = options.wrapT,
|
|
26
20
|
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
|
|
27
|
-
|
|
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,
|
|
21
|
+
aniso = options.aniso,
|
|
33
22
|
_options$mipmap = options.mipmap,
|
|
34
23
|
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
|
|
35
24
|
_options$mag = options.mag,
|
|
36
25
|
mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
|
|
37
26
|
_options$min = options.min,
|
|
38
27
|
min = _options$min === void 0 ? gl.NEAREST : _options$min;
|
|
39
|
-
this.
|
|
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
|
-
}
|
|
28
|
+
this.createTexture(options);
|
|
70
29
|
this.sampler = device.createSampler({
|
|
71
30
|
addressModeU: wrapModeMap[wrapS],
|
|
72
31
|
addressModeV: wrapModeMap[wrapT],
|
|
@@ -79,6 +38,71 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
79
38
|
});
|
|
80
39
|
}
|
|
81
40
|
_createClass(DeviceTexture2D, [{
|
|
41
|
+
key: "createTexture",
|
|
42
|
+
value: function createTexture(options) {
|
|
43
|
+
var _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
|
+
var data = options.data;
|
|
60
|
+
this.width = width;
|
|
61
|
+
this.height = height;
|
|
62
|
+
var pixelFormat = Format.U8_RGBA_RT;
|
|
63
|
+
if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
|
|
64
|
+
pixelFormat = unorm ? Format.U8_RGBA_NORM : Format.U8_RGBA_RT;
|
|
65
|
+
} else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
|
|
66
|
+
pixelFormat = Format.U8_LUMINANCE;
|
|
67
|
+
} else if (type === gl.FLOAT && format === gl.RGB) {
|
|
68
|
+
// @see https://github.com/antvis/L7/pull/2262
|
|
69
|
+
if (this.device.queryVendorInfo().platformString === 'WebGPU') {
|
|
70
|
+
if (data) {
|
|
71
|
+
// @ts-ignore
|
|
72
|
+
data = extend3ChannelsTo4(data, 0);
|
|
73
|
+
}
|
|
74
|
+
pixelFormat = Format.F32_RGBA;
|
|
75
|
+
} else {
|
|
76
|
+
pixelFormat = Format.F32_RGB;
|
|
77
|
+
}
|
|
78
|
+
} else if (type === gl.FLOAT && format === gl.RGBA) {
|
|
79
|
+
pixelFormat = Format.F32_RGBA;
|
|
80
|
+
} else if (type === gl.FLOAT && format === gl.RED) {
|
|
81
|
+
pixelFormat = Format.F32_R;
|
|
82
|
+
} else {
|
|
83
|
+
throw new Error("create texture error, type: ".concat(type, ", format: ").concat(format));
|
|
84
|
+
}
|
|
85
|
+
this.texture = this.device.createTexture({
|
|
86
|
+
format: pixelFormat,
|
|
87
|
+
width: width,
|
|
88
|
+
height: height,
|
|
89
|
+
usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
|
|
90
|
+
pixelStore: {
|
|
91
|
+
unpackFlipY: flipY,
|
|
92
|
+
packAlignment: alignment
|
|
93
|
+
},
|
|
94
|
+
// mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
|
|
95
|
+
mipLevelCount: 1
|
|
96
|
+
});
|
|
97
|
+
if (label) {
|
|
98
|
+
this.device.setResourceName(this.texture, label);
|
|
99
|
+
}
|
|
100
|
+
if (data) {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
this.texture.setImageData([data]);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
82
106
|
key: "get",
|
|
83
107
|
value: function get() {
|
|
84
108
|
return this.texture;
|
|
@@ -99,9 +123,13 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
99
123
|
value: function resize(_ref) {
|
|
100
124
|
var width = _ref.width,
|
|
101
125
|
height = _ref.height;
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
if (this.width !== width || this.height !== height) {
|
|
127
|
+
this.destroy();
|
|
128
|
+
}
|
|
129
|
+
this.options.width = width;
|
|
130
|
+
this.options.height = height;
|
|
131
|
+
this.createTexture(this.options);
|
|
132
|
+
this.isDestroy = false;
|
|
105
133
|
}
|
|
106
134
|
}, {
|
|
107
135
|
key: "getSize",
|
|
@@ -111,7 +139,8 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
111
139
|
}, {
|
|
112
140
|
key: "destroy",
|
|
113
141
|
value: function destroy() {
|
|
114
|
-
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
if (!this.isDestroy && !this.texture.destroyed) {
|
|
115
144
|
var _this$texture;
|
|
116
145
|
(_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
|
|
117
146
|
}
|