@antv/l7-renderer 2.19.11 → 2.20.0
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.d.ts +13 -0
- package/es/device/DeviceAttribute.js +44 -0
- package/es/device/DeviceBuffer.d.ts +18 -0
- package/es/device/DeviceBuffer.js +65 -0
- package/es/device/DeviceElements.d.ts +13 -0
- package/es/device/DeviceElements.js +52 -0
- package/es/device/DeviceFramebuffer.d.ts +15 -0
- package/es/device/DeviceFramebuffer.js +58 -0
- package/es/device/DeviceModel.d.ts +36 -0
- package/es/device/DeviceModel.js +414 -0
- package/es/device/DeviceTexture2D.d.ts +20 -0
- package/es/device/DeviceTexture2D.js +116 -0
- package/es/device/constants.d.ts +29 -0
- package/es/device/constants.js +32 -0
- package/es/device/index.d.ts +53 -0
- package/es/device/index.js +319 -0
- package/es/device/utils/pipeline.d.ts +1 -0
- package/es/device/utils/pipeline.js +1 -0
- package/es/device/utils/typedarray.d.ts +2 -0
- package/es/device/utils/typedarray.js +16 -0
- package/es/device/utils/webgl.d.ts +1 -0
- package/es/device/utils/webgl.js +9 -0
- package/es/index.d.ts +2 -1
- package/es/index.js +2 -1
- package/es/regl/ReglModel.js +20 -6
- package/es/regl/ReglTexture2D.js +1 -1
- package/es/regl/index.d.ts +3 -0
- package/es/regl/index.js +10 -3
- package/lib/device/DeviceAttribute.js +58 -0
- package/lib/device/DeviceBuffer.js +68 -0
- package/lib/device/DeviceElements.js +66 -0
- package/lib/device/DeviceFramebuffer.js +67 -0
- package/lib/device/DeviceModel.js +370 -0
- package/lib/device/DeviceTexture2D.js +119 -0
- package/lib/device/constants.js +117 -0
- package/lib/device/index.js +189 -0
- package/lib/device/utils/pipeline.js +30 -0
- package/lib/device/utils/typedarray.js +43 -0
- package/lib/device/utils/webgl.js +34 -0
- package/lib/index.js +3 -0
- package/lib/regl/ReglModel.js +16 -2
- package/lib/regl/index.js +5 -0
- package/package.json +15 -15
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
5
|
+
import { BlendFactor, BlendMode, ChannelWriteMask, CompareFunction, CullMode, Format, TransparentBlack, VertexStepMode } from '@antv/g-device-api';
|
|
6
|
+
import { gl } from '@antv/l7-core';
|
|
7
|
+
import { lodashUtil } from '@antv/l7-utils';
|
|
8
|
+
import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, sizeFormatMap } from "./constants";
|
|
9
|
+
var isPlainObject = lodashUtil.isPlainObject,
|
|
10
|
+
isTypedArray = lodashUtil.isTypedArray;
|
|
11
|
+
var DeviceModel = /*#__PURE__*/function () {
|
|
12
|
+
function DeviceModel(device, options) {
|
|
13
|
+
var _this = this;
|
|
14
|
+
_classCallCheck(this, DeviceModel);
|
|
15
|
+
_defineProperty(this, "destroyed", false);
|
|
16
|
+
_defineProperty(this, "uniforms", {});
|
|
17
|
+
_defineProperty(this, "vertexBuffers", []);
|
|
18
|
+
this.device = device;
|
|
19
|
+
this.options = options;
|
|
20
|
+
var vs = options.vs,
|
|
21
|
+
fs = options.fs,
|
|
22
|
+
attributes = options.attributes,
|
|
23
|
+
uniforms = options.uniforms,
|
|
24
|
+
count = options.count,
|
|
25
|
+
elements = options.elements;
|
|
26
|
+
this.options = options;
|
|
27
|
+
var program = device.createProgram({
|
|
28
|
+
vertex: {
|
|
29
|
+
glsl: vs
|
|
30
|
+
},
|
|
31
|
+
fragment: {
|
|
32
|
+
glsl: fs
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.program = program;
|
|
36
|
+
if (uniforms) {
|
|
37
|
+
this.uniforms = this.extractUniforms(uniforms);
|
|
38
|
+
}
|
|
39
|
+
var vertexBufferDescriptors = [];
|
|
40
|
+
|
|
41
|
+
// Infer count from data if not provided.
|
|
42
|
+
var inferredCount = 0;
|
|
43
|
+
Object.keys(attributes).forEach(function (name) {
|
|
44
|
+
var attribute = attributes[name];
|
|
45
|
+
var buffer = attribute.get();
|
|
46
|
+
// Bind at each frame.
|
|
47
|
+
_this.vertexBuffers.push(buffer.get());
|
|
48
|
+
var _attribute$attribute = attribute['attribute'],
|
|
49
|
+
_attribute$attribute$ = _attribute$attribute.offset,
|
|
50
|
+
offset = _attribute$attribute$ === void 0 ? 0 : _attribute$attribute$,
|
|
51
|
+
_attribute$attribute$2 = _attribute$attribute.stride,
|
|
52
|
+
stride = _attribute$attribute$2 === void 0 ? 0 : _attribute$attribute$2,
|
|
53
|
+
_attribute$attribute$3 = _attribute$attribute.size,
|
|
54
|
+
size = _attribute$attribute$3 === void 0 ? 1 : _attribute$attribute$3,
|
|
55
|
+
_attribute$attribute$4 = _attribute$attribute.divisor,
|
|
56
|
+
divisor = _attribute$attribute$4 === void 0 ? 0 : _attribute$attribute$4,
|
|
57
|
+
_attribute$attribute$5 = _attribute$attribute.shaderLocation,
|
|
58
|
+
shaderLocation = _attribute$attribute$5 === void 0 ? 0 : _attribute$attribute$5;
|
|
59
|
+
vertexBufferDescriptors.push({
|
|
60
|
+
arrayStride: stride || size * 4,
|
|
61
|
+
// TODO: L7 hasn't use instanced array for now.
|
|
62
|
+
stepMode: VertexStepMode.VERTEX,
|
|
63
|
+
attributes: [{
|
|
64
|
+
format: sizeFormatMap[size],
|
|
65
|
+
shaderLocation: shaderLocation,
|
|
66
|
+
offset: offset,
|
|
67
|
+
divisor: divisor
|
|
68
|
+
}]
|
|
69
|
+
});
|
|
70
|
+
inferredCount = buffer['size'] / size;
|
|
71
|
+
});
|
|
72
|
+
if (!count) {
|
|
73
|
+
this.options.count = inferredCount;
|
|
74
|
+
}
|
|
75
|
+
if (elements) {
|
|
76
|
+
this.indexBuffer = elements.get();
|
|
77
|
+
}
|
|
78
|
+
var inputLayout = device.createInputLayout({
|
|
79
|
+
vertexBufferDescriptors: vertexBufferDescriptors,
|
|
80
|
+
indexBufferFormat: elements ? Format.U32_R : null,
|
|
81
|
+
program: program
|
|
82
|
+
});
|
|
83
|
+
this.inputLayout = inputLayout;
|
|
84
|
+
this.pipeline = this.createPipeline(options);
|
|
85
|
+
}
|
|
86
|
+
_createClass(DeviceModel, [{
|
|
87
|
+
key: "createPipeline",
|
|
88
|
+
value: function createPipeline(options) {
|
|
89
|
+
var _options$primitive = options.primitive,
|
|
90
|
+
primitive = _options$primitive === void 0 ? gl.TRIANGLES : _options$primitive,
|
|
91
|
+
depth = options.depth,
|
|
92
|
+
cull = options.cull,
|
|
93
|
+
blend = options.blend;
|
|
94
|
+
var depthParams = this.initDepthDrawParams({
|
|
95
|
+
depth: depth
|
|
96
|
+
});
|
|
97
|
+
var depthEnabled = !!(depthParams && depthParams.enable);
|
|
98
|
+
var cullParams = this.initCullDrawParams({
|
|
99
|
+
cull: cull
|
|
100
|
+
});
|
|
101
|
+
var cullEnabled = !!(cullParams && cullParams.enable);
|
|
102
|
+
var blendParams = this.getBlendDrawParams({
|
|
103
|
+
blend: blend
|
|
104
|
+
});
|
|
105
|
+
var blendEnabled = !!(blendParams && blendParams.enable);
|
|
106
|
+
return this.device.createRenderPipeline({
|
|
107
|
+
inputLayout: this.inputLayout,
|
|
108
|
+
program: this.program,
|
|
109
|
+
topology: primitiveMap[primitive],
|
|
110
|
+
colorAttachmentFormats: [Format.U8_RGBA_RT],
|
|
111
|
+
depthStencilAttachmentFormat: Format.D24_S8,
|
|
112
|
+
megaStateDescriptor: {
|
|
113
|
+
attachmentsState: [{
|
|
114
|
+
channelWriteMask: ChannelWriteMask.ALL,
|
|
115
|
+
rgbBlendState: {
|
|
116
|
+
blendMode: blendEnabled && blendParams.equation.rgb || BlendMode.ADD,
|
|
117
|
+
blendSrcFactor: blendEnabled && blendParams.func.srcRGB || BlendFactor.SRC_ALPHA,
|
|
118
|
+
blendDstFactor: blendEnabled && blendParams.func.dstRGB || BlendFactor.ONE_MINUS_SRC_ALPHA
|
|
119
|
+
},
|
|
120
|
+
alphaBlendState: {
|
|
121
|
+
blendMode: blendEnabled && blendParams.equation.alpha || BlendMode.ADD,
|
|
122
|
+
blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || BlendFactor.ONE,
|
|
123
|
+
blendDstFactor: blendEnabled && blendParams.func.dstAlpha || BlendFactor.ONE_MINUS_SRC_ALPHA
|
|
124
|
+
}
|
|
125
|
+
}],
|
|
126
|
+
blendConstant: TransparentBlack,
|
|
127
|
+
depthWrite: depthEnabled,
|
|
128
|
+
depthCompare: depthEnabled && depthParams.func || CompareFunction.LESS,
|
|
129
|
+
cullMode: cullEnabled && cullParams.face || CullMode.NONE,
|
|
130
|
+
stencilWrite: false
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}, {
|
|
135
|
+
key: "updateAttributesAndElements",
|
|
136
|
+
value: function updateAttributesAndElements()
|
|
137
|
+
// elements: IElements, // attributes: { [key: string]: IAttribute },
|
|
138
|
+
{
|
|
139
|
+
// TODO: implement
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "updateAttributes",
|
|
143
|
+
value: function updateAttributes() {// attributes: { [key: string]: IAttribute }
|
|
144
|
+
// TODO: implement
|
|
145
|
+
// Object.keys(attributes).forEach((name: string) => {
|
|
146
|
+
// const attribute = attributes[name] as DeviceAttribute;
|
|
147
|
+
// attribute.updateBuffer();
|
|
148
|
+
// });
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
key: "addUniforms",
|
|
152
|
+
value: function addUniforms(uniforms) {
|
|
153
|
+
this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
|
|
154
|
+
}
|
|
155
|
+
}, {
|
|
156
|
+
key: "draw",
|
|
157
|
+
value: function draw(options
|
|
158
|
+
// pick?: boolean
|
|
159
|
+
) {
|
|
160
|
+
var mergedOptions = _objectSpread(_objectSpread({}, this.options), options);
|
|
161
|
+
var _mergedOptions$count = mergedOptions.count,
|
|
162
|
+
count = _mergedOptions$count === void 0 ? 0 : _mergedOptions$count,
|
|
163
|
+
instances = mergedOptions.instances,
|
|
164
|
+
elements = mergedOptions.elements,
|
|
165
|
+
_mergedOptions$unifor = mergedOptions.uniforms,
|
|
166
|
+
uniforms = _mergedOptions$unifor === void 0 ? {} : _mergedOptions$unifor,
|
|
167
|
+
uniformBuffers = mergedOptions.uniformBuffers,
|
|
168
|
+
textures = mergedOptions.textures;
|
|
169
|
+
this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
|
|
170
|
+
|
|
171
|
+
// @ts-ignore
|
|
172
|
+
var _this$device = this.device,
|
|
173
|
+
width = _this$device.width,
|
|
174
|
+
height = _this$device.height;
|
|
175
|
+
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
// const renderTarget = this.device.currentFramebuffer;
|
|
178
|
+
// const { onscreen } = renderTarget
|
|
179
|
+
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
var renderPass = this.device.renderPass;
|
|
182
|
+
// TODO: Recreate pipeline only when blend / cull changed.
|
|
183
|
+
this.pipeline = this.createPipeline(mergedOptions);
|
|
184
|
+
renderPass.setPipeline(this.pipeline);
|
|
185
|
+
renderPass.setVertexInput(this.inputLayout, this.vertexBuffers.map(function (buffer) {
|
|
186
|
+
return {
|
|
187
|
+
buffer: buffer
|
|
188
|
+
};
|
|
189
|
+
}), elements ? {
|
|
190
|
+
buffer: this.indexBuffer,
|
|
191
|
+
offset: 0 // TODO: use defaule value
|
|
192
|
+
} : null);
|
|
193
|
+
renderPass.setViewport(0, 0, width, height);
|
|
194
|
+
if (uniformBuffers) {
|
|
195
|
+
this.bindings = this.device.createBindings({
|
|
196
|
+
pipeline: this.pipeline,
|
|
197
|
+
uniformBufferBindings: uniformBuffers.map(function (uniformBuffer, i) {
|
|
198
|
+
var buffer = uniformBuffer;
|
|
199
|
+
return {
|
|
200
|
+
binding: i,
|
|
201
|
+
buffer: buffer.get(),
|
|
202
|
+
size: buffer['size']
|
|
203
|
+
};
|
|
204
|
+
}),
|
|
205
|
+
samplerBindings: textures === null || textures === void 0 ? void 0 : textures.map(function (t) {
|
|
206
|
+
return {
|
|
207
|
+
texture: t['texture'],
|
|
208
|
+
sampler: t['sampler']
|
|
209
|
+
};
|
|
210
|
+
})
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (this.bindings) {
|
|
214
|
+
renderPass.setBindings(this.bindings);
|
|
215
|
+
// Compatible to WebGL1.
|
|
216
|
+
this.program.setUniformsLegacy(this.uniforms);
|
|
217
|
+
}
|
|
218
|
+
if (elements) {
|
|
219
|
+
var indexCount = elements['count'];
|
|
220
|
+
if (indexCount === 0) {
|
|
221
|
+
renderPass.draw(count, instances);
|
|
222
|
+
} else {
|
|
223
|
+
renderPass.drawIndexed(indexCount, instances);
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
renderPass.draw(count, instances);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}, {
|
|
230
|
+
key: "destroy",
|
|
231
|
+
value: function destroy() {
|
|
232
|
+
var _this$vertexBuffers, _this$indexBuffer, _this$bindings;
|
|
233
|
+
this.program.destroy();
|
|
234
|
+
(_this$vertexBuffers = this.vertexBuffers) === null || _this$vertexBuffers === void 0 || _this$vertexBuffers.forEach(function (buffer) {
|
|
235
|
+
return buffer.destroy();
|
|
236
|
+
});
|
|
237
|
+
(_this$indexBuffer = this.indexBuffer) === null || _this$indexBuffer === void 0 || _this$indexBuffer.destroy();
|
|
238
|
+
(_this$bindings = this.bindings) === null || _this$bindings === void 0 || _this$bindings.destroy();
|
|
239
|
+
this.inputLayout.destroy();
|
|
240
|
+
this.pipeline.destroy();
|
|
241
|
+
this.destroyed = true;
|
|
242
|
+
}
|
|
243
|
+
}, {
|
|
244
|
+
key: "initDepthDrawParams",
|
|
245
|
+
value: function initDepthDrawParams(_ref) {
|
|
246
|
+
var depth = _ref.depth;
|
|
247
|
+
if (depth) {
|
|
248
|
+
return {
|
|
249
|
+
enable: depth.enable === undefined ? true : !!depth.enable,
|
|
250
|
+
mask: depth.mask === undefined ? true : !!depth.mask,
|
|
251
|
+
func: depthFuncMap[depth.func || gl.LESS],
|
|
252
|
+
range: depth.range || [0, 1]
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, {
|
|
257
|
+
key: "getBlendDrawParams",
|
|
258
|
+
value: function getBlendDrawParams(_ref2) {
|
|
259
|
+
var blend = _ref2.blend;
|
|
260
|
+
var _ref3 = blend || {},
|
|
261
|
+
enable = _ref3.enable,
|
|
262
|
+
func = _ref3.func,
|
|
263
|
+
equation = _ref3.equation,
|
|
264
|
+
_ref3$color = _ref3.color,
|
|
265
|
+
color = _ref3$color === void 0 ? [0, 0, 0, 0] : _ref3$color;
|
|
266
|
+
return {
|
|
267
|
+
enable: !!enable,
|
|
268
|
+
func: {
|
|
269
|
+
srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
|
|
270
|
+
srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
|
|
271
|
+
dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
|
|
272
|
+
dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
|
|
273
|
+
},
|
|
274
|
+
equation: {
|
|
275
|
+
rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
|
|
276
|
+
alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
|
|
277
|
+
},
|
|
278
|
+
color: color
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// /**
|
|
283
|
+
// * @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
|
|
284
|
+
// */
|
|
285
|
+
// private getStencilDrawParams({
|
|
286
|
+
// stencil,
|
|
287
|
+
// }: Pick<IModelInitializationOptions, 'stencil'>) {
|
|
288
|
+
// const {
|
|
289
|
+
// enable,
|
|
290
|
+
// mask = -1,
|
|
291
|
+
// func = {
|
|
292
|
+
// cmp: gl.ALWAYS,
|
|
293
|
+
// ref: 0,
|
|
294
|
+
// mask: -1,
|
|
295
|
+
// },
|
|
296
|
+
// opFront = {
|
|
297
|
+
// fail: gl.KEEP,
|
|
298
|
+
// zfail: gl.KEEP,
|
|
299
|
+
// zpass: gl.KEEP,
|
|
300
|
+
// },
|
|
301
|
+
// opBack = {
|
|
302
|
+
// fail: gl.KEEP,
|
|
303
|
+
// zfail: gl.KEEP,
|
|
304
|
+
// zpass: gl.KEEP,
|
|
305
|
+
// },
|
|
306
|
+
// } = stencil || {};
|
|
307
|
+
// return {
|
|
308
|
+
// enable: !!enable,
|
|
309
|
+
// mask,
|
|
310
|
+
// func: {
|
|
311
|
+
// ...func,
|
|
312
|
+
// cmp: stencilFuncMap[func.cmp],
|
|
313
|
+
// },
|
|
314
|
+
// opFront: {
|
|
315
|
+
// fail: stencilOpMap[opFront.fail],
|
|
316
|
+
// zfail: stencilOpMap[opFront.zfail],
|
|
317
|
+
// zpass: stencilOpMap[opFront.zpass],
|
|
318
|
+
// },
|
|
319
|
+
// opBack: {
|
|
320
|
+
// fail: stencilOpMap[opBack.fail],
|
|
321
|
+
// zfail: stencilOpMap[opBack.zfail],
|
|
322
|
+
// zpass: stencilOpMap[opBack.zpass],
|
|
323
|
+
// },
|
|
324
|
+
// };
|
|
325
|
+
// }
|
|
326
|
+
|
|
327
|
+
// private getColorMaskDrawParams(
|
|
328
|
+
// { stencil }: Pick<IModelInitializationOptions, 'stencil'>,
|
|
329
|
+
// pick: boolean,
|
|
330
|
+
// ) {
|
|
331
|
+
// // TODO: 重构相关参数
|
|
332
|
+
// // 掩膜模式下,颜色通道全部关闭
|
|
333
|
+
// const colorMask =
|
|
334
|
+
// stencil?.enable && stencil.opFront && !pick
|
|
335
|
+
// ? [false, false, false, false]
|
|
336
|
+
// : [true, true, true, true]; // 非掩码模式下,颜色通道全部开启
|
|
337
|
+
// return colorMask;
|
|
338
|
+
// }
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
|
|
342
|
+
*/
|
|
343
|
+
}, {
|
|
344
|
+
key: "initCullDrawParams",
|
|
345
|
+
value: function initCullDrawParams(_ref4) {
|
|
346
|
+
var cull = _ref4.cull;
|
|
347
|
+
if (cull) {
|
|
348
|
+
var enable = cull.enable,
|
|
349
|
+
_cull$face = cull.face,
|
|
350
|
+
face = _cull$face === void 0 ? gl.BACK : _cull$face;
|
|
351
|
+
return {
|
|
352
|
+
enable: !!enable,
|
|
353
|
+
face: cullFaceMap[face]
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* 考虑结构体命名, eg:
|
|
360
|
+
* a: { b: 1 } -> 'a.b'
|
|
361
|
+
* a: [ { b: 1 } ] -> 'a[0].b'
|
|
362
|
+
*/
|
|
363
|
+
}, {
|
|
364
|
+
key: "extractUniforms",
|
|
365
|
+
value: function extractUniforms(uniforms) {
|
|
366
|
+
var _this2 = this;
|
|
367
|
+
var extractedUniforms = {};
|
|
368
|
+
Object.keys(uniforms).forEach(function (uniformName) {
|
|
369
|
+
_this2.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, '');
|
|
370
|
+
});
|
|
371
|
+
return extractedUniforms;
|
|
372
|
+
}
|
|
373
|
+
}, {
|
|
374
|
+
key: "extractUniformsRecursively",
|
|
375
|
+
value: function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
|
|
376
|
+
var _this3 = this;
|
|
377
|
+
if (uniformValue === null || typeof uniformValue === 'number' ||
|
|
378
|
+
// u_A: 1
|
|
379
|
+
typeof uniformValue === 'boolean' ||
|
|
380
|
+
// u_A: false
|
|
381
|
+
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
|
|
382
|
+
// u_A: [1, 2, 3]
|
|
383
|
+
isTypedArray(uniformValue) ||
|
|
384
|
+
// u_A: Float32Array
|
|
385
|
+
// @ts-ignore
|
|
386
|
+
uniformValue === '' || 'resize' in uniformValue) {
|
|
387
|
+
uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// u_Struct.a.b.c
|
|
392
|
+
if (isPlainObject(uniformValue)) {
|
|
393
|
+
Object.keys(uniformValue).forEach(function (childName) {
|
|
394
|
+
_this3.extractUniformsRecursively(childName,
|
|
395
|
+
// @ts-ignore
|
|
396
|
+
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
// u_Struct[0].a
|
|
401
|
+
if (Array.isArray(uniformValue)) {
|
|
402
|
+
uniformValue.forEach(function (child, idx) {
|
|
403
|
+
Object.keys(child).forEach(function (childName) {
|
|
404
|
+
_this3.extractUniformsRecursively(childName,
|
|
405
|
+
// @ts-ignore
|
|
406
|
+
child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}]);
|
|
412
|
+
return DeviceModel;
|
|
413
|
+
}();
|
|
414
|
+
export { DeviceModel as default };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Device, Texture } from '@antv/g-device-api';
|
|
2
|
+
import { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
3
|
+
export declare function isTexture2D(t: any): t is ITexture2D;
|
|
4
|
+
export default class DeviceTexture2D implements ITexture2D {
|
|
5
|
+
private texture;
|
|
6
|
+
private sampler;
|
|
7
|
+
private width;
|
|
8
|
+
private height;
|
|
9
|
+
private isDestroy;
|
|
10
|
+
constructor(device: Device, options: ITexture2DInitializationOptions);
|
|
11
|
+
get(): Texture;
|
|
12
|
+
update(props: any): void;
|
|
13
|
+
bind(): void;
|
|
14
|
+
resize({ width, height }: {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
}): void;
|
|
18
|
+
getSize(): [number, number];
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import { FilterMode, Format, MipmapFilterMode, TextureUsage } from '@antv/g-device-api';
|
|
5
|
+
import { gl } from '@antv/l7-core';
|
|
6
|
+
import { wrapModeMap } from "./constants";
|
|
7
|
+
export function isTexture2D(t) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
var DeviceTexture2D = /*#__PURE__*/function () {
|
|
11
|
+
function DeviceTexture2D(device, options) {
|
|
12
|
+
_classCallCheck(this, DeviceTexture2D);
|
|
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,
|
|
24
|
+
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
|
|
25
|
+
_options$wrapT = options.wrapT,
|
|
26
|
+
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
|
|
27
|
+
_options$alignment = options.alignment,
|
|
28
|
+
alignment = _options$alignment === void 0 ? 1 : _options$alignment;
|
|
29
|
+
this.width = width;
|
|
30
|
+
this.height = height;
|
|
31
|
+
var pixelFormat = Format.U8_RGBA_RT;
|
|
32
|
+
if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
|
|
33
|
+
pixelFormat = Format.U8_RGBA_RT;
|
|
34
|
+
} else if (format === gl.LUMINANCE && type === gl.FLOAT) {
|
|
35
|
+
pixelFormat = Format.F32_LUMINANCE;
|
|
36
|
+
} else if (format === gl.LUMINANCE && type === gl.UNSIGNED_BYTE) {
|
|
37
|
+
pixelFormat = Format.U8_LUMINANCE;
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error("create texture error, type: ".concat(type, ", format: ").concat(format));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// // copy pixels from current bind framebuffer
|
|
43
|
+
// x,
|
|
44
|
+
// y,
|
|
45
|
+
// copy,
|
|
46
|
+
// };
|
|
47
|
+
|
|
48
|
+
this.texture = device.createTexture({
|
|
49
|
+
format: pixelFormat,
|
|
50
|
+
width: width,
|
|
51
|
+
height: height,
|
|
52
|
+
usage: TextureUsage.SAMPLED,
|
|
53
|
+
pixelStore: {
|
|
54
|
+
unpackFlipY: flipY,
|
|
55
|
+
packAlignment: alignment
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (data) {
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
this.texture.setImageData([data]);
|
|
61
|
+
}
|
|
62
|
+
this.sampler = device.createSampler({
|
|
63
|
+
addressModeU: wrapModeMap[wrapS],
|
|
64
|
+
addressModeV: wrapModeMap[wrapT],
|
|
65
|
+
minFilter: FilterMode.POINT,
|
|
66
|
+
// TODO: use mag & min
|
|
67
|
+
magFilter: FilterMode.BILINEAR,
|
|
68
|
+
mipmapFilter: MipmapFilterMode.NO_MIP,
|
|
69
|
+
lodMinClamp: 0,
|
|
70
|
+
lodMaxClamp: 0
|
|
71
|
+
// maxAnisotropy: aniso,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
_createClass(DeviceTexture2D, [{
|
|
75
|
+
key: "get",
|
|
76
|
+
value: function get() {
|
|
77
|
+
return this.texture;
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
key: "update",
|
|
81
|
+
value: function update(props) {
|
|
82
|
+
var data = props.data;
|
|
83
|
+
this.texture.setImageData([data]);
|
|
84
|
+
}
|
|
85
|
+
}, {
|
|
86
|
+
key: "bind",
|
|
87
|
+
value: function bind() {
|
|
88
|
+
// this.texture._texture.bind();
|
|
89
|
+
}
|
|
90
|
+
}, {
|
|
91
|
+
key: "resize",
|
|
92
|
+
value: function resize(_ref) {
|
|
93
|
+
var width = _ref.width,
|
|
94
|
+
height = _ref.height;
|
|
95
|
+
// this.texture.resize(width, height);
|
|
96
|
+
this.width = width;
|
|
97
|
+
this.height = height;
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "getSize",
|
|
101
|
+
value: function getSize() {
|
|
102
|
+
return [this.width, this.height];
|
|
103
|
+
}
|
|
104
|
+
}, {
|
|
105
|
+
key: "destroy",
|
|
106
|
+
value: function destroy() {
|
|
107
|
+
if (!this.isDestroy) {
|
|
108
|
+
var _this$texture;
|
|
109
|
+
(_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
|
|
110
|
+
}
|
|
111
|
+
this.isDestroy = true;
|
|
112
|
+
}
|
|
113
|
+
}]);
|
|
114
|
+
return DeviceTexture2D;
|
|
115
|
+
}();
|
|
116
|
+
export { DeviceTexture2D as default };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { AddressMode, BlendFactor, BlendMode, BufferFrequencyHint, CompareFunction, CullMode, Format, PrimitiveTopology } from '@antv/g-device-api';
|
|
2
|
+
import { TypedArray } from './utils/typedarray';
|
|
3
|
+
export declare const typedArrayCtorMap: {
|
|
4
|
+
[key: string]: new (data: number[]) => TypedArray;
|
|
5
|
+
};
|
|
6
|
+
export declare const primitiveMap: {
|
|
7
|
+
[key: string]: PrimitiveTopology;
|
|
8
|
+
};
|
|
9
|
+
export declare const sizeFormatMap: {
|
|
10
|
+
[key: number]: Format;
|
|
11
|
+
};
|
|
12
|
+
export declare const hintMap: {
|
|
13
|
+
[key: string]: BufferFrequencyHint;
|
|
14
|
+
};
|
|
15
|
+
export declare const wrapModeMap: {
|
|
16
|
+
[key: string]: AddressMode;
|
|
17
|
+
};
|
|
18
|
+
export declare const depthFuncMap: {
|
|
19
|
+
[key: string]: CompareFunction;
|
|
20
|
+
};
|
|
21
|
+
export declare const cullFaceMap: {
|
|
22
|
+
[key: string]: CullMode;
|
|
23
|
+
};
|
|
24
|
+
export declare const blendEquationMap: {
|
|
25
|
+
[key: string]: BlendMode;
|
|
26
|
+
};
|
|
27
|
+
export declare const blendFuncMap: {
|
|
28
|
+
[key: string]: BlendFactor;
|
|
29
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
var _typedArrayCtorMap, _primitiveMap, _sizeFormatMap, _hintMap, _wrapModeMap, _depthFuncMap, _cullFaceMap, _blendEquationMap, _blendFuncMap;
|
|
3
|
+
import { AddressMode, BlendFactor, BlendMode, BufferFrequencyHint, CompareFunction, CullMode, Format, PrimitiveTopology } from '@antv/g-device-api';
|
|
4
|
+
import { gl } from '@antv/l7-core';
|
|
5
|
+
export var typedArrayCtorMap = (_typedArrayCtorMap = {}, _defineProperty(_typedArrayCtorMap, gl.FLOAT, Float32Array), _defineProperty(_typedArrayCtorMap, gl.UNSIGNED_BYTE, Uint8Array), _defineProperty(_typedArrayCtorMap, gl.SHORT, Int16Array), _defineProperty(_typedArrayCtorMap, gl.UNSIGNED_SHORT, Uint16Array), _defineProperty(_typedArrayCtorMap, gl.INT, Int32Array), _defineProperty(_typedArrayCtorMap, gl.UNSIGNED_INT, Uint32Array), _typedArrayCtorMap);
|
|
6
|
+
export var primitiveMap = (_primitiveMap = {}, _defineProperty(_primitiveMap, gl.POINTS, PrimitiveTopology.POINTS), _defineProperty(_primitiveMap, gl.LINES, PrimitiveTopology.LINES), _defineProperty(_primitiveMap, gl.LINE_LOOP, PrimitiveTopology.LINES), _defineProperty(_primitiveMap, gl.LINE_STRIP, PrimitiveTopology.LINE_STRIP), _defineProperty(_primitiveMap, gl.TRIANGLES, PrimitiveTopology.TRIANGLES), _defineProperty(_primitiveMap, gl.TRIANGLE_FAN, PrimitiveTopology.TRIANGLES), _defineProperty(_primitiveMap, gl.TRIANGLE_STRIP, PrimitiveTopology.TRIANGLE_STRIP), _primitiveMap);
|
|
7
|
+
export var sizeFormatMap = (_sizeFormatMap = {}, _defineProperty(_sizeFormatMap, 1, Format.F32_R), _defineProperty(_sizeFormatMap, 2, Format.F32_RG), _defineProperty(_sizeFormatMap, 3, Format.F32_RGB), _defineProperty(_sizeFormatMap, 4, Format.F32_RGBA), _sizeFormatMap);
|
|
8
|
+
export var hintMap = (_hintMap = {}, _defineProperty(_hintMap, gl.STATIC_DRAW, BufferFrequencyHint.STATIC), _defineProperty(_hintMap, gl.DYNAMIC_DRAW, BufferFrequencyHint.DYNAMIC), _defineProperty(_hintMap, gl.STREAM_DRAW, BufferFrequencyHint.DYNAMIC), _hintMap);
|
|
9
|
+
export var wrapModeMap = (_wrapModeMap = {}, _defineProperty(_wrapModeMap, gl.REPEAT, AddressMode.REPEAT), _defineProperty(_wrapModeMap, gl.CLAMP_TO_EDGE, AddressMode.CLAMP_TO_EDGE), _defineProperty(_wrapModeMap, gl.MIRRORED_REPEAT, AddressMode.MIRRORED_REPEAT), _wrapModeMap);
|
|
10
|
+
export var depthFuncMap = (_depthFuncMap = {}, _defineProperty(_depthFuncMap, gl.NEVER, CompareFunction.NEVER), _defineProperty(_depthFuncMap, gl.ALWAYS, CompareFunction.ALWAYS), _defineProperty(_depthFuncMap, gl.LESS, CompareFunction.LESS), _defineProperty(_depthFuncMap, gl.LEQUAL, CompareFunction.LEQUAL), _defineProperty(_depthFuncMap, gl.GREATER, CompareFunction.GREATER), _defineProperty(_depthFuncMap, gl.GEQUAL, CompareFunction.GEQUAL), _defineProperty(_depthFuncMap, gl.EQUAL, CompareFunction.EQUAL), _defineProperty(_depthFuncMap, gl.NOTEQUAL, CompareFunction.NOTEQUAL), _depthFuncMap);
|
|
11
|
+
export var cullFaceMap = (_cullFaceMap = {}, _defineProperty(_cullFaceMap, gl.FRONT, CullMode.FRONT), _defineProperty(_cullFaceMap, gl.BACK, CullMode.BACK), _cullFaceMap);
|
|
12
|
+
export var blendEquationMap = (_blendEquationMap = {}, _defineProperty(_blendEquationMap, gl.FUNC_ADD, BlendMode.ADD), _defineProperty(_blendEquationMap, gl.MIN_EXT, BlendMode.MIN), _defineProperty(_blendEquationMap, gl.MAX_EXT, BlendMode.MAX), _defineProperty(_blendEquationMap, gl.FUNC_SUBTRACT, BlendMode.SUBSTRACT), _defineProperty(_blendEquationMap, gl.FUNC_REVERSE_SUBTRACT, BlendMode.REVERSE_SUBSTRACT), _blendEquationMap);
|
|
13
|
+
export var blendFuncMap = (_blendFuncMap = {}, _defineProperty(_blendFuncMap, gl.ZERO, BlendFactor.ZERO), _defineProperty(_blendFuncMap, gl.ONE, BlendFactor.ONE), _defineProperty(_blendFuncMap, gl.SRC_COLOR, BlendFactor.SRC), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_COLOR, BlendFactor.ONE_MINUS_SRC), _defineProperty(_blendFuncMap, gl.SRC_ALPHA, BlendFactor.SRC_ALPHA), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_ALPHA, BlendFactor.ONE_MINUS_SRC_ALPHA), _defineProperty(_blendFuncMap, gl.DST_COLOR, BlendFactor.DST), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_COLOR, BlendFactor.ONE_MINUS_DST), _defineProperty(_blendFuncMap, gl.DST_ALPHA, BlendFactor.DST_ALPHA), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_ALPHA, BlendFactor.ONE_MINUS_DST_ALPHA), _defineProperty(_blendFuncMap, gl.CONSTANT_COLOR, BlendFactor.CONST), _defineProperty(_blendFuncMap, gl.ONE_MINUS_CONSTANT_COLOR, BlendFactor.ONE_MINUS_CONSTANT), _defineProperty(_blendFuncMap, gl.CONSTANT_ALPHA, BlendFactor.CONST), _defineProperty(_blendFuncMap, gl.ONE_MINUS_CONSTANT_ALPHA, BlendFactor.ONE_MINUS_CONSTANT), _defineProperty(_blendFuncMap, gl.SRC_ALPHA_SATURATE, BlendFactor.SRC_ALPHA_SATURATE), _blendFuncMap);
|
|
14
|
+
|
|
15
|
+
// export const filterMap: {
|
|
16
|
+
// [key: string]: FilterMode;
|
|
17
|
+
// } = {
|
|
18
|
+
// [gl.NEAREST]: 'nearest',
|
|
19
|
+
// [gl.LINEAR]: 'linear',
|
|
20
|
+
// [gl.LINEAR_MIPMAP_LINEAR]: 'mipmap',
|
|
21
|
+
// [gl.NEAREST_MIPMAP_LINEAR]: 'nearest mipmap linear',
|
|
22
|
+
// [gl.LINEAR_MIPMAP_NEAREST]: 'linear mipmap nearest',
|
|
23
|
+
// [gl.NEAREST_MIPMAP_NEAREST]: 'nearest mipmap nearest',
|
|
24
|
+
// };
|
|
25
|
+
|
|
26
|
+
// export const mipmapMap: {
|
|
27
|
+
// [key: string]: MipmapFilterMode;
|
|
28
|
+
// } = {
|
|
29
|
+
// [gl.DONT_CARE]: MipmapFilterMode,
|
|
30
|
+
// [gl.NICEST]: 'nice',
|
|
31
|
+
// [gl.FASTEST]: 'fast',
|
|
32
|
+
// };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import 'reflect-metadata';
|
|
3
|
+
import DeviceFramebuffer from './DeviceFramebuffer';
|
|
4
|
+
/**
|
|
5
|
+
* Device API renderer
|
|
6
|
+
*/
|
|
7
|
+
export default class DeviceRendererService implements IRendererService {
|
|
8
|
+
uniformBuffers: IBuffer[];
|
|
9
|
+
extensionObject: IExtensions;
|
|
10
|
+
private device;
|
|
11
|
+
private swapChain;
|
|
12
|
+
private $container;
|
|
13
|
+
private canvas;
|
|
14
|
+
private width;
|
|
15
|
+
private height;
|
|
16
|
+
private isDirty;
|
|
17
|
+
private renderPass;
|
|
18
|
+
private renderTarget;
|
|
19
|
+
private mainDepthRT;
|
|
20
|
+
init(canvas: HTMLCanvasElement, cfg: IRenderConfig): Promise<void>;
|
|
21
|
+
beginFrame(): void;
|
|
22
|
+
endFrame(): void;
|
|
23
|
+
getPointSizeRange(): any;
|
|
24
|
+
testExtension(name: string): boolean;
|
|
25
|
+
createModel: (options: IModelInitializationOptions) => IModel;
|
|
26
|
+
createAttribute: (options: IAttributeInitializationOptions) => IAttribute;
|
|
27
|
+
createBuffer: (options: IBufferInitializationOptions) => IBuffer;
|
|
28
|
+
createElements: (options: IElementsInitializationOptions) => IElements;
|
|
29
|
+
createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
|
|
30
|
+
createFramebuffer: (options: IFramebufferInitializationOptions) => DeviceFramebuffer;
|
|
31
|
+
useFramebuffer: () => void;
|
|
32
|
+
clear: () => void;
|
|
33
|
+
viewport: ({ width, height, }: {
|
|
34
|
+
x: number;
|
|
35
|
+
y: number;
|
|
36
|
+
width: number;
|
|
37
|
+
height: number;
|
|
38
|
+
}) => void;
|
|
39
|
+
readPixels: () => Uint8Array;
|
|
40
|
+
getViewportSize: () => {
|
|
41
|
+
width: any;
|
|
42
|
+
height: any;
|
|
43
|
+
};
|
|
44
|
+
getContainer: () => HTMLElement | null;
|
|
45
|
+
getCanvas: () => HTMLCanvasElement;
|
|
46
|
+
getGLContext: () => WebGLRenderingContext;
|
|
47
|
+
setState(): void;
|
|
48
|
+
setBaseState(): void;
|
|
49
|
+
setCustomLayerDefaults(): void;
|
|
50
|
+
setDirty(flag: boolean): void;
|
|
51
|
+
getDirty(): boolean;
|
|
52
|
+
destroy: () => void;
|
|
53
|
+
}
|