@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,13 @@
|
|
|
1
|
+
import { Device } from '@antv/g-device-api';
|
|
2
|
+
import { IAttribute, IAttributeInitializationOptions, IBuffer } from '@antv/l7-core';
|
|
3
|
+
export default class DeviceAttribute implements IAttribute {
|
|
4
|
+
private attribute;
|
|
5
|
+
private buffer;
|
|
6
|
+
constructor(device: Device, options: IAttributeInitializationOptions);
|
|
7
|
+
get(): IBuffer;
|
|
8
|
+
updateBuffer(options: {
|
|
9
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
10
|
+
offset: number;
|
|
11
|
+
}): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
var DeviceAttribute = /*#__PURE__*/function () {
|
|
4
|
+
function DeviceAttribute(device, options) {
|
|
5
|
+
_classCallCheck(this, DeviceAttribute);
|
|
6
|
+
var buffer = options.buffer,
|
|
7
|
+
offset = options.offset,
|
|
8
|
+
stride = options.stride,
|
|
9
|
+
normalized = options.normalized,
|
|
10
|
+
size = options.size,
|
|
11
|
+
divisor = options.divisor,
|
|
12
|
+
shaderLocation = options.shaderLocation;
|
|
13
|
+
this.buffer = buffer;
|
|
14
|
+
this.attribute = {
|
|
15
|
+
shaderLocation: shaderLocation,
|
|
16
|
+
buffer: buffer.get(),
|
|
17
|
+
offset: offset || 0,
|
|
18
|
+
stride: stride || 0,
|
|
19
|
+
normalized: normalized || false,
|
|
20
|
+
divisor: divisor || 0
|
|
21
|
+
};
|
|
22
|
+
if (size) {
|
|
23
|
+
this.attribute.size = size;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
_createClass(DeviceAttribute, [{
|
|
27
|
+
key: "get",
|
|
28
|
+
value: function get() {
|
|
29
|
+
return this.buffer;
|
|
30
|
+
}
|
|
31
|
+
}, {
|
|
32
|
+
key: "updateBuffer",
|
|
33
|
+
value: function updateBuffer(options) {
|
|
34
|
+
this.buffer.subData(options);
|
|
35
|
+
}
|
|
36
|
+
}, {
|
|
37
|
+
key: "destroy",
|
|
38
|
+
value: function destroy() {
|
|
39
|
+
this.buffer.destroy();
|
|
40
|
+
}
|
|
41
|
+
}]);
|
|
42
|
+
return DeviceAttribute;
|
|
43
|
+
}();
|
|
44
|
+
export { DeviceAttribute as default };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
+
import { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
|
|
3
|
+
/**
|
|
4
|
+
* Use Buffer from @antv/g-device-api
|
|
5
|
+
*/
|
|
6
|
+
export default class DeviceBuffer implements IBuffer {
|
|
7
|
+
private buffer;
|
|
8
|
+
private isDestroyed;
|
|
9
|
+
private type;
|
|
10
|
+
private size;
|
|
11
|
+
constructor(device: Device, options: IBufferInitializationOptions);
|
|
12
|
+
get(): Buffer;
|
|
13
|
+
destroy(): void;
|
|
14
|
+
subData({ data, offset, }: {
|
|
15
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
16
|
+
offset: number;
|
|
17
|
+
}): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
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 { BufferUsage } from '@antv/g-device-api';
|
|
5
|
+
import { gl } from '@antv/l7-core';
|
|
6
|
+
import { hintMap, typedArrayCtorMap } from "./constants";
|
|
7
|
+
import { isTypedArray } from "./utils/typedarray";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Use Buffer from @antv/g-device-api
|
|
11
|
+
*/
|
|
12
|
+
var DeviceBuffer = /*#__PURE__*/function () {
|
|
13
|
+
function DeviceBuffer(device, options) {
|
|
14
|
+
_classCallCheck(this, DeviceBuffer);
|
|
15
|
+
_defineProperty(this, "isDestroyed", false);
|
|
16
|
+
var data = options.data,
|
|
17
|
+
usage = options.usage,
|
|
18
|
+
type = options.type,
|
|
19
|
+
isUBO = options.isUBO;
|
|
20
|
+
var typed;
|
|
21
|
+
if (isTypedArray(data)) {
|
|
22
|
+
typed = data;
|
|
23
|
+
} else {
|
|
24
|
+
typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
|
|
25
|
+
}
|
|
26
|
+
this.type = type;
|
|
27
|
+
this.size = typed.byteLength;
|
|
28
|
+
|
|
29
|
+
// @see https://www.npmjs.com/package/@antv/g-device-api#createBuffer
|
|
30
|
+
this.buffer = device.createBuffer({
|
|
31
|
+
viewOrSize: typed,
|
|
32
|
+
usage: isUBO ? BufferUsage.UNIFORM : BufferUsage.VERTEX,
|
|
33
|
+
hint: hintMap[usage || gl.STATIC_DRAW]
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
_createClass(DeviceBuffer, [{
|
|
37
|
+
key: "get",
|
|
38
|
+
value: function get() {
|
|
39
|
+
return this.buffer;
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
42
|
+
key: "destroy",
|
|
43
|
+
value: function destroy() {
|
|
44
|
+
if (!this.isDestroyed) {
|
|
45
|
+
this.buffer.destroy();
|
|
46
|
+
}
|
|
47
|
+
this.isDestroyed = true;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
50
|
+
key: "subData",
|
|
51
|
+
value: function subData(_ref) {
|
|
52
|
+
var data = _ref.data,
|
|
53
|
+
offset = _ref.offset;
|
|
54
|
+
var typed;
|
|
55
|
+
if (isTypedArray(data)) {
|
|
56
|
+
typed = data;
|
|
57
|
+
} else {
|
|
58
|
+
typed = new typedArrayCtorMap[this.type || gl.FLOAT](data);
|
|
59
|
+
}
|
|
60
|
+
this.buffer.setSubData(offset, new Uint8Array(typed.buffer));
|
|
61
|
+
}
|
|
62
|
+
}]);
|
|
63
|
+
return DeviceBuffer;
|
|
64
|
+
}();
|
|
65
|
+
export { DeviceBuffer as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
+
import { IElements, IElementsInitializationOptions } from '@antv/l7-core';
|
|
3
|
+
export default class DeviceElements implements IElements {
|
|
4
|
+
private indexBuffer;
|
|
5
|
+
private type;
|
|
6
|
+
private count;
|
|
7
|
+
constructor(device: Device, options: IElementsInitializationOptions);
|
|
8
|
+
get(): Buffer;
|
|
9
|
+
subData({ data, }: {
|
|
10
|
+
data: number[] | number[][] | Uint8Array | Uint16Array | Uint32Array;
|
|
11
|
+
}): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import { BufferUsage } from '@antv/g-device-api';
|
|
4
|
+
import { gl } from '@antv/l7-core';
|
|
5
|
+
import { typedArrayCtorMap } from "./constants";
|
|
6
|
+
import { isTypedArray } from "./utils/typedarray";
|
|
7
|
+
var DeviceElements = /*#__PURE__*/function () {
|
|
8
|
+
function DeviceElements(device, options) {
|
|
9
|
+
_classCallCheck(this, DeviceElements);
|
|
10
|
+
var data = options.data,
|
|
11
|
+
type = options.type,
|
|
12
|
+
_options$count = options.count,
|
|
13
|
+
count = _options$count === void 0 ? 0 : _options$count;
|
|
14
|
+
var typed;
|
|
15
|
+
if (isTypedArray(data)) {
|
|
16
|
+
typed = data;
|
|
17
|
+
} else {
|
|
18
|
+
typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
|
|
19
|
+
}
|
|
20
|
+
this.type = type;
|
|
21
|
+
this.count = count;
|
|
22
|
+
this.indexBuffer = device.createBuffer({
|
|
23
|
+
viewOrSize: typed,
|
|
24
|
+
usage: BufferUsage.INDEX
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_createClass(DeviceElements, [{
|
|
28
|
+
key: "get",
|
|
29
|
+
value: function get() {
|
|
30
|
+
return this.indexBuffer;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "subData",
|
|
34
|
+
value: function subData(_ref) {
|
|
35
|
+
var data = _ref.data;
|
|
36
|
+
var typed;
|
|
37
|
+
if (isTypedArray(data)) {
|
|
38
|
+
typed = data;
|
|
39
|
+
} else {
|
|
40
|
+
typed = new typedArrayCtorMap[this.type || gl.UNSIGNED_INT](data);
|
|
41
|
+
}
|
|
42
|
+
this.indexBuffer.setSubData(0, new Uint8Array(typed.buffer));
|
|
43
|
+
}
|
|
44
|
+
}, {
|
|
45
|
+
key: "destroy",
|
|
46
|
+
value: function destroy() {
|
|
47
|
+
this.indexBuffer.destroy();
|
|
48
|
+
}
|
|
49
|
+
}]);
|
|
50
|
+
return DeviceElements;
|
|
51
|
+
}();
|
|
52
|
+
export { DeviceElements as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Device, RenderTarget } from '@antv/g-device-api';
|
|
2
|
+
import { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
|
|
3
|
+
export default class DeviceFramebuffer implements IFramebuffer {
|
|
4
|
+
private device;
|
|
5
|
+
private renderTarget;
|
|
6
|
+
private width;
|
|
7
|
+
private height;
|
|
8
|
+
constructor(device: Device, options: IFramebufferInitializationOptions);
|
|
9
|
+
get(): RenderTarget;
|
|
10
|
+
destroy(): void;
|
|
11
|
+
resize({ width, height }: {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
}): void;
|
|
15
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import { Format } from '@antv/g-device-api';
|
|
4
|
+
import { isTexture2D } from "./DeviceTexture2D";
|
|
5
|
+
var DeviceFramebuffer = /*#__PURE__*/function () {
|
|
6
|
+
function DeviceFramebuffer(device, options) {
|
|
7
|
+
_classCallCheck(this, DeviceFramebuffer);
|
|
8
|
+
this.device = device;
|
|
9
|
+
// TODO: depth
|
|
10
|
+
var width = options.width,
|
|
11
|
+
height = options.height,
|
|
12
|
+
color = options.color;
|
|
13
|
+
if (isTexture2D(color)) {
|
|
14
|
+
this.renderTarget = device.createRenderTargetFromTexture(color.get());
|
|
15
|
+
this.width = color['width'];
|
|
16
|
+
this.height = color['height'];
|
|
17
|
+
} else if (width && height) {
|
|
18
|
+
this.renderTarget = device.createRenderTarget({
|
|
19
|
+
format: Format.U8_RGBA_RT,
|
|
20
|
+
width: width,
|
|
21
|
+
height: height
|
|
22
|
+
});
|
|
23
|
+
this.width = width;
|
|
24
|
+
this.height = height;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
_createClass(DeviceFramebuffer, [{
|
|
28
|
+
key: "get",
|
|
29
|
+
value: function get() {
|
|
30
|
+
return this.renderTarget;
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
key: "destroy",
|
|
34
|
+
value: function destroy() {
|
|
35
|
+
this.renderTarget.destroy();
|
|
36
|
+
}
|
|
37
|
+
}, {
|
|
38
|
+
key: "resize",
|
|
39
|
+
value: function resize(_ref) {
|
|
40
|
+
var width = _ref.width,
|
|
41
|
+
height = _ref.height;
|
|
42
|
+
if (this.width !== width || this.height !== height) {
|
|
43
|
+
if (this.renderTarget) {
|
|
44
|
+
this.renderTarget.destroy();
|
|
45
|
+
}
|
|
46
|
+
this.renderTarget = this.device.createRenderTarget({
|
|
47
|
+
format: Format.U8_RGBA_RT,
|
|
48
|
+
width: width,
|
|
49
|
+
height: height
|
|
50
|
+
});
|
|
51
|
+
this.width = width;
|
|
52
|
+
this.height = height;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}]);
|
|
56
|
+
return DeviceFramebuffer;
|
|
57
|
+
}();
|
|
58
|
+
export { DeviceFramebuffer as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Device } from '@antv/g-device-api';
|
|
2
|
+
import { IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
|
|
3
|
+
export default class DeviceModel implements IModel {
|
|
4
|
+
private device;
|
|
5
|
+
private options;
|
|
6
|
+
private destroyed;
|
|
7
|
+
private uniforms;
|
|
8
|
+
private program;
|
|
9
|
+
private inputLayout;
|
|
10
|
+
private pipeline;
|
|
11
|
+
private indexBuffer;
|
|
12
|
+
private vertexBuffers;
|
|
13
|
+
private bindings;
|
|
14
|
+
constructor(device: Device, options: IModelInitializationOptions);
|
|
15
|
+
private createPipeline;
|
|
16
|
+
updateAttributesAndElements(): void;
|
|
17
|
+
updateAttributes(): void;
|
|
18
|
+
addUniforms(uniforms: {
|
|
19
|
+
[key: string]: IUniform;
|
|
20
|
+
}): void;
|
|
21
|
+
draw(options: IModelDrawOptions): void;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
private initDepthDrawParams;
|
|
24
|
+
private getBlendDrawParams;
|
|
25
|
+
/**
|
|
26
|
+
* @see https://github.com/regl-project/regl/blob/gh-pages/API.md#culling
|
|
27
|
+
*/
|
|
28
|
+
private initCullDrawParams;
|
|
29
|
+
/**
|
|
30
|
+
* 考虑结构体命名, eg:
|
|
31
|
+
* a: { b: 1 } -> 'a.b'
|
|
32
|
+
* a: [ { b: 1 } ] -> 'a[0].b'
|
|
33
|
+
*/
|
|
34
|
+
private extractUniforms;
|
|
35
|
+
private extractUniformsRecursively;
|
|
36
|
+
}
|