@antv/l7-renderer 2.18.2 → 2.18.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/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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import { formatMap } from "./constants";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* adaptor for regl.Renderbuffer
|
|
7
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#renderbuffers
|
|
8
|
+
*/
|
|
9
|
+
var ReglRenderbuffer = /*#__PURE__*/function () {
|
|
10
|
+
function ReglRenderbuffer(reGl, options) {
|
|
11
|
+
_classCallCheck(this, ReglRenderbuffer);
|
|
12
|
+
var width = options.width,
|
|
13
|
+
height = options.height,
|
|
14
|
+
format = options.format;
|
|
15
|
+
this.renderbuffer = reGl.renderbuffer({
|
|
16
|
+
width: width,
|
|
17
|
+
height: height,
|
|
18
|
+
format: formatMap[format]
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
_createClass(ReglRenderbuffer, [{
|
|
22
|
+
key: "get",
|
|
23
|
+
value: function get() {
|
|
24
|
+
return this.renderbuffer;
|
|
25
|
+
}
|
|
26
|
+
}, {
|
|
27
|
+
key: "destroy",
|
|
28
|
+
value: function destroy() {
|
|
29
|
+
this.renderbuffer.destroy();
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "resize",
|
|
33
|
+
value: function resize(_ref) {
|
|
34
|
+
var width = _ref.width,
|
|
35
|
+
height = _ref.height;
|
|
36
|
+
this.renderbuffer.resize(width, height);
|
|
37
|
+
}
|
|
38
|
+
}]);
|
|
39
|
+
return ReglRenderbuffer;
|
|
40
|
+
}();
|
|
41
|
+
export { ReglRenderbuffer as default };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ITexture2D, ITexture2DInitializationOptions } 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 ReglTexture2D implements ITexture2D {
|
|
8
|
+
private texture;
|
|
9
|
+
private width;
|
|
10
|
+
private height;
|
|
11
|
+
private isDestroy;
|
|
12
|
+
constructor(reGl: regl.Regl, options: ITexture2DInitializationOptions);
|
|
13
|
+
get(): regl.Texture2D;
|
|
14
|
+
update(props?: regl.Texture2DOptions): void;
|
|
15
|
+
bind(): void;
|
|
16
|
+
resize({ width, height }: {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}): void;
|
|
20
|
+
getSize(): [number, number];
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
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 { colorSpaceMap, dataTypeMap, filterMap, formatMap, mipmapMap, wrapModeMap } 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 ReglTexture2D = /*#__PURE__*/function () {
|
|
12
|
+
function ReglTexture2D(reGl, options) {
|
|
13
|
+
_classCallCheck(this, ReglTexture2D);
|
|
14
|
+
_defineProperty(this, "isDestroy", false);
|
|
15
|
+
var data = options.data,
|
|
16
|
+
_options$type = options.type,
|
|
17
|
+
type = _options$type === void 0 ? gl.UNSIGNED_BYTE : _options$type,
|
|
18
|
+
width = options.width,
|
|
19
|
+
height = options.height,
|
|
20
|
+
_options$flipY = options.flipY,
|
|
21
|
+
flipY = _options$flipY === void 0 ? false : _options$flipY,
|
|
22
|
+
_options$format = options.format,
|
|
23
|
+
format = _options$format === void 0 ? gl.RGBA : _options$format,
|
|
24
|
+
_options$mipmap = options.mipmap,
|
|
25
|
+
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
|
|
26
|
+
_options$wrapS = options.wrapS,
|
|
27
|
+
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
|
|
28
|
+
_options$wrapT = options.wrapT,
|
|
29
|
+
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
|
|
30
|
+
_options$aniso = options.aniso,
|
|
31
|
+
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
|
|
32
|
+
_options$alignment = options.alignment,
|
|
33
|
+
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
|
|
34
|
+
_options$premultiplyA = options.premultiplyAlpha,
|
|
35
|
+
premultiplyAlpha = _options$premultiplyA === void 0 ? false : _options$premultiplyA,
|
|
36
|
+
_options$mag = options.mag,
|
|
37
|
+
mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
|
|
38
|
+
_options$min = options.min,
|
|
39
|
+
min = _options$min === void 0 ? gl.NEAREST : _options$min,
|
|
40
|
+
_options$colorSpace = options.colorSpace,
|
|
41
|
+
colorSpace = _options$colorSpace === void 0 ? gl.BROWSER_DEFAULT_WEBGL : _options$colorSpace,
|
|
42
|
+
_options$x = options.x,
|
|
43
|
+
x = _options$x === void 0 ? 0 : _options$x,
|
|
44
|
+
_options$y = options.y,
|
|
45
|
+
y = _options$y === void 0 ? 0 : _options$y,
|
|
46
|
+
_options$copy = options.copy,
|
|
47
|
+
copy = _options$copy === void 0 ? false : _options$copy;
|
|
48
|
+
this.width = width;
|
|
49
|
+
this.height = height;
|
|
50
|
+
var textureOptions = {
|
|
51
|
+
width: width,
|
|
52
|
+
height: height,
|
|
53
|
+
// @ts-ignore
|
|
54
|
+
type: dataTypeMap[type],
|
|
55
|
+
format: formatMap[format],
|
|
56
|
+
wrapS: wrapModeMap[wrapS],
|
|
57
|
+
wrapT: wrapModeMap[wrapT],
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
mag: filterMap[mag],
|
|
60
|
+
min: filterMap[min],
|
|
61
|
+
alignment: alignment,
|
|
62
|
+
flipY: flipY,
|
|
63
|
+
colorSpace: colorSpaceMap[colorSpace],
|
|
64
|
+
premultiplyAlpha: premultiplyAlpha,
|
|
65
|
+
aniso: aniso,
|
|
66
|
+
// copy pixels from current bind framebuffer
|
|
67
|
+
x: x,
|
|
68
|
+
y: y,
|
|
69
|
+
copy: copy
|
|
70
|
+
};
|
|
71
|
+
if (data) {
|
|
72
|
+
// @ts-ignore
|
|
73
|
+
textureOptions.data = data;
|
|
74
|
+
}
|
|
75
|
+
if (typeof mipmap === 'number') {
|
|
76
|
+
textureOptions.mipmap = mipmapMap[mipmap];
|
|
77
|
+
} else if (typeof mipmap === 'boolean') {
|
|
78
|
+
textureOptions.mipmap = mipmap;
|
|
79
|
+
}
|
|
80
|
+
this.texture = reGl.texture(textureOptions);
|
|
81
|
+
}
|
|
82
|
+
_createClass(ReglTexture2D, [{
|
|
83
|
+
key: "get",
|
|
84
|
+
value: function get() {
|
|
85
|
+
return this.texture;
|
|
86
|
+
}
|
|
87
|
+
}, {
|
|
88
|
+
key: "update",
|
|
89
|
+
value: function update() {
|
|
90
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
91
|
+
this.texture(props);
|
|
92
|
+
}
|
|
93
|
+
}, {
|
|
94
|
+
key: "bind",
|
|
95
|
+
value: function bind() {
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
this.texture._texture.bind();
|
|
98
|
+
}
|
|
99
|
+
}, {
|
|
100
|
+
key: "resize",
|
|
101
|
+
value: function resize(_ref) {
|
|
102
|
+
var width = _ref.width,
|
|
103
|
+
height = _ref.height;
|
|
104
|
+
this.texture.resize(width, height);
|
|
105
|
+
this.width = width;
|
|
106
|
+
this.height = height;
|
|
107
|
+
}
|
|
108
|
+
}, {
|
|
109
|
+
key: "getSize",
|
|
110
|
+
value: function getSize() {
|
|
111
|
+
return [this.width, this.height];
|
|
112
|
+
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "destroy",
|
|
115
|
+
value: function destroy() {
|
|
116
|
+
if (!this.isDestroy) {
|
|
117
|
+
var _this$texture;
|
|
118
|
+
(_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
|
|
119
|
+
}
|
|
120
|
+
this.isDestroy = true;
|
|
121
|
+
}
|
|
122
|
+
}]);
|
|
123
|
+
return ReglTexture2D;
|
|
124
|
+
}();
|
|
125
|
+
export { ReglTexture2D as default };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import regl from 'regl';
|
|
2
|
+
export declare const primitiveMap: {
|
|
3
|
+
[key: string]: 'points' | 'lines' | 'line loop' | 'line strip' | 'triangles' | 'triangle strip' | 'triangle fan';
|
|
4
|
+
};
|
|
5
|
+
export declare const usageMap: {
|
|
6
|
+
[key: string]: 'static' | 'dynamic' | 'stream';
|
|
7
|
+
};
|
|
8
|
+
export declare const dataTypeMap: {
|
|
9
|
+
[key: string]: 'int8' | 'int16' | 'int32' | 'uint8' | 'uint16' | 'uint32' | 'float';
|
|
10
|
+
};
|
|
11
|
+
export declare const formatMap: {
|
|
12
|
+
[key: string]: 'alpha' | 'luminance' | 'luminance alpha' | 'rgb' | 'rgba' | 'rgba4' | 'rgb5 a1' | 'rgb565' | 'depth' | 'depth stencil';
|
|
13
|
+
};
|
|
14
|
+
export declare const mipmapMap: {
|
|
15
|
+
[key: string]: 'dont care' | 'nice' | 'fast';
|
|
16
|
+
};
|
|
17
|
+
export declare const filterMap: {
|
|
18
|
+
[key: string]: 'nearest' | 'linear' | 'mipmap' | 'nearest mipmap linear' | 'linear mipmap nearest' | 'nearest mipmap nearest';
|
|
19
|
+
};
|
|
20
|
+
export declare const wrapModeMap: {
|
|
21
|
+
[key: string]: 'repeat' | 'clamp' | 'mirror';
|
|
22
|
+
};
|
|
23
|
+
export declare const colorSpaceMap: {
|
|
24
|
+
[key: string]: 'none' | 'browser';
|
|
25
|
+
};
|
|
26
|
+
export declare const depthFuncMap: {
|
|
27
|
+
[key: string]: 'never' | 'always' | 'less' | 'lequal' | 'greater' | 'gequal' | 'equal' | 'notequal';
|
|
28
|
+
};
|
|
29
|
+
export declare const blendEquationMap: {
|
|
30
|
+
[key: string]: regl.BlendingEquation;
|
|
31
|
+
};
|
|
32
|
+
export declare const blendFuncMap: {
|
|
33
|
+
[key: string]: regl.BlendingFunction;
|
|
34
|
+
};
|
|
35
|
+
export declare const stencilFuncMap: {
|
|
36
|
+
[key: string]: regl.ComparisonOperatorType;
|
|
37
|
+
};
|
|
38
|
+
export declare const stencilOpMap: {
|
|
39
|
+
[key: string]: regl.StencilOperationType;
|
|
40
|
+
};
|
|
41
|
+
export declare const cullFaceMap: {
|
|
42
|
+
[key: string]: regl.FaceOrientationType;
|
|
43
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
var _primitiveMap, _usageMap, _dataTypeMap, _formatMap, _mipmapMap, _filterMap, _wrapModeMap, _colorSpaceMap, _depthFuncMap, _blendEquationMap, _blendFuncMap, _stencilFuncMap, _stencilOpMap, _cullFaceMap;
|
|
3
|
+
/**
|
|
4
|
+
* @desc 由于 regl 使用大量字符串而非 WebGL 常量,因此需要映射
|
|
5
|
+
*/
|
|
6
|
+
import { gl } from '@antv/l7-core';
|
|
7
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/lib/constants/primitives.json
|
|
8
|
+
export var primitiveMap = (_primitiveMap = {}, _defineProperty(_primitiveMap, gl.POINTS, 'points'), _defineProperty(_primitiveMap, gl.LINES, 'lines'), _defineProperty(_primitiveMap, gl.LINE_LOOP, 'line loop'), _defineProperty(_primitiveMap, gl.LINE_STRIP, 'line strip'), _defineProperty(_primitiveMap, gl.TRIANGLES, 'triangles'), _defineProperty(_primitiveMap, gl.TRIANGLE_FAN, 'triangle fan'), _defineProperty(_primitiveMap, gl.TRIANGLE_STRIP, 'triangle strip'), _primitiveMap);
|
|
9
|
+
export var usageMap = (_usageMap = {}, _defineProperty(_usageMap, gl.STATIC_DRAW, 'static'), _defineProperty(_usageMap, gl.DYNAMIC_DRAW, 'dynamic'), _defineProperty(_usageMap, gl.STREAM_DRAW, 'stream'), _usageMap);
|
|
10
|
+
export var dataTypeMap = (_dataTypeMap = {}, _defineProperty(_dataTypeMap, gl.BYTE, 'int8'), _defineProperty(_dataTypeMap, gl.UNSIGNED_INT, 'int16'), _defineProperty(_dataTypeMap, gl.INT, 'int32'), _defineProperty(_dataTypeMap, gl.UNSIGNED_BYTE, 'uint8'), _defineProperty(_dataTypeMap, gl.UNSIGNED_SHORT, 'uint16'), _defineProperty(_dataTypeMap, gl.UNSIGNED_INT, 'uint32'), _defineProperty(_dataTypeMap, gl.FLOAT, 'float'), _dataTypeMap);
|
|
11
|
+
export var formatMap = (_formatMap = {}, _defineProperty(_formatMap, gl.ALPHA, 'alpha'), _defineProperty(_formatMap, gl.LUMINANCE, 'luminance'), _defineProperty(_formatMap, gl.LUMINANCE_ALPHA, 'luminance alpha'), _defineProperty(_formatMap, gl.RGB, 'rgb'), _defineProperty(_formatMap, gl.RGBA, 'rgba'), _defineProperty(_formatMap, gl.RGBA4, 'rgba4'), _defineProperty(_formatMap, gl.RGB5_A1, 'rgb5 a1'), _defineProperty(_formatMap, gl.RGB565, 'rgb565'), _defineProperty(_formatMap, gl.DEPTH_COMPONENT, 'depth'), _defineProperty(_formatMap, gl.DEPTH_STENCIL, 'depth stencil'), _formatMap);
|
|
12
|
+
export var mipmapMap = (_mipmapMap = {}, _defineProperty(_mipmapMap, gl.DONT_CARE, 'dont care'), _defineProperty(_mipmapMap, gl.NICEST, 'nice'), _defineProperty(_mipmapMap, gl.FASTEST, 'fast'), _mipmapMap);
|
|
13
|
+
export var filterMap = (_filterMap = {}, _defineProperty(_filterMap, gl.NEAREST, 'nearest'), _defineProperty(_filterMap, gl.LINEAR, 'linear'), _defineProperty(_filterMap, gl.LINEAR_MIPMAP_LINEAR, 'mipmap'), _defineProperty(_filterMap, gl.NEAREST_MIPMAP_LINEAR, 'nearest mipmap linear'), _defineProperty(_filterMap, gl.LINEAR_MIPMAP_NEAREST, 'linear mipmap nearest'), _defineProperty(_filterMap, gl.NEAREST_MIPMAP_NEAREST, 'nearest mipmap nearest'), _filterMap);
|
|
14
|
+
export var wrapModeMap = (_wrapModeMap = {}, _defineProperty(_wrapModeMap, gl.REPEAT, 'repeat'), _defineProperty(_wrapModeMap, gl.CLAMP_TO_EDGE, 'clamp'), _defineProperty(_wrapModeMap, gl.MIRRORED_REPEAT, 'mirror'), _wrapModeMap);
|
|
15
|
+
export var colorSpaceMap = (_colorSpaceMap = {}, _defineProperty(_colorSpaceMap, gl.NONE, 'none'), _defineProperty(_colorSpaceMap, gl.BROWSER_DEFAULT_WEBGL, 'browser'), _colorSpaceMap);
|
|
16
|
+
export var depthFuncMap = (_depthFuncMap = {}, _defineProperty(_depthFuncMap, gl.NEVER, 'never'), _defineProperty(_depthFuncMap, gl.ALWAYS, 'always'), _defineProperty(_depthFuncMap, gl.LESS, 'less'), _defineProperty(_depthFuncMap, gl.LEQUAL, 'lequal'), _defineProperty(_depthFuncMap, gl.GREATER, 'greater'), _defineProperty(_depthFuncMap, gl.GEQUAL, 'gequal'), _defineProperty(_depthFuncMap, gl.EQUAL, 'equal'), _defineProperty(_depthFuncMap, gl.NOTEQUAL, 'notequal'), _depthFuncMap);
|
|
17
|
+
export var blendEquationMap = (_blendEquationMap = {}, _defineProperty(_blendEquationMap, gl.FUNC_ADD, 'add'), _defineProperty(_blendEquationMap, gl.MIN_EXT, 'min'), _defineProperty(_blendEquationMap, gl.MAX_EXT, 'max'), _defineProperty(_blendEquationMap, gl.FUNC_SUBTRACT, 'subtract'), _defineProperty(_blendEquationMap, gl.FUNC_REVERSE_SUBTRACT, 'reverse subtract'), _blendEquationMap);
|
|
18
|
+
export var blendFuncMap = (_blendFuncMap = {}, _defineProperty(_blendFuncMap, gl.ZERO, 'zero'), _defineProperty(_blendFuncMap, gl.ONE, 'one'), _defineProperty(_blendFuncMap, gl.SRC_COLOR, 'src color'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_COLOR, 'one minus src color'), _defineProperty(_blendFuncMap, gl.SRC_ALPHA, 'src alpha'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_SRC_ALPHA, 'one minus src alpha'), _defineProperty(_blendFuncMap, gl.DST_COLOR, 'dst color'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_COLOR, 'one minus dst color'), _defineProperty(_blendFuncMap, gl.DST_ALPHA, 'dst alpha'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_DST_ALPHA, 'one minus dst alpha'), _defineProperty(_blendFuncMap, gl.CONSTANT_COLOR, 'constant color'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_CONSTANT_COLOR, 'one minus constant color'), _defineProperty(_blendFuncMap, gl.CONSTANT_ALPHA, 'constant alpha'), _defineProperty(_blendFuncMap, gl.ONE_MINUS_CONSTANT_ALPHA, 'one minus constant alpha'), _defineProperty(_blendFuncMap, gl.SRC_ALPHA_SATURATE, 'src alpha saturate'), _blendFuncMap);
|
|
19
|
+
export var stencilFuncMap = (_stencilFuncMap = {}, _defineProperty(_stencilFuncMap, gl.NEVER, 'never'), _defineProperty(_stencilFuncMap, gl.ALWAYS, 'always'), _defineProperty(_stencilFuncMap, gl.LESS, 'less'), _defineProperty(_stencilFuncMap, gl.LEQUAL, 'lequal'), _defineProperty(_stencilFuncMap, gl.GREATER, 'greater'), _defineProperty(_stencilFuncMap, gl.GEQUAL, 'gequal'), _defineProperty(_stencilFuncMap, gl.EQUAL, 'equal'), _defineProperty(_stencilFuncMap, gl.NOTEQUAL, 'notequal'), _stencilFuncMap);
|
|
20
|
+
export var stencilOpMap = (_stencilOpMap = {}, _defineProperty(_stencilOpMap, gl.ZERO, 'zero'), _defineProperty(_stencilOpMap, gl.KEEP, 'keep'), _defineProperty(_stencilOpMap, gl.REPLACE, 'replace'), _defineProperty(_stencilOpMap, gl.INVERT, 'invert'), _defineProperty(_stencilOpMap, gl.INCR, 'increment'), _defineProperty(_stencilOpMap, gl.DECR, 'decrement'), _defineProperty(_stencilOpMap, gl.INCR_WRAP, 'increment wrap'), _defineProperty(_stencilOpMap, gl.DECR_WRAP, 'decrement wrap'), _stencilOpMap);
|
|
21
|
+
export var cullFaceMap = (_cullFaceMap = {}, _defineProperty(_cullFaceMap, gl.FRONT, 'front'), _defineProperty(_cullFaceMap, gl.BACK, 'back'), _cullFaceMap);
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* render w/ regl
|
|
3
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md
|
|
4
|
+
*/
|
|
5
|
+
import { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
6
|
+
import 'reflect-metadata';
|
|
7
|
+
import regl from 'regl';
|
|
8
|
+
import ReglFramebuffer from './ReglFramebuffer';
|
|
9
|
+
/**
|
|
10
|
+
* regl renderer
|
|
11
|
+
*/
|
|
12
|
+
export default class ReglRendererService implements IRendererService {
|
|
13
|
+
extensionObject: IExtensions;
|
|
14
|
+
private gl;
|
|
15
|
+
private $container;
|
|
16
|
+
private canvas;
|
|
17
|
+
private width;
|
|
18
|
+
private height;
|
|
19
|
+
private isDirty;
|
|
20
|
+
init(canvas: HTMLCanvasElement, cfg: IRenderConfig, gl?: regl.Regl): Promise<void>;
|
|
21
|
+
getPointSizeRange(): any;
|
|
22
|
+
testExtension(name: string): boolean;
|
|
23
|
+
createModel: (options: IModelInitializationOptions) => IModel;
|
|
24
|
+
createAttribute: (options: IAttributeInitializationOptions) => IAttribute;
|
|
25
|
+
createBuffer: (options: IBufferInitializationOptions) => IBuffer;
|
|
26
|
+
createElements: (options: IElementsInitializationOptions) => IElements;
|
|
27
|
+
createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
|
|
28
|
+
createFramebuffer: (options: IFramebufferInitializationOptions) => ReglFramebuffer;
|
|
29
|
+
useFramebuffer: (framebuffer: IFramebuffer | null, drawCommands: () => void) => void;
|
|
30
|
+
clear: (options: IClearOptions) => void;
|
|
31
|
+
viewport: ({ x, y, width, height, }: {
|
|
32
|
+
x: number;
|
|
33
|
+
y: number;
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}) => void;
|
|
37
|
+
readPixels: (options: IReadPixelsOptions) => Uint8Array;
|
|
38
|
+
getViewportSize: () => {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
};
|
|
42
|
+
getContainer: () => HTMLElement | null;
|
|
43
|
+
getCanvas: () => HTMLCanvasElement;
|
|
44
|
+
getGLContext: () => WebGLRenderingContext;
|
|
45
|
+
setState(): void;
|
|
46
|
+
setBaseState(): void;
|
|
47
|
+
setCustomLayerDefaults(): void;
|
|
48
|
+
setDirty(flag: boolean): void;
|
|
49
|
+
getDirty(): boolean;
|
|
50
|
+
destroy: () => void;
|
|
51
|
+
}
|
package/es/regl/index.js
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
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
|
+
var _dec, _class;
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
+
/**
|
|
8
|
+
* render w/ regl
|
|
9
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { injectable } from 'inversify';
|
|
13
|
+
import 'reflect-metadata';
|
|
14
|
+
import regl from 'regl';
|
|
15
|
+
import ReglAttribute from "./ReglAttribute";
|
|
16
|
+
import ReglBuffer from "./ReglBuffer";
|
|
17
|
+
import ReglElements from "./ReglElements";
|
|
18
|
+
import ReglFramebuffer from "./ReglFramebuffer";
|
|
19
|
+
import ReglModel from "./ReglModel";
|
|
20
|
+
import ReglTexture2D from "./ReglTexture2D";
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* regl renderer
|
|
24
|
+
*/
|
|
25
|
+
var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/function () {
|
|
26
|
+
function ReglRendererService() {
|
|
27
|
+
var _this = this;
|
|
28
|
+
_classCallCheck(this, ReglRendererService);
|
|
29
|
+
_defineProperty(this, "createModel", function (options) {
|
|
30
|
+
return new ReglModel(_this.gl, options);
|
|
31
|
+
});
|
|
32
|
+
_defineProperty(this, "createAttribute", function (options) {
|
|
33
|
+
return new ReglAttribute(_this.gl, options);
|
|
34
|
+
});
|
|
35
|
+
_defineProperty(this, "createBuffer", function (options) {
|
|
36
|
+
return new ReglBuffer(_this.gl, options);
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "createElements", function (options) {
|
|
39
|
+
return new ReglElements(_this.gl, options);
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "createTexture2D", function (options) {
|
|
42
|
+
return new ReglTexture2D(_this.gl, options);
|
|
43
|
+
});
|
|
44
|
+
_defineProperty(this, "createFramebuffer", function (options) {
|
|
45
|
+
return new ReglFramebuffer(_this.gl, options);
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "useFramebuffer", function (framebuffer, drawCommands) {
|
|
48
|
+
_this.gl({
|
|
49
|
+
framebuffer: framebuffer ? framebuffer.get() : null
|
|
50
|
+
})(drawCommands);
|
|
51
|
+
});
|
|
52
|
+
_defineProperty(this, "clear", function (options) {
|
|
53
|
+
var _this$gl;
|
|
54
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
|
|
55
|
+
var color = options.color,
|
|
56
|
+
depth = options.depth,
|
|
57
|
+
stencil = options.stencil,
|
|
58
|
+
_options$framebuffer = options.framebuffer,
|
|
59
|
+
framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
|
|
60
|
+
var reglClearOptions = {
|
|
61
|
+
color: color,
|
|
62
|
+
depth: depth,
|
|
63
|
+
stencil: stencil
|
|
64
|
+
};
|
|
65
|
+
reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
|
|
66
|
+
(_this$gl = _this.gl) === null || _this$gl === void 0 ? void 0 : _this$gl.clear(reglClearOptions);
|
|
67
|
+
});
|
|
68
|
+
_defineProperty(this, "viewport", function (_ref) {
|
|
69
|
+
var x = _ref.x,
|
|
70
|
+
y = _ref.y,
|
|
71
|
+
width = _ref.width,
|
|
72
|
+
height = _ref.height;
|
|
73
|
+
// use WebGL context directly
|
|
74
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#unsafe-escape-hatch
|
|
75
|
+
_this.gl._gl.viewport(x, y, width, height);
|
|
76
|
+
_this.width = width;
|
|
77
|
+
_this.height = height;
|
|
78
|
+
_this.gl._refresh();
|
|
79
|
+
});
|
|
80
|
+
_defineProperty(this, "readPixels", function (options) {
|
|
81
|
+
var framebuffer = options.framebuffer,
|
|
82
|
+
x = options.x,
|
|
83
|
+
y = options.y,
|
|
84
|
+
width = options.width,
|
|
85
|
+
height = options.height;
|
|
86
|
+
var readPixelsOptions = {
|
|
87
|
+
x: x,
|
|
88
|
+
y: y,
|
|
89
|
+
width: width,
|
|
90
|
+
height: height
|
|
91
|
+
};
|
|
92
|
+
if (framebuffer) {
|
|
93
|
+
readPixelsOptions.framebuffer = framebuffer.get();
|
|
94
|
+
}
|
|
95
|
+
return _this.gl.read(readPixelsOptions);
|
|
96
|
+
});
|
|
97
|
+
_defineProperty(this, "getViewportSize", function () {
|
|
98
|
+
return {
|
|
99
|
+
width: _this.gl._gl.drawingBufferWidth,
|
|
100
|
+
height: _this.gl._gl.drawingBufferHeight
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
_defineProperty(this, "getContainer", function () {
|
|
104
|
+
var _this$canvas;
|
|
105
|
+
return (_this$canvas = _this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.parentElement;
|
|
106
|
+
});
|
|
107
|
+
_defineProperty(this, "getCanvas", function () {
|
|
108
|
+
// return this.$container?.getElementsByTagName('canvas')[0] || null;
|
|
109
|
+
return _this.canvas;
|
|
110
|
+
});
|
|
111
|
+
_defineProperty(this, "getGLContext", function () {
|
|
112
|
+
return _this.gl._gl;
|
|
113
|
+
});
|
|
114
|
+
_defineProperty(this, "destroy", function () {
|
|
115
|
+
var _this$gl2, _this$gl2$_gl, _this$gl2$_gl$getExte;
|
|
116
|
+
// this.canvas = null 清除对 webgl 实例的引用
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
_this.canvas = null;
|
|
119
|
+
|
|
120
|
+
// make sure release webgl context
|
|
121
|
+
(_this$gl2 = _this.gl) === null || _this$gl2 === void 0 ? void 0 : (_this$gl2$_gl = _this$gl2._gl) === null || _this$gl2$_gl === void 0 ? void 0 : (_this$gl2$_gl$getExte = _this$gl2$_gl.getExtension('WEBGL_lose_context')) === null || _this$gl2$_gl$getExte === void 0 ? void 0 : _this$gl2$_gl$getExte.loseContext();
|
|
122
|
+
|
|
123
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clean-up
|
|
124
|
+
_this.gl.destroy();
|
|
125
|
+
|
|
126
|
+
// @ts-ignore
|
|
127
|
+
_this.gl = null;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
_createClass(ReglRendererService, [{
|
|
131
|
+
key: "init",
|
|
132
|
+
value: function () {
|
|
133
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(canvas, cfg, gl) {
|
|
134
|
+
var _this2 = this;
|
|
135
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
136
|
+
while (1) switch (_context.prev = _context.next) {
|
|
137
|
+
case 0:
|
|
138
|
+
// this.$container = $container;
|
|
139
|
+
this.canvas = canvas;
|
|
140
|
+
if (!gl) {
|
|
141
|
+
_context.next = 5;
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
this.gl = gl;
|
|
145
|
+
_context.next = 8;
|
|
146
|
+
break;
|
|
147
|
+
case 5:
|
|
148
|
+
_context.next = 7;
|
|
149
|
+
return new Promise(function (resolve, reject) {
|
|
150
|
+
regl({
|
|
151
|
+
canvas: _this2.canvas,
|
|
152
|
+
attributes: {
|
|
153
|
+
alpha: true,
|
|
154
|
+
// use TAA instead of MSAA
|
|
155
|
+
// @see https://www.khronos.org/registry/webgl/specs/1.0/#5.2.1
|
|
156
|
+
antialias: cfg.antialias,
|
|
157
|
+
premultipliedAlpha: true,
|
|
158
|
+
preserveDrawingBuffer: cfg.preserveDrawingBuffer,
|
|
159
|
+
stencil: cfg.stencil
|
|
160
|
+
},
|
|
161
|
+
// TODO: use extensions
|
|
162
|
+
extensions: ['OES_element_index_uint', 'OES_standard_derivatives',
|
|
163
|
+
// wireframe
|
|
164
|
+
'ANGLE_instanced_arrays' // VSM shadow map
|
|
165
|
+
],
|
|
166
|
+
|
|
167
|
+
optionalExtensions: ['oes_texture_float_linear', 'OES_texture_float', 'EXT_texture_filter_anisotropic', 'EXT_blend_minmax', 'WEBGL_depth_texture', 'WEBGL_lose_context'],
|
|
168
|
+
profile: true,
|
|
169
|
+
onDone: function onDone(err, r) {
|
|
170
|
+
if (err || !r) {
|
|
171
|
+
reject(err);
|
|
172
|
+
}
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
resolve(r);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
case 7:
|
|
179
|
+
this.gl = _context.sent;
|
|
180
|
+
case 8:
|
|
181
|
+
this.extensionObject = {
|
|
182
|
+
OES_texture_float: this.testExtension('OES_texture_float')
|
|
183
|
+
};
|
|
184
|
+
case 9:
|
|
185
|
+
case "end":
|
|
186
|
+
return _context.stop();
|
|
187
|
+
}
|
|
188
|
+
}, _callee, this);
|
|
189
|
+
}));
|
|
190
|
+
function init(_x, _x2, _x3) {
|
|
191
|
+
return _init.apply(this, arguments);
|
|
192
|
+
}
|
|
193
|
+
return init;
|
|
194
|
+
}()
|
|
195
|
+
}, {
|
|
196
|
+
key: "getPointSizeRange",
|
|
197
|
+
value: function getPointSizeRange() {
|
|
198
|
+
return this.gl._gl.getParameter(this.gl._gl.ALIASED_POINT_SIZE_RANGE);
|
|
199
|
+
}
|
|
200
|
+
}, {
|
|
201
|
+
key: "testExtension",
|
|
202
|
+
value: function testExtension(name) {
|
|
203
|
+
// OES_texture_float
|
|
204
|
+
return !!this.getGLContext().getExtension(name);
|
|
205
|
+
}
|
|
206
|
+
}, {
|
|
207
|
+
key: "setState",
|
|
208
|
+
value:
|
|
209
|
+
// TODO: 临时方法
|
|
210
|
+
function setState() {
|
|
211
|
+
this.gl({
|
|
212
|
+
cull: {
|
|
213
|
+
enable: false,
|
|
214
|
+
face: 'back'
|
|
215
|
+
},
|
|
216
|
+
viewport: {
|
|
217
|
+
x: 0,
|
|
218
|
+
y: 0,
|
|
219
|
+
height: this.width,
|
|
220
|
+
width: this.height
|
|
221
|
+
},
|
|
222
|
+
blend: {
|
|
223
|
+
enable: true,
|
|
224
|
+
equation: 'add'
|
|
225
|
+
},
|
|
226
|
+
framebuffer: null
|
|
227
|
+
});
|
|
228
|
+
this.gl._refresh();
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
key: "setBaseState",
|
|
232
|
+
value: function setBaseState() {
|
|
233
|
+
this.gl({
|
|
234
|
+
cull: {
|
|
235
|
+
enable: false,
|
|
236
|
+
face: 'back'
|
|
237
|
+
},
|
|
238
|
+
viewport: {
|
|
239
|
+
x: 0,
|
|
240
|
+
y: 0,
|
|
241
|
+
height: this.width,
|
|
242
|
+
width: this.height
|
|
243
|
+
},
|
|
244
|
+
blend: {
|
|
245
|
+
enable: false,
|
|
246
|
+
equation: 'add'
|
|
247
|
+
},
|
|
248
|
+
framebuffer: null
|
|
249
|
+
});
|
|
250
|
+
this.gl._refresh();
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "setCustomLayerDefaults",
|
|
254
|
+
value: function setCustomLayerDefaults() {
|
|
255
|
+
var gl = this.getGLContext();
|
|
256
|
+
gl.disable(gl.CULL_FACE);
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
key: "setDirty",
|
|
260
|
+
value: function setDirty(flag) {
|
|
261
|
+
this.isDirty = flag;
|
|
262
|
+
}
|
|
263
|
+
}, {
|
|
264
|
+
key: "getDirty",
|
|
265
|
+
value: function getDirty() {
|
|
266
|
+
return this.isDirty;
|
|
267
|
+
}
|
|
268
|
+
}]);
|
|
269
|
+
return ReglRendererService;
|
|
270
|
+
}()) || _class);
|
|
271
|
+
export { ReglRendererService as default };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/index.ts
|
|
30
|
+
var src_exports = {};
|
|
31
|
+
__export(src_exports, {
|
|
32
|
+
ReglRendererService: () => import_regl.default
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
var import_regl = __toESM(require("./regl"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
ReglRendererService
|
|
39
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
|
|
19
|
+
// src/regl/ReglAttribute.ts
|
|
20
|
+
var ReglAttribute_exports = {};
|
|
21
|
+
__export(ReglAttribute_exports, {
|
|
22
|
+
default: () => ReglAttribute
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(ReglAttribute_exports);
|
|
25
|
+
var ReglAttribute = class {
|
|
26
|
+
constructor(gl, options) {
|
|
27
|
+
const { buffer, offset, stride, normalized, size, divisor } = options;
|
|
28
|
+
this.buffer = buffer;
|
|
29
|
+
this.attribute = {
|
|
30
|
+
buffer: buffer.get(),
|
|
31
|
+
offset: offset || 0,
|
|
32
|
+
stride: stride || 0,
|
|
33
|
+
normalized: normalized || false,
|
|
34
|
+
divisor: divisor || 0
|
|
35
|
+
};
|
|
36
|
+
if (size) {
|
|
37
|
+
this.attribute.size = size;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
get() {
|
|
41
|
+
return this.attribute;
|
|
42
|
+
}
|
|
43
|
+
updateBuffer(options) {
|
|
44
|
+
this.buffer.subData(options);
|
|
45
|
+
}
|
|
46
|
+
destroy() {
|
|
47
|
+
this.buffer.destroy();
|
|
48
|
+
}
|
|
49
|
+
};
|