@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
package/es/device/DeviceModel.js
CHANGED
|
@@ -1,80 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
98
|
+
attributes: [
|
|
99
|
+
{
|
|
100
|
+
format: sizeFormatMap[size],
|
|
101
|
+
shaderLocation,
|
|
102
|
+
offset,
|
|
103
|
+
divisor
|
|
104
|
+
}
|
|
105
|
+
]
|
|
76
106
|
});
|
|
77
|
-
inferredCount = buffer[
|
|
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
|
-
|
|
86
|
-
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
this.
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
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
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
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
|
-
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
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
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
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
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
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
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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],
|
|
457
|
-
|
|
427
|
+
child[childName],
|
|
428
|
+
uniforms,
|
|
429
|
+
`${prefix && prefix + "."}${uniformName}[${idx}]`
|
|
430
|
+
);
|
|
458
431
|
});
|
|
459
|
-
}
|
|
432
|
+
});
|
|
460
433
|
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
434
|
+
}
|
|
435
|
+
};
|
|
436
|
+
export {
|
|
437
|
+
DeviceModel as default
|
|
438
|
+
};
|