@antv/l7-renderer 2.21.1 → 2.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/device/DeviceAttribute.js +26 -32
- package/es/device/DeviceBuffer.js +31 -49
- package/es/device/DeviceCache.js +136 -170
- package/es/device/DeviceElements.js +32 -38
- package/es/device/DeviceFramebuffer.js +76 -104
- package/es/device/DeviceModel.js +358 -384
- package/es/device/DeviceTexture2D.js +103 -122
- package/es/device/constants.js +117 -34
- package/es/device/index.js +254 -381
- package/es/device/utils/HashMap.js +71 -138
- package/es/device/utils/pipeline.js +6 -1
- package/es/device/utils/typedarray.js +23 -24
- package/es/device/utils/webgl.js +7 -6
- package/es/index.js +5 -4
- package/es/regl/ReglAttribute.js +17 -33
- package/es/regl/ReglBuffer.js +25 -40
- package/es/regl/ReglElements.js +21 -36
- package/es/regl/ReglFramebuffer.js +24 -44
- package/es/regl/ReglModel.js +266 -306
- package/es/regl/ReglRenderbuffer.js +19 -36
- package/es/regl/ReglTexture2D.js +72 -103
- package/es/regl/constants.js +133 -21
- package/es/regl/index.js +205 -289
- package/lib/device/DeviceAttribute.d.ts +13 -0
- package/lib/device/DeviceBuffer.d.ts +18 -0
- package/lib/device/DeviceCache.d.ts +14 -0
- package/lib/device/DeviceElements.d.ts +13 -0
- package/lib/device/DeviceFramebuffer.d.ts +24 -0
- package/lib/device/DeviceModel.d.ts +53 -0
- package/lib/device/DeviceModel.js +22 -15
- package/lib/device/DeviceTexture2D.d.ts +23 -0
- package/lib/device/constants.d.ts +35 -0
- package/lib/device/index.d.ts +68 -0
- package/lib/device/index.js +58 -36
- package/lib/device/utils/HashMap.d.ts +24 -0
- package/lib/device/utils/pipeline.d.ts +1 -0
- package/lib/device/utils/typedarray.d.ts +7 -0
- package/lib/device/utils/webgl.d.ts +1 -0
- package/lib/index.d.ts +6 -0
- package/lib/regl/ReglAttribute.d.ts +16 -0
- package/lib/regl/ReglBuffer.d.ts +17 -0
- package/lib/regl/ReglElements.d.ts +14 -0
- package/lib/regl/ReglFramebuffer.d.ts +16 -0
- package/lib/regl/ReglModel.d.ts +46 -0
- package/lib/regl/ReglModel.js +21 -11
- package/lib/regl/ReglRenderbuffer.d.ts +16 -0
- package/lib/regl/ReglTexture2D.d.ts +22 -0
- package/lib/regl/constants.d.ts +43 -0
- package/lib/regl/index.d.ts +56 -0
- package/lib/regl/index.js +70 -48
- package/package.json +14 -18
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// src/device/DeviceTexture2D.ts
|
|
2
|
+
import {
|
|
3
|
+
TextureUsage as DeviceTextureUsage,
|
|
4
|
+
FilterMode,
|
|
5
|
+
Format,
|
|
6
|
+
MipmapFilterMode
|
|
7
|
+
} from "@antv/g-device-api";
|
|
8
|
+
import { TextureUsage, gl } from "@antv/l7-core";
|
|
6
9
|
import { wrapModeMap } from "./constants";
|
|
7
10
|
import { extend3ChannelsTo4 } from "./utils/typedarray";
|
|
8
|
-
|
|
9
|
-
return !!(t && t[
|
|
11
|
+
function isTexture2D(t) {
|
|
12
|
+
return !!(t && t["texture"]);
|
|
10
13
|
}
|
|
11
|
-
var DeviceTexture2D =
|
|
12
|
-
|
|
13
|
-
_classCallCheck(this, DeviceTexture2D);
|
|
14
|
-
_defineProperty(this, "isDestroy", false);
|
|
14
|
+
var DeviceTexture2D = class {
|
|
15
|
+
constructor(device, options) {
|
|
15
16
|
this.device = device;
|
|
16
17
|
this.options = options;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
wrapT =
|
|
21
|
-
aniso
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
min = _options$min === void 0 ? gl.NEAREST : _options$min;
|
|
18
|
+
this.isDestroy = false;
|
|
19
|
+
const {
|
|
20
|
+
wrapS = gl.CLAMP_TO_EDGE,
|
|
21
|
+
wrapT = gl.CLAMP_TO_EDGE,
|
|
22
|
+
aniso,
|
|
23
|
+
mag = gl.NEAREST,
|
|
24
|
+
min = gl.NEAREST
|
|
25
|
+
} = options;
|
|
26
26
|
this.createTexture(options);
|
|
27
27
|
this.sampler = device.createSampler({
|
|
28
28
|
addressModeU: wrapModeMap[wrapS],
|
|
@@ -35,115 +35,96 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
35
35
|
maxAnisotropy: aniso
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (data) {
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
data = extend3ChannelsTo4(data, 0);
|
|
70
|
-
}
|
|
71
|
-
pixelFormat = Format.F32_RGBA;
|
|
72
|
-
} else {
|
|
73
|
-
pixelFormat = Format.F32_RGB;
|
|
38
|
+
createTexture(options) {
|
|
39
|
+
const {
|
|
40
|
+
type = gl.UNSIGNED_BYTE,
|
|
41
|
+
width,
|
|
42
|
+
height,
|
|
43
|
+
flipY = false,
|
|
44
|
+
format = gl.RGBA,
|
|
45
|
+
alignment = 1,
|
|
46
|
+
usage = TextureUsage.SAMPLED,
|
|
47
|
+
// premultiplyAlpha = false,
|
|
48
|
+
unorm = false,
|
|
49
|
+
// colorSpace = gl.BROWSER_DEFAULT_WEBGL,
|
|
50
|
+
// x = 0,
|
|
51
|
+
// y = 0,
|
|
52
|
+
// copy = false,
|
|
53
|
+
label
|
|
54
|
+
} = options;
|
|
55
|
+
let { data } = options;
|
|
56
|
+
this.width = width;
|
|
57
|
+
this.height = height;
|
|
58
|
+
let pixelFormat = Format.U8_RGBA_RT;
|
|
59
|
+
if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
|
|
60
|
+
pixelFormat = unorm ? Format.U8_RGBA_NORM : Format.U8_RGBA_RT;
|
|
61
|
+
} else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
|
|
62
|
+
pixelFormat = Format.U8_LUMINANCE;
|
|
63
|
+
} else if (type === gl.FLOAT && format === gl.RGB) {
|
|
64
|
+
if (this.device.queryVendorInfo().platformString === "WebGPU") {
|
|
65
|
+
if (data) {
|
|
66
|
+
data = extend3ChannelsTo4(data, 0);
|
|
74
67
|
}
|
|
75
|
-
} else if (type === gl.FLOAT && format === gl.RGBA) {
|
|
76
68
|
pixelFormat = Format.F32_RGBA;
|
|
77
|
-
} else if (type === gl.FLOAT && format === gl.RED) {
|
|
78
|
-
pixelFormat = Format.F32_R;
|
|
79
69
|
} else {
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
this.texture = this.device.createTexture({
|
|
83
|
-
format: pixelFormat,
|
|
84
|
-
width: width,
|
|
85
|
-
height: height,
|
|
86
|
-
usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
|
|
87
|
-
pixelStore: {
|
|
88
|
-
unpackFlipY: flipY,
|
|
89
|
-
packAlignment: alignment
|
|
90
|
-
},
|
|
91
|
-
// mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
|
|
92
|
-
mipLevelCount: 1
|
|
93
|
-
});
|
|
94
|
-
if (label) {
|
|
95
|
-
this.device.setResourceName(this.texture, label);
|
|
96
|
-
}
|
|
97
|
-
if (data) {
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
this.texture.setImageData([data]);
|
|
70
|
+
pixelFormat = Format.F32_RGB;
|
|
100
71
|
}
|
|
72
|
+
} else if (type === gl.FLOAT && format === gl.RGBA) {
|
|
73
|
+
pixelFormat = Format.F32_RGBA;
|
|
74
|
+
} else if (type === gl.FLOAT && format === gl.RED) {
|
|
75
|
+
pixelFormat = Format.F32_R;
|
|
76
|
+
} else {
|
|
77
|
+
throw new Error(`create texture error, type: ${type}, format: ${format}`);
|
|
101
78
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
79
|
+
this.texture = this.device.createTexture({
|
|
80
|
+
format: pixelFormat,
|
|
81
|
+
width,
|
|
82
|
+
height,
|
|
83
|
+
usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
|
|
84
|
+
pixelStore: {
|
|
85
|
+
unpackFlipY: flipY,
|
|
86
|
+
packAlignment: alignment
|
|
87
|
+
},
|
|
88
|
+
// mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0,
|
|
89
|
+
mipLevelCount: 1
|
|
90
|
+
});
|
|
91
|
+
if (label) {
|
|
92
|
+
this.device.setResourceName(this.texture, label);
|
|
106
93
|
}
|
|
107
|
-
|
|
108
|
-
key: "update",
|
|
109
|
-
value: function update(props) {
|
|
110
|
-
var data = props.data;
|
|
94
|
+
if (data) {
|
|
111
95
|
this.texture.setImageData([data]);
|
|
112
96
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
this.options.width = width;
|
|
127
|
-
this.options.height = height;
|
|
128
|
-
this.createTexture(this.options);
|
|
129
|
-
this.isDestroy = false;
|
|
130
|
-
}
|
|
131
|
-
}, {
|
|
132
|
-
key: "getSize",
|
|
133
|
-
value: function getSize() {
|
|
134
|
-
return [this.width, this.height];
|
|
97
|
+
}
|
|
98
|
+
get() {
|
|
99
|
+
return this.texture;
|
|
100
|
+
}
|
|
101
|
+
update(props) {
|
|
102
|
+
const { data } = props;
|
|
103
|
+
this.texture.setImageData([data]);
|
|
104
|
+
}
|
|
105
|
+
bind() {
|
|
106
|
+
}
|
|
107
|
+
resize({ width, height }) {
|
|
108
|
+
if (this.width !== width || this.height !== height) {
|
|
109
|
+
this.destroy();
|
|
135
110
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
111
|
+
this.options.width = width;
|
|
112
|
+
this.options.height = height;
|
|
113
|
+
this.createTexture(this.options);
|
|
114
|
+
this.isDestroy = false;
|
|
115
|
+
}
|
|
116
|
+
getSize() {
|
|
117
|
+
return [this.width, this.height];
|
|
118
|
+
}
|
|
119
|
+
destroy() {
|
|
120
|
+
var _a;
|
|
121
|
+
if (!this.isDestroy && !this.texture.destroyed) {
|
|
122
|
+
(_a = this.texture) == null ? void 0 : _a.destroy();
|
|
145
123
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
export {
|
|
124
|
+
this.isDestroy = true;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
export {
|
|
128
|
+
DeviceTexture2D as default,
|
|
129
|
+
isTexture2D
|
|
130
|
+
};
|
package/es/device/constants.js
CHANGED
|
@@ -1,34 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
// src/device/constants.ts
|
|
2
|
+
import {
|
|
3
|
+
AddressMode,
|
|
4
|
+
BlendFactor,
|
|
5
|
+
BlendMode,
|
|
6
|
+
BufferFrequencyHint,
|
|
7
|
+
CompareFunction,
|
|
8
|
+
CullMode,
|
|
9
|
+
Format,
|
|
10
|
+
PrimitiveTopology,
|
|
11
|
+
StencilOp
|
|
12
|
+
} from "@antv/g-device-api";
|
|
13
|
+
import { gl } from "@antv/l7-core";
|
|
14
|
+
var typedArrayCtorMap = {
|
|
15
|
+
[gl.FLOAT]: Float32Array,
|
|
16
|
+
[gl.UNSIGNED_BYTE]: Uint8Array,
|
|
17
|
+
[gl.SHORT]: Int16Array,
|
|
18
|
+
[gl.UNSIGNED_SHORT]: Uint16Array,
|
|
19
|
+
[gl.INT]: Int32Array,
|
|
20
|
+
[gl.UNSIGNED_INT]: Uint32Array
|
|
21
|
+
};
|
|
22
|
+
var primitiveMap = {
|
|
23
|
+
[gl.POINTS]: PrimitiveTopology.POINTS,
|
|
24
|
+
[gl.LINES]: PrimitiveTopology.LINES,
|
|
25
|
+
[gl.LINE_LOOP]: PrimitiveTopology.LINES,
|
|
26
|
+
[gl.LINE_STRIP]: PrimitiveTopology.LINE_STRIP,
|
|
27
|
+
[gl.TRIANGLES]: PrimitiveTopology.TRIANGLES,
|
|
28
|
+
[gl.TRIANGLE_FAN]: PrimitiveTopology.TRIANGLES,
|
|
29
|
+
[gl.TRIANGLE_STRIP]: PrimitiveTopology.TRIANGLE_STRIP
|
|
30
|
+
};
|
|
31
|
+
var sizeFormatMap = {
|
|
32
|
+
[1]: Format.F32_R,
|
|
33
|
+
[2]: Format.F32_RG,
|
|
34
|
+
[3]: Format.F32_RGB,
|
|
35
|
+
[4]: Format.F32_RGBA
|
|
36
|
+
};
|
|
37
|
+
var hintMap = {
|
|
38
|
+
[gl.STATIC_DRAW]: BufferFrequencyHint.STATIC,
|
|
39
|
+
[gl.DYNAMIC_DRAW]: BufferFrequencyHint.DYNAMIC,
|
|
40
|
+
[gl.STREAM_DRAW]: BufferFrequencyHint.DYNAMIC
|
|
41
|
+
};
|
|
42
|
+
var wrapModeMap = {
|
|
43
|
+
[gl.REPEAT]: AddressMode.REPEAT,
|
|
44
|
+
[gl.CLAMP_TO_EDGE]: AddressMode.CLAMP_TO_EDGE,
|
|
45
|
+
[gl.MIRRORED_REPEAT]: AddressMode.MIRRORED_REPEAT
|
|
46
|
+
};
|
|
47
|
+
var depthFuncMap = {
|
|
48
|
+
[gl.NEVER]: CompareFunction.NEVER,
|
|
49
|
+
[gl.ALWAYS]: CompareFunction.ALWAYS,
|
|
50
|
+
[gl.LESS]: CompareFunction.LESS,
|
|
51
|
+
[gl.LEQUAL]: CompareFunction.LEQUAL,
|
|
52
|
+
[gl.GREATER]: CompareFunction.GREATER,
|
|
53
|
+
[gl.GEQUAL]: CompareFunction.GEQUAL,
|
|
54
|
+
[gl.EQUAL]: CompareFunction.EQUAL,
|
|
55
|
+
[gl.NOTEQUAL]: CompareFunction.NOTEQUAL
|
|
56
|
+
};
|
|
57
|
+
var cullFaceMap = {
|
|
58
|
+
[gl.FRONT]: CullMode.FRONT,
|
|
59
|
+
[gl.BACK]: CullMode.BACK
|
|
60
|
+
};
|
|
61
|
+
var blendEquationMap = {
|
|
62
|
+
[gl.FUNC_ADD]: BlendMode.ADD,
|
|
63
|
+
[gl.MIN_EXT]: BlendMode.MIN,
|
|
64
|
+
[gl.MAX_EXT]: BlendMode.MAX,
|
|
65
|
+
[gl.FUNC_SUBTRACT]: BlendMode.SUBSTRACT,
|
|
66
|
+
[gl.FUNC_REVERSE_SUBTRACT]: BlendMode.REVERSE_SUBSTRACT
|
|
67
|
+
};
|
|
68
|
+
var blendFuncMap = {
|
|
69
|
+
[gl.ZERO]: BlendFactor.ZERO,
|
|
70
|
+
[gl.ONE]: BlendFactor.ONE,
|
|
71
|
+
[gl.SRC_COLOR]: BlendFactor.SRC,
|
|
72
|
+
[gl.ONE_MINUS_SRC_COLOR]: BlendFactor.ONE_MINUS_SRC,
|
|
73
|
+
[gl.SRC_ALPHA]: BlendFactor.SRC_ALPHA,
|
|
74
|
+
[gl.ONE_MINUS_SRC_ALPHA]: BlendFactor.ONE_MINUS_SRC_ALPHA,
|
|
75
|
+
[gl.DST_COLOR]: BlendFactor.DST,
|
|
76
|
+
[gl.ONE_MINUS_DST_COLOR]: BlendFactor.ONE_MINUS_DST,
|
|
77
|
+
[gl.DST_ALPHA]: BlendFactor.DST_ALPHA,
|
|
78
|
+
[gl.ONE_MINUS_DST_ALPHA]: BlendFactor.ONE_MINUS_DST_ALPHA,
|
|
79
|
+
[gl.CONSTANT_COLOR]: BlendFactor.CONST,
|
|
80
|
+
[gl.ONE_MINUS_CONSTANT_COLOR]: BlendFactor.ONE_MINUS_CONSTANT,
|
|
81
|
+
[gl.CONSTANT_ALPHA]: BlendFactor.CONST,
|
|
82
|
+
[gl.ONE_MINUS_CONSTANT_ALPHA]: BlendFactor.ONE_MINUS_CONSTANT,
|
|
83
|
+
[gl.SRC_ALPHA_SATURATE]: BlendFactor.SRC_ALPHA_SATURATE
|
|
84
|
+
};
|
|
85
|
+
var stencilOpMap = {
|
|
86
|
+
[gl.REPLACE]: StencilOp.REPLACE,
|
|
87
|
+
[gl.KEEP]: StencilOp.KEEP,
|
|
88
|
+
[gl.ZERO]: StencilOp.ZERO,
|
|
89
|
+
[gl.INVERT]: StencilOp.INVERT,
|
|
90
|
+
[gl.INCR]: StencilOp.INCREMENT_CLAMP,
|
|
91
|
+
[gl.DECR]: StencilOp.DECREMENT_CLAMP,
|
|
92
|
+
[gl.INCR_WRAP]: StencilOp.INCREMENT_WRAP,
|
|
93
|
+
[gl.DECR_WRAP]: StencilOp.DECREMENT_WRAP
|
|
94
|
+
};
|
|
95
|
+
var stencilFuncMap = {
|
|
96
|
+
[gl.ALWAYS]: CompareFunction.ALWAYS,
|
|
97
|
+
[gl.EQUAL]: CompareFunction.EQUAL,
|
|
98
|
+
[gl.GEQUAL]: CompareFunction.GEQUAL,
|
|
99
|
+
[gl.GREATER]: CompareFunction.GREATER,
|
|
100
|
+
[gl.LEQUAL]: CompareFunction.LEQUAL,
|
|
101
|
+
[gl.LESS]: CompareFunction.LESS,
|
|
102
|
+
[gl.NEVER]: CompareFunction.NEVER,
|
|
103
|
+
[gl.NOTEQUAL]: CompareFunction.NOTEQUAL
|
|
104
|
+
};
|
|
105
|
+
export {
|
|
106
|
+
blendEquationMap,
|
|
107
|
+
blendFuncMap,
|
|
108
|
+
cullFaceMap,
|
|
109
|
+
depthFuncMap,
|
|
110
|
+
hintMap,
|
|
111
|
+
primitiveMap,
|
|
112
|
+
sizeFormatMap,
|
|
113
|
+
stencilFuncMap,
|
|
114
|
+
stencilOpMap,
|
|
115
|
+
typedArrayCtorMap,
|
|
116
|
+
wrapModeMap
|
|
117
|
+
};
|