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