@antv/l7-renderer 2.18.2 → 2.19.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/index.d.ts +5 -0
- package/es/index.js +5 -0
- package/es/regl/ReglAttribute.d.ts +16 -0
- package/es/regl/ReglAttribute.js +45 -0
- package/es/regl/ReglBuffer.d.ts +17 -0
- package/es/regl/ReglBuffer.js +48 -0
- package/es/regl/ReglElements.d.ts +14 -0
- package/es/regl/ReglElements.js +42 -0
- package/es/regl/ReglFramebuffer.d.ts +16 -0
- package/es/regl/ReglFramebuffer.js +51 -0
- package/es/regl/ReglModel.d.ts +46 -0
- package/es/regl/ReglModel.js +350 -0
- package/es/regl/ReglRenderbuffer.d.ts +16 -0
- package/es/regl/ReglRenderbuffer.js +41 -0
- package/es/regl/ReglTexture2D.d.ts +22 -0
- package/es/regl/ReglTexture2D.js +125 -0
- package/es/regl/constants.d.ts +43 -0
- package/es/regl/constants.js +21 -0
- package/es/regl/index.d.ts +51 -0
- package/es/regl/index.js +271 -0
- package/lib/index.js +39 -0
- package/lib/regl/ReglAttribute.js +49 -0
- package/lib/regl/ReglBuffer.js +53 -0
- package/lib/regl/ReglElements.js +47 -0
- package/lib/regl/ReglFramebuffer.js +51 -0
- package/lib/regl/ReglModel.js +305 -0
- package/lib/regl/ReglRenderbuffer.js +44 -0
- package/lib/regl/ReglTexture2D.js +107 -0
- package/lib/regl/constants.js +170 -0
- package/lib/regl/index.js +232 -0
- package/package.json +5 -5
package/es/index.d.ts
ADDED
package/es/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IAttribute, IAttributeInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#attributes
|
|
5
|
+
*/
|
|
6
|
+
export default class ReglAttribute implements IAttribute {
|
|
7
|
+
private attribute;
|
|
8
|
+
private buffer;
|
|
9
|
+
constructor(gl: regl.Regl, options: IAttributeInitializationOptions);
|
|
10
|
+
get(): regl.Attribute;
|
|
11
|
+
updateBuffer(options: {
|
|
12
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
13
|
+
offset: number;
|
|
14
|
+
}): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
/**
|
|
4
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#attributes
|
|
5
|
+
*/
|
|
6
|
+
var ReglAttribute = /*#__PURE__*/function () {
|
|
7
|
+
function ReglAttribute(gl, options) {
|
|
8
|
+
_classCallCheck(this, ReglAttribute);
|
|
9
|
+
var buffer = options.buffer,
|
|
10
|
+
offset = options.offset,
|
|
11
|
+
stride = options.stride,
|
|
12
|
+
normalized = options.normalized,
|
|
13
|
+
size = options.size,
|
|
14
|
+
divisor = options.divisor;
|
|
15
|
+
this.buffer = buffer;
|
|
16
|
+
this.attribute = {
|
|
17
|
+
buffer: buffer.get(),
|
|
18
|
+
offset: offset || 0,
|
|
19
|
+
stride: stride || 0,
|
|
20
|
+
normalized: normalized || false,
|
|
21
|
+
divisor: divisor || 0
|
|
22
|
+
};
|
|
23
|
+
if (size) {
|
|
24
|
+
this.attribute.size = size;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
_createClass(ReglAttribute, [{
|
|
28
|
+
key: "get",
|
|
29
|
+
value: function get() {
|
|
30
|
+
return this.attribute;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "updateBuffer",
|
|
34
|
+
value: function updateBuffer(options) {
|
|
35
|
+
this.buffer.subData(options);
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "destroy",
|
|
39
|
+
value: function destroy() {
|
|
40
|
+
this.buffer.destroy();
|
|
41
|
+
}
|
|
42
|
+
}]);
|
|
43
|
+
return ReglAttribute;
|
|
44
|
+
}();
|
|
45
|
+
export { ReglAttribute as default };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* adaptor for regl.Buffer
|
|
5
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#buffers
|
|
6
|
+
*/
|
|
7
|
+
export default class ReglBuffer implements IBuffer {
|
|
8
|
+
private buffer;
|
|
9
|
+
private isDestroyed;
|
|
10
|
+
constructor(reGl: regl.Regl, options: IBufferInitializationOptions);
|
|
11
|
+
get(): regl.Buffer;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
subData({ data, offset, }: {
|
|
14
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
15
|
+
offset: number;
|
|
16
|
+
}): void;
|
|
17
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 { gl } from '@antv/l7-core';
|
|
5
|
+
import { dataTypeMap, usageMap } from "./constants";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* adaptor for regl.Buffer
|
|
9
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#buffers
|
|
10
|
+
*/
|
|
11
|
+
var ReglBuffer = /*#__PURE__*/function () {
|
|
12
|
+
function ReglBuffer(reGl, options) {
|
|
13
|
+
_classCallCheck(this, ReglBuffer);
|
|
14
|
+
_defineProperty(this, "isDestroyed", false);
|
|
15
|
+
var data = options.data,
|
|
16
|
+
usage = options.usage,
|
|
17
|
+
type = options.type;
|
|
18
|
+
this.buffer = reGl.buffer({
|
|
19
|
+
data: data,
|
|
20
|
+
usage: usageMap[usage || gl.STATIC_DRAW],
|
|
21
|
+
type: dataTypeMap[type || gl.UNSIGNED_BYTE]
|
|
22
|
+
// length: 0,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
_createClass(ReglBuffer, [{
|
|
26
|
+
key: "get",
|
|
27
|
+
value: function get() {
|
|
28
|
+
return this.buffer;
|
|
29
|
+
}
|
|
30
|
+
}, {
|
|
31
|
+
key: "destroy",
|
|
32
|
+
value: function destroy() {
|
|
33
|
+
if (!this.isDestroyed) {
|
|
34
|
+
this.buffer.destroy();
|
|
35
|
+
}
|
|
36
|
+
this.isDestroyed = true;
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
key: "subData",
|
|
40
|
+
value: function subData(_ref) {
|
|
41
|
+
var data = _ref.data,
|
|
42
|
+
offset = _ref.offset;
|
|
43
|
+
this.buffer.subdata(data, offset);
|
|
44
|
+
}
|
|
45
|
+
}]);
|
|
46
|
+
return ReglBuffer;
|
|
47
|
+
}();
|
|
48
|
+
export { ReglBuffer as default };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IElements, IElementsInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#elements
|
|
5
|
+
*/
|
|
6
|
+
export default class ReglElements implements IElements {
|
|
7
|
+
private elements;
|
|
8
|
+
constructor(reGl: regl.Regl, options: IElementsInitializationOptions);
|
|
9
|
+
get(): regl.Elements;
|
|
10
|
+
subData({ data, }: {
|
|
11
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
12
|
+
}): void;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import { gl } from '@antv/l7-core';
|
|
4
|
+
import { dataTypeMap, usageMap } from "./constants";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#elements
|
|
8
|
+
*/
|
|
9
|
+
var ReglElements = /*#__PURE__*/function () {
|
|
10
|
+
function ReglElements(reGl, options) {
|
|
11
|
+
_classCallCheck(this, ReglElements);
|
|
12
|
+
var data = options.data,
|
|
13
|
+
usage = options.usage,
|
|
14
|
+
type = options.type,
|
|
15
|
+
count = options.count;
|
|
16
|
+
this.elements = reGl.elements({
|
|
17
|
+
data: data,
|
|
18
|
+
usage: usageMap[usage || gl.STATIC_DRAW],
|
|
19
|
+
type: dataTypeMap[type || gl.UNSIGNED_BYTE],
|
|
20
|
+
count: count
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
_createClass(ReglElements, [{
|
|
24
|
+
key: "get",
|
|
25
|
+
value: function get() {
|
|
26
|
+
return this.elements;
|
|
27
|
+
}
|
|
28
|
+
}, {
|
|
29
|
+
key: "subData",
|
|
30
|
+
value: function subData(_ref) {
|
|
31
|
+
var data = _ref.data;
|
|
32
|
+
this.elements.subdata(data);
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
key: "destroy",
|
|
36
|
+
value: function destroy() {
|
|
37
|
+
// this.elements.destroy();
|
|
38
|
+
}
|
|
39
|
+
}]);
|
|
40
|
+
return ReglElements;
|
|
41
|
+
}();
|
|
42
|
+
export { ReglElements as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* adaptor for regl.Framebuffer
|
|
5
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#framebuffers
|
|
6
|
+
*/
|
|
7
|
+
export default class ReglFramebuffer implements IFramebuffer {
|
|
8
|
+
private framebuffer;
|
|
9
|
+
constructor(reGl: regl.Regl, options: IFramebufferInitializationOptions);
|
|
10
|
+
get(): regl.Framebuffer;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
resize({ width, height }: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}): void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
/**
|
|
4
|
+
* adaptor for regl.Framebuffer
|
|
5
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#framebuffers
|
|
6
|
+
*/
|
|
7
|
+
var ReglFramebuffer = /*#__PURE__*/function () {
|
|
8
|
+
function ReglFramebuffer(reGl, options) {
|
|
9
|
+
_classCallCheck(this, ReglFramebuffer);
|
|
10
|
+
var width = options.width,
|
|
11
|
+
height = options.height,
|
|
12
|
+
color = options.color,
|
|
13
|
+
colors = options.colors;
|
|
14
|
+
var framebufferOptions = {
|
|
15
|
+
width: width,
|
|
16
|
+
height: height
|
|
17
|
+
};
|
|
18
|
+
if (Array.isArray(colors)) {
|
|
19
|
+
framebufferOptions.colors = colors.map(function (c) {
|
|
20
|
+
return c.get();
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (color && typeof color !== 'boolean') {
|
|
24
|
+
framebufferOptions.color = color.get();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// TODO: depth & stencil
|
|
28
|
+
|
|
29
|
+
this.framebuffer = reGl.framebuffer(framebufferOptions);
|
|
30
|
+
}
|
|
31
|
+
_createClass(ReglFramebuffer, [{
|
|
32
|
+
key: "get",
|
|
33
|
+
value: function get() {
|
|
34
|
+
return this.framebuffer;
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "destroy",
|
|
38
|
+
value: function destroy() {
|
|
39
|
+
this.framebuffer.destroy();
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "resize",
|
|
43
|
+
value: function resize(_ref) {
|
|
44
|
+
var width = _ref.width,
|
|
45
|
+
height = _ref.height;
|
|
46
|
+
this.framebuffer.resize(width, height);
|
|
47
|
+
}
|
|
48
|
+
}]);
|
|
49
|
+
return ReglFramebuffer;
|
|
50
|
+
}();
|
|
51
|
+
export { ReglFramebuffer as default };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { IAttribute, IElements, IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* adaptor for regl.DrawCommand
|
|
5
|
+
*/
|
|
6
|
+
export default class ReglModel implements IModel {
|
|
7
|
+
private reGl;
|
|
8
|
+
private destroyed;
|
|
9
|
+
private drawCommand;
|
|
10
|
+
private drawParams;
|
|
11
|
+
private options;
|
|
12
|
+
private uniforms;
|
|
13
|
+
constructor(reGl: regl.Regl, options: IModelInitializationOptions);
|
|
14
|
+
updateAttributesAndElements(attributes: {
|
|
15
|
+
[key: string]: IAttribute;
|
|
16
|
+
}, elements: IElements): void;
|
|
17
|
+
updateAttributes(attributes: {
|
|
18
|
+
[key: string]: IAttribute;
|
|
19
|
+
}): void;
|
|
20
|
+
addUniforms(uniforms: {
|
|
21
|
+
[key: string]: IUniform;
|
|
22
|
+
}): void;
|
|
23
|
+
draw(options: IModelDrawOptions, pick?: boolean): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
/**
|
|
26
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
|
|
27
|
+
*/
|
|
28
|
+
private initDepthDrawParams;
|
|
29
|
+
private getBlendDrawParams;
|
|
30
|
+
/**
|
|
31
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
|
|
32
|
+
*/
|
|
33
|
+
private getStencilDrawParams;
|
|
34
|
+
private getColorMaskDrawParams;
|
|
35
|
+
/**
|
|
36
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
|
|
37
|
+
*/
|
|
38
|
+
private initCullDrawParams;
|
|
39
|
+
/**
|
|
40
|
+
* 考虑结构体命名, eg:
|
|
41
|
+
* a: { b: 1 } -> 'a.b'
|
|
42
|
+
* a: [ { b: 1 } ] -> 'a[0].b'
|
|
43
|
+
*/
|
|
44
|
+
private extractUniforms;
|
|
45
|
+
private extractUniformsRecursively;
|
|
46
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
import { gl } from '@antv/l7-core';
|
|
7
|
+
import { lodashUtil } from '@antv/l7-utils';
|
|
8
|
+
import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, stencilFuncMap, stencilOpMap } from "./constants";
|
|
9
|
+
var isPlainObject = lodashUtil.isPlainObject,
|
|
10
|
+
isTypedArray = lodashUtil.isTypedArray;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* adaptor for regl.DrawCommand
|
|
14
|
+
*/
|
|
15
|
+
var ReglModel = /*#__PURE__*/function () {
|
|
16
|
+
function ReglModel(reGl, options) {
|
|
17
|
+
_classCallCheck(this, ReglModel);
|
|
18
|
+
_defineProperty(this, "destroyed", false);
|
|
19
|
+
_defineProperty(this, "uniforms", {});
|
|
20
|
+
this.reGl = reGl;
|
|
21
|
+
var vs = options.vs,
|
|
22
|
+
fs = options.fs,
|
|
23
|
+
attributes = options.attributes,
|
|
24
|
+
uniforms = options.uniforms,
|
|
25
|
+
primitive = options.primitive,
|
|
26
|
+
count = options.count,
|
|
27
|
+
elements = options.elements,
|
|
28
|
+
depth = options.depth,
|
|
29
|
+
cull = options.cull,
|
|
30
|
+
instances = options.instances;
|
|
31
|
+
var reglUniforms = {};
|
|
32
|
+
this.options = options;
|
|
33
|
+
if (uniforms) {
|
|
34
|
+
this.uniforms = this.extractUniforms(uniforms);
|
|
35
|
+
Object.keys(uniforms).forEach(function (uniformName) {
|
|
36
|
+
// use regl prop API
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
reglUniforms[uniformName] = reGl.prop(uniformName);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
var reglAttributes = {};
|
|
42
|
+
Object.keys(attributes).forEach(function (name) {
|
|
43
|
+
reglAttributes[name] = attributes[name].get();
|
|
44
|
+
});
|
|
45
|
+
var drawParams = {
|
|
46
|
+
attributes: reglAttributes,
|
|
47
|
+
frag: fs,
|
|
48
|
+
uniforms: reglUniforms,
|
|
49
|
+
vert: vs,
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
colorMask: reGl.prop('colorMask'),
|
|
52
|
+
lineWidth: 1,
|
|
53
|
+
blend: {
|
|
54
|
+
// @ts-ignore
|
|
55
|
+
enable: reGl.prop('blend.enable'),
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
func: reGl.prop('blend.func'),
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
equation: reGl.prop('blend.equation'),
|
|
60
|
+
// @ts-ignore
|
|
61
|
+
color: reGl.prop('blend.color')
|
|
62
|
+
},
|
|
63
|
+
stencil: {
|
|
64
|
+
// @ts-ignore
|
|
65
|
+
enable: reGl.prop('stencil.enable'),
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
mask: reGl.prop('stencil.mask'),
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
func: reGl.prop('stencil.func'),
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
opFront: reGl.prop('stencil.opFront'),
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
opBack: reGl.prop('stencil.opBack')
|
|
74
|
+
},
|
|
75
|
+
primitive: primitiveMap[primitive === undefined ? gl.TRIANGLES : primitive]
|
|
76
|
+
};
|
|
77
|
+
if (instances) {
|
|
78
|
+
drawParams.instances = instances;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Tip:
|
|
82
|
+
// elements 中可能包含 count,此时不应传入
|
|
83
|
+
// count 和 elements 相比、count 优先
|
|
84
|
+
if (count) {
|
|
85
|
+
drawParams.count = count;
|
|
86
|
+
} else if (elements) {
|
|
87
|
+
drawParams.elements = elements.get();
|
|
88
|
+
}
|
|
89
|
+
this.initDepthDrawParams({
|
|
90
|
+
depth: depth
|
|
91
|
+
}, drawParams);
|
|
92
|
+
// this.initBlendDrawParams({ blend }, drawParams);
|
|
93
|
+
// this.initStencilDrawParams({ stencil }, drawParams);
|
|
94
|
+
this.initCullDrawParams({
|
|
95
|
+
cull: cull
|
|
96
|
+
}, drawParams);
|
|
97
|
+
this.drawCommand = reGl(drawParams);
|
|
98
|
+
this.drawParams = drawParams;
|
|
99
|
+
}
|
|
100
|
+
_createClass(ReglModel, [{
|
|
101
|
+
key: "updateAttributesAndElements",
|
|
102
|
+
value: function updateAttributesAndElements(attributes, elements) {
|
|
103
|
+
var reglAttributes = {};
|
|
104
|
+
Object.keys(attributes).forEach(function (name) {
|
|
105
|
+
reglAttributes[name] = attributes[name].get();
|
|
106
|
+
});
|
|
107
|
+
this.drawParams.attributes = reglAttributes;
|
|
108
|
+
this.drawParams.elements = elements.get();
|
|
109
|
+
this.drawCommand = this.reGl(this.drawParams);
|
|
110
|
+
}
|
|
111
|
+
}, {
|
|
112
|
+
key: "updateAttributes",
|
|
113
|
+
value: function updateAttributes(attributes) {
|
|
114
|
+
var reglAttributes = {};
|
|
115
|
+
Object.keys(attributes).forEach(function (name) {
|
|
116
|
+
reglAttributes[name] = attributes[name].get();
|
|
117
|
+
});
|
|
118
|
+
this.drawParams.attributes = reglAttributes;
|
|
119
|
+
this.drawCommand = this.reGl(this.drawParams);
|
|
120
|
+
}
|
|
121
|
+
}, {
|
|
122
|
+
key: "addUniforms",
|
|
123
|
+
value: function addUniforms(uniforms) {
|
|
124
|
+
this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
key: "draw",
|
|
128
|
+
value: function draw(options, pick) {
|
|
129
|
+
if (this.drawParams.attributes && Object.keys(this.drawParams.attributes).length === 0) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
var uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(options.uniforms || {}));
|
|
133
|
+
var reglDrawProps = {};
|
|
134
|
+
Object.keys(uniforms).forEach(function (uniformName) {
|
|
135
|
+
var type = _typeof(uniforms[uniformName]);
|
|
136
|
+
if (type === 'boolean' || type === 'number' || Array.isArray(uniforms[uniformName]) ||
|
|
137
|
+
// @ts-ignore
|
|
138
|
+
uniforms[uniformName].BYTES_PER_ELEMENT) {
|
|
139
|
+
reglDrawProps[uniformName] = uniforms[uniformName];
|
|
140
|
+
} else {
|
|
141
|
+
reglDrawProps[uniformName] = uniforms[uniformName].get();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
// 更新 blend
|
|
145
|
+
// @ts-ignore
|
|
146
|
+
reglDrawProps.blend = pick // picking 操作不应该使用 blend
|
|
147
|
+
? this.getBlendDrawParams({
|
|
148
|
+
blend: {
|
|
149
|
+
enable: false
|
|
150
|
+
}
|
|
151
|
+
}) : this.getBlendDrawParams(options);
|
|
152
|
+
|
|
153
|
+
// 更新stentil 配置
|
|
154
|
+
// @ts-ignore
|
|
155
|
+
reglDrawProps.stencil = this.getStencilDrawParams(options);
|
|
156
|
+
// @ts-ignore
|
|
157
|
+
reglDrawProps.colorMask = this.getColorMaskDrawParams(options, pick);
|
|
158
|
+
|
|
159
|
+
// 在进行拾取操作的绘制中,不应该使用叠加模式 - picking 根据拾取的颜色作为判断的输入,而叠加模式会产生新的,在 id 序列中不存在的颜色
|
|
160
|
+
this.drawCommand(reglDrawProps);
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "destroy",
|
|
164
|
+
value: function destroy() {
|
|
165
|
+
var _this$drawParams, _this$drawParams$elem;
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
(_this$drawParams = this.drawParams) === null || _this$drawParams === void 0 ? void 0 : (_this$drawParams$elem = _this$drawParams.elements) === null || _this$drawParams$elem === void 0 ? void 0 : _this$drawParams$elem.destroy();
|
|
168
|
+
if (this.options.attributes) {
|
|
169
|
+
Object.values(this.options.attributes).forEach(function (attr) {
|
|
170
|
+
// @ts-ignore
|
|
171
|
+
attr === null || attr === void 0 ? void 0 : attr.destroy();
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
this.destroyed = true;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#depth-buffer
|
|
179
|
+
*/
|
|
180
|
+
}, {
|
|
181
|
+
key: "initDepthDrawParams",
|
|
182
|
+
value: function initDepthDrawParams(_ref, drawParams) {
|
|
183
|
+
var depth = _ref.depth;
|
|
184
|
+
if (depth) {
|
|
185
|
+
drawParams.depth = {
|
|
186
|
+
enable: depth.enable === undefined ? true : !!depth.enable,
|
|
187
|
+
mask: depth.mask === undefined ? true : !!depth.mask,
|
|
188
|
+
func: depthFuncMap[depth.func || gl.LESS],
|
|
189
|
+
range: depth.range || [0, 1]
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}, {
|
|
194
|
+
key: "getBlendDrawParams",
|
|
195
|
+
value: function getBlendDrawParams(_ref2) {
|
|
196
|
+
var blend = _ref2.blend;
|
|
197
|
+
var _ref3 = blend || {},
|
|
198
|
+
enable = _ref3.enable,
|
|
199
|
+
func = _ref3.func,
|
|
200
|
+
equation = _ref3.equation,
|
|
201
|
+
_ref3$color = _ref3.color,
|
|
202
|
+
color = _ref3$color === void 0 ? [0, 0, 0, 0] : _ref3$color;
|
|
203
|
+
// @ts-ignore
|
|
204
|
+
return {
|
|
205
|
+
enable: !!enable,
|
|
206
|
+
func: {
|
|
207
|
+
srcRGB: blendFuncMap[func && func.srcRGB || gl.SRC_ALPHA],
|
|
208
|
+
srcAlpha: blendFuncMap[func && func.srcAlpha || gl.SRC_ALPHA],
|
|
209
|
+
dstRGB: blendFuncMap[func && func.dstRGB || gl.ONE_MINUS_SRC_ALPHA],
|
|
210
|
+
dstAlpha: blendFuncMap[func && func.dstAlpha || gl.ONE_MINUS_SRC_ALPHA]
|
|
211
|
+
},
|
|
212
|
+
equation: {
|
|
213
|
+
rgb: blendEquationMap[equation && equation.rgb || gl.FUNC_ADD],
|
|
214
|
+
alpha: blendEquationMap[equation && equation.alpha || gl.FUNC_ADD]
|
|
215
|
+
},
|
|
216
|
+
color: color
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#stencil
|
|
221
|
+
*/
|
|
222
|
+
}, {
|
|
223
|
+
key: "getStencilDrawParams",
|
|
224
|
+
value: function getStencilDrawParams(_ref4) {
|
|
225
|
+
var stencil = _ref4.stencil;
|
|
226
|
+
var _ref5 = stencil || {},
|
|
227
|
+
enable = _ref5.enable,
|
|
228
|
+
_ref5$mask = _ref5.mask,
|
|
229
|
+
mask = _ref5$mask === void 0 ? -1 : _ref5$mask,
|
|
230
|
+
_ref5$func = _ref5.func,
|
|
231
|
+
func = _ref5$func === void 0 ? {
|
|
232
|
+
cmp: gl.ALWAYS,
|
|
233
|
+
ref: 0,
|
|
234
|
+
mask: -1
|
|
235
|
+
} : _ref5$func,
|
|
236
|
+
_ref5$opFront = _ref5.opFront,
|
|
237
|
+
opFront = _ref5$opFront === void 0 ? {
|
|
238
|
+
fail: gl.KEEP,
|
|
239
|
+
zfail: gl.KEEP,
|
|
240
|
+
zpass: gl.KEEP
|
|
241
|
+
} : _ref5$opFront,
|
|
242
|
+
_ref5$opBack = _ref5.opBack,
|
|
243
|
+
opBack = _ref5$opBack === void 0 ? {
|
|
244
|
+
fail: gl.KEEP,
|
|
245
|
+
zfail: gl.KEEP,
|
|
246
|
+
zpass: gl.KEEP
|
|
247
|
+
} : _ref5$opBack;
|
|
248
|
+
return {
|
|
249
|
+
enable: !!enable,
|
|
250
|
+
mask: mask,
|
|
251
|
+
func: _objectSpread(_objectSpread({}, func), {}, {
|
|
252
|
+
cmp: stencilFuncMap[func.cmp]
|
|
253
|
+
}),
|
|
254
|
+
opFront: {
|
|
255
|
+
fail: stencilOpMap[opFront.fail],
|
|
256
|
+
zfail: stencilOpMap[opFront.zfail],
|
|
257
|
+
zpass: stencilOpMap[opFront.zpass]
|
|
258
|
+
},
|
|
259
|
+
opBack: {
|
|
260
|
+
fail: stencilOpMap[opBack.fail],
|
|
261
|
+
zfail: stencilOpMap[opBack.zfail],
|
|
262
|
+
zpass: stencilOpMap[opBack.zpass]
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
}, {
|
|
267
|
+
key: "getColorMaskDrawParams",
|
|
268
|
+
value: function getColorMaskDrawParams(_ref6, pick) {
|
|
269
|
+
var stencil = _ref6.stencil;
|
|
270
|
+
// TODO: 重构相关参数
|
|
271
|
+
// 掩膜模式下,颜色通道全部关闭
|
|
272
|
+
var colorMask = stencil !== null && stencil !== void 0 && stencil.enable && stencil.opFront && !pick ? [false, false, false, false] : [true, true, true, true]; // 非掩码模式下,颜色通道全部开启
|
|
273
|
+
return colorMask;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
|
|
278
|
+
*/
|
|
279
|
+
}, {
|
|
280
|
+
key: "initCullDrawParams",
|
|
281
|
+
value: function initCullDrawParams(_ref7, drawParams) {
|
|
282
|
+
var cull = _ref7.cull;
|
|
283
|
+
if (cull) {
|
|
284
|
+
var enable = cull.enable,
|
|
285
|
+
_cull$face = cull.face,
|
|
286
|
+
face = _cull$face === void 0 ? gl.BACK : _cull$face;
|
|
287
|
+
drawParams.cull = {
|
|
288
|
+
enable: !!enable,
|
|
289
|
+
face: cullFaceMap[face]
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* 考虑结构体命名, eg:
|
|
296
|
+
* a: { b: 1 } -> 'a.b'
|
|
297
|
+
* a: [ { b: 1 } ] -> 'a[0].b'
|
|
298
|
+
*/
|
|
299
|
+
}, {
|
|
300
|
+
key: "extractUniforms",
|
|
301
|
+
value: function extractUniforms(uniforms) {
|
|
302
|
+
var _this = this;
|
|
303
|
+
var extractedUniforms = {};
|
|
304
|
+
Object.keys(uniforms).forEach(function (uniformName) {
|
|
305
|
+
_this.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, '');
|
|
306
|
+
});
|
|
307
|
+
return extractedUniforms;
|
|
308
|
+
}
|
|
309
|
+
}, {
|
|
310
|
+
key: "extractUniformsRecursively",
|
|
311
|
+
value: function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
|
|
312
|
+
var _this2 = this;
|
|
313
|
+
if (uniformValue === null || typeof uniformValue === 'number' ||
|
|
314
|
+
// u_A: 1
|
|
315
|
+
typeof uniformValue === 'boolean' ||
|
|
316
|
+
// u_A: false
|
|
317
|
+
Array.isArray(uniformValue) && typeof uniformValue[0] === 'number' ||
|
|
318
|
+
// u_A: [1, 2, 3]
|
|
319
|
+
isTypedArray(uniformValue) ||
|
|
320
|
+
// u_A: Float32Array
|
|
321
|
+
// @ts-ignore
|
|
322
|
+
uniformValue === '' || 'resize' in uniformValue) {
|
|
323
|
+
uniforms["".concat(prefix && prefix + '.').concat(uniformName)] = uniformValue;
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// u_Struct.a.b.c
|
|
328
|
+
if (isPlainObject(uniformValue)) {
|
|
329
|
+
Object.keys(uniformValue).forEach(function (childName) {
|
|
330
|
+
_this2.extractUniformsRecursively(childName,
|
|
331
|
+
// @ts-ignore
|
|
332
|
+
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// u_Struct[0].a
|
|
337
|
+
if (Array.isArray(uniformValue)) {
|
|
338
|
+
uniformValue.forEach(function (child, idx) {
|
|
339
|
+
Object.keys(child).forEach(function (childName) {
|
|
340
|
+
_this2.extractUniformsRecursively(childName,
|
|
341
|
+
// @ts-ignore
|
|
342
|
+
child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
}]);
|
|
348
|
+
return ReglModel;
|
|
349
|
+
}();
|
|
350
|
+
export { ReglModel as default };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { IRenderbuffer, IRenderbufferInitializationOptions } from '@antv/l7-core';
|
|
2
|
+
import regl from 'regl';
|
|
3
|
+
/**
|
|
4
|
+
* adaptor for regl.Renderbuffer
|
|
5
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#renderbuffers
|
|
6
|
+
*/
|
|
7
|
+
export default class ReglRenderbuffer implements IRenderbuffer {
|
|
8
|
+
private renderbuffer;
|
|
9
|
+
constructor(reGl: regl.Regl, options: IRenderbufferInitializationOptions);
|
|
10
|
+
get(): regl.Renderbuffer;
|
|
11
|
+
destroy(): void;
|
|
12
|
+
resize({ width, height }: {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}): void;
|
|
16
|
+
}
|