@antv/l7-renderer 2.20.5 → 2.20.6
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 +2 -2
- package/es/device/DeviceBuffer.d.ts +2 -2
- package/es/device/DeviceBuffer.js +5 -1
- package/es/device/DeviceElements.d.ts +2 -2
- package/es/device/DeviceFramebuffer.d.ts +12 -3
- package/es/device/DeviceFramebuffer.js +70 -30
- package/es/device/DeviceModel.d.ts +17 -4
- package/es/device/DeviceModel.js +64 -40
- package/es/device/DeviceTexture2D.d.ts +2 -2
- package/es/device/DeviceTexture2D.js +25 -22
- package/es/device/constants.d.ts +1 -1
- package/es/device/index.d.ts +20 -12
- package/es/device/index.js +73 -74
- package/es/regl/ReglAttribute.d.ts +2 -2
- package/es/regl/ReglBuffer.d.ts +2 -2
- package/es/regl/ReglElements.d.ts +2 -2
- package/es/regl/ReglFramebuffer.d.ts +2 -2
- package/es/regl/ReglModel.d.ts +2 -2
- package/es/regl/ReglModel.js +4 -2
- package/es/regl/ReglRenderbuffer.d.ts +2 -2
- package/es/regl/ReglTexture2D.d.ts +2 -2
- package/es/regl/constants.d.ts +1 -1
- package/es/regl/index.d.ts +1 -1
- package/lib/device/DeviceBuffer.js +4 -1
- package/lib/device/DeviceFramebuffer.js +61 -27
- package/lib/device/DeviceModel.js +59 -11
- package/lib/device/DeviceTexture2D.js +18 -17
- package/lib/device/index.js +60 -27
- package/lib/regl/ReglModel.js +8 -6
- package/package.json +9 -9
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Device } from '@antv/g-device-api';
|
|
2
|
-
import { IAttribute, IAttributeInitializationOptions, IBuffer } from '@antv/l7-core';
|
|
1
|
+
import type { Device } from '@antv/g-device-api';
|
|
2
|
+
import type { IAttribute, IAttributeInitializationOptions, IBuffer } from '@antv/l7-core';
|
|
3
3
|
export default class DeviceAttribute implements IAttribute {
|
|
4
4
|
private attribute;
|
|
5
5
|
private buffer;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
-
import { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
|
|
1
|
+
import type { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
+
import type { IBuffer, IBufferInitializationOptions } from '@antv/l7-core';
|
|
3
3
|
/**
|
|
4
4
|
* Use Buffer from @antv/g-device-api
|
|
5
5
|
*/
|
|
@@ -16,7 +16,8 @@ var DeviceBuffer = /*#__PURE__*/function () {
|
|
|
16
16
|
var data = options.data,
|
|
17
17
|
usage = options.usage,
|
|
18
18
|
type = options.type,
|
|
19
|
-
isUBO = options.isUBO
|
|
19
|
+
isUBO = options.isUBO,
|
|
20
|
+
label = options.label;
|
|
20
21
|
var typed;
|
|
21
22
|
if (isTypedArray(data)) {
|
|
22
23
|
typed = data;
|
|
@@ -32,6 +33,9 @@ var DeviceBuffer = /*#__PURE__*/function () {
|
|
|
32
33
|
usage: isUBO ? BufferUsage.UNIFORM : BufferUsage.VERTEX,
|
|
33
34
|
hint: hintMap[usage || gl.STATIC_DRAW]
|
|
34
35
|
});
|
|
36
|
+
if (label) {
|
|
37
|
+
device.setResourceName(this.buffer, label);
|
|
38
|
+
}
|
|
35
39
|
}
|
|
36
40
|
_createClass(DeviceBuffer, [{
|
|
37
41
|
key: "get",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
-
import { IElements, IElementsInitializationOptions } from '@antv/l7-core';
|
|
1
|
+
import type { Buffer, Device } from '@antv/g-device-api';
|
|
2
|
+
import type { IElements, IElementsInitializationOptions } from '@antv/l7-core';
|
|
3
3
|
export default class DeviceElements implements IElements {
|
|
4
4
|
private indexBuffer;
|
|
5
5
|
private type;
|
|
@@ -1,11 +1,20 @@
|
|
|
1
|
-
import { Device, RenderTarget } from '@antv/g-device-api';
|
|
2
|
-
import { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
|
|
1
|
+
import type { Device, RenderTarget, Texture } from '@antv/g-device-api';
|
|
2
|
+
import type { IFramebuffer, IFramebufferInitializationOptions } from '@antv/l7-core';
|
|
3
|
+
/**
|
|
4
|
+
* Contains 2 render targets: color and depth.
|
|
5
|
+
*/
|
|
3
6
|
export default class DeviceFramebuffer implements IFramebuffer {
|
|
4
7
|
private device;
|
|
5
|
-
private
|
|
8
|
+
private options;
|
|
9
|
+
private colorRenderTarget;
|
|
10
|
+
colorTexture: Texture;
|
|
11
|
+
private depthRenderTarget;
|
|
12
|
+
private depthTexture;
|
|
6
13
|
private width;
|
|
7
14
|
private height;
|
|
8
15
|
constructor(device: Device, options: IFramebufferInitializationOptions);
|
|
16
|
+
private createColorRenderTarget;
|
|
17
|
+
private createDepthRenderTarget;
|
|
9
18
|
get(): RenderTarget;
|
|
10
19
|
destroy(): void;
|
|
11
20
|
resize({ width, height }: {
|
|
@@ -1,38 +1,83 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import { Format } from '@antv/g-device-api';
|
|
3
|
+
import { Format, TextureUsage } from '@antv/g-device-api';
|
|
4
4
|
import { isTexture2D } from "./DeviceTexture2D";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Contains 2 render targets: color and depth.
|
|
8
|
+
*/
|
|
5
9
|
var DeviceFramebuffer = /*#__PURE__*/function () {
|
|
6
10
|
function DeviceFramebuffer(device, options) {
|
|
7
11
|
_classCallCheck(this, DeviceFramebuffer);
|
|
8
12
|
this.device = device;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
}
|
|
13
|
+
this.options = options;
|
|
14
|
+
this.createColorRenderTarget();
|
|
15
|
+
this.createDepthRenderTarget();
|
|
26
16
|
}
|
|
27
17
|
_createClass(DeviceFramebuffer, [{
|
|
18
|
+
key: "createColorRenderTarget",
|
|
19
|
+
value: function createColorRenderTarget() {
|
|
20
|
+
var _this$options = this.options,
|
|
21
|
+
width = _this$options.width,
|
|
22
|
+
height = _this$options.height,
|
|
23
|
+
color = _this$options.color;
|
|
24
|
+
if (color) {
|
|
25
|
+
if (isTexture2D(color)) {
|
|
26
|
+
this.colorTexture = color.get();
|
|
27
|
+
this.colorRenderTarget = this.device.createRenderTargetFromTexture(this.colorTexture);
|
|
28
|
+
this.width = color['width'];
|
|
29
|
+
this.height = color['height'];
|
|
30
|
+
} else if (width && height) {
|
|
31
|
+
this.colorTexture = this.device.createTexture({
|
|
32
|
+
format: Format.U8_RGBA_RT,
|
|
33
|
+
usage: TextureUsage.RENDER_TARGET,
|
|
34
|
+
width: width,
|
|
35
|
+
height: height
|
|
36
|
+
});
|
|
37
|
+
this.colorRenderTarget = this.device.createRenderTargetFromTexture(this.colorTexture);
|
|
38
|
+
this.width = width;
|
|
39
|
+
this.height = height;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
key: "createDepthRenderTarget",
|
|
45
|
+
value: function createDepthRenderTarget() {
|
|
46
|
+
var _this$options2 = this.options,
|
|
47
|
+
width = _this$options2.width,
|
|
48
|
+
height = _this$options2.height,
|
|
49
|
+
depth = _this$options2.depth;
|
|
50
|
+
// TODO: avoid creating depth texture if not needed
|
|
51
|
+
if (depth) {
|
|
52
|
+
if (isTexture2D(depth)) {
|
|
53
|
+
this.depthTexture = depth.get();
|
|
54
|
+
this.depthRenderTarget = this.device.createRenderTargetFromTexture(this.depthTexture);
|
|
55
|
+
this.width = depth['width'];
|
|
56
|
+
this.height = depth['height'];
|
|
57
|
+
} else if (width && height) {
|
|
58
|
+
this.depthTexture = this.device.createTexture({
|
|
59
|
+
format: Format.D24_S8,
|
|
60
|
+
usage: TextureUsage.RENDER_TARGET,
|
|
61
|
+
width: width,
|
|
62
|
+
height: height
|
|
63
|
+
});
|
|
64
|
+
this.depthRenderTarget = this.device.createRenderTargetFromTexture(this.depthTexture);
|
|
65
|
+
this.width = width;
|
|
66
|
+
this.height = height;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}, {
|
|
28
71
|
key: "get",
|
|
29
72
|
value: function get() {
|
|
30
|
-
return this.
|
|
73
|
+
return this.colorRenderTarget;
|
|
31
74
|
}
|
|
32
75
|
}, {
|
|
33
76
|
key: "destroy",
|
|
34
77
|
value: function destroy() {
|
|
35
|
-
|
|
78
|
+
var _this$colorRenderTarg, _this$depthRenderTarg;
|
|
79
|
+
(_this$colorRenderTarg = this.colorRenderTarget) === null || _this$colorRenderTarg === void 0 || _this$colorRenderTarg.destroy();
|
|
80
|
+
(_this$depthRenderTarg = this.depthRenderTarget) === null || _this$depthRenderTarg === void 0 || _this$depthRenderTarg.destroy();
|
|
36
81
|
}
|
|
37
82
|
}, {
|
|
38
83
|
key: "resize",
|
|
@@ -40,16 +85,11 @@ var DeviceFramebuffer = /*#__PURE__*/function () {
|
|
|
40
85
|
var width = _ref.width,
|
|
41
86
|
height = _ref.height;
|
|
42
87
|
if (this.width !== width || this.height !== height) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
width: width,
|
|
49
|
-
height: height
|
|
50
|
-
});
|
|
51
|
-
this.width = width;
|
|
52
|
-
this.height = height;
|
|
88
|
+
this.destroy();
|
|
89
|
+
this.options.width = width;
|
|
90
|
+
this.options.height = height;
|
|
91
|
+
this.createColorRenderTarget();
|
|
92
|
+
this.createDepthRenderTarget();
|
|
53
93
|
}
|
|
54
94
|
}
|
|
55
95
|
}]);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Device } from '@antv/g-device-api';
|
|
2
|
-
import { IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
|
|
1
|
+
import type { Device } from '@antv/g-device-api';
|
|
2
|
+
import type { IModel, IModelDrawOptions, IModelInitializationOptions, IUniform } from '@antv/l7-core';
|
|
3
|
+
import type DeviceRendererService from '.';
|
|
3
4
|
export default class DeviceModel implements IModel {
|
|
4
5
|
private device;
|
|
5
6
|
private options;
|
|
7
|
+
private service;
|
|
6
8
|
private destroyed;
|
|
7
9
|
private uniforms;
|
|
8
10
|
private program;
|
|
@@ -11,14 +13,25 @@ export default class DeviceModel implements IModel {
|
|
|
11
13
|
private indexBuffer;
|
|
12
14
|
private vertexBuffers;
|
|
13
15
|
private bindings;
|
|
14
|
-
constructor(device: Device, options: IModelInitializationOptions);
|
|
16
|
+
constructor(device: Device, options: IModelInitializationOptions, service: DeviceRendererService);
|
|
15
17
|
private createPipeline;
|
|
16
18
|
updateAttributesAndElements(): void;
|
|
19
|
+
/**
|
|
20
|
+
* No need to implement this method, you should update data on `Attribute` like this:
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* attribute.updateBuffer({
|
|
25
|
+
* data: [],
|
|
26
|
+
* offset: 0,
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
17
30
|
updateAttributes(): void;
|
|
18
31
|
addUniforms(uniforms: {
|
|
19
32
|
[key: string]: IUniform;
|
|
20
33
|
}): void;
|
|
21
|
-
draw(options: IModelDrawOptions): void;
|
|
34
|
+
draw(options: IModelDrawOptions, pick?: boolean): void;
|
|
22
35
|
destroy(): void;
|
|
23
36
|
private initDepthDrawParams;
|
|
24
37
|
private getBlendDrawParams;
|
package/es/device/DeviceModel.js
CHANGED
|
@@ -5,11 +5,13 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
5
5
|
import { BlendFactor, BlendMode, ChannelWriteMask, CompareFunction, CullMode, Format, TransparentBlack, VertexStepMode } from '@antv/g-device-api';
|
|
6
6
|
import { gl } from '@antv/l7-core';
|
|
7
7
|
import { lodashUtil } from '@antv/l7-utils';
|
|
8
|
+
import DeviceFramebuffer from "./DeviceFramebuffer";
|
|
9
|
+
import DeviceTexture2D from "./DeviceTexture2D";
|
|
8
10
|
import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, sizeFormatMap } from "./constants";
|
|
9
11
|
var isPlainObject = lodashUtil.isPlainObject,
|
|
10
12
|
isTypedArray = lodashUtil.isTypedArray;
|
|
11
13
|
var DeviceModel = /*#__PURE__*/function () {
|
|
12
|
-
function DeviceModel(device, options) {
|
|
14
|
+
function DeviceModel(device, options, service) {
|
|
13
15
|
var _this = this;
|
|
14
16
|
_classCallCheck(this, DeviceModel);
|
|
15
17
|
_defineProperty(this, "destroyed", false);
|
|
@@ -17,6 +19,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
17
19
|
_defineProperty(this, "vertexBuffers", []);
|
|
18
20
|
this.device = device;
|
|
19
21
|
this.options = options;
|
|
22
|
+
this.service = service;
|
|
20
23
|
var vs = options.vs,
|
|
21
24
|
fs = options.fs,
|
|
22
25
|
attributes = options.attributes,
|
|
@@ -85,7 +88,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
85
88
|
}
|
|
86
89
|
_createClass(DeviceModel, [{
|
|
87
90
|
key: "createPipeline",
|
|
88
|
-
value: function createPipeline(options) {
|
|
91
|
+
value: function createPipeline(options, pick) {
|
|
89
92
|
var _options$primitive = options.primitive,
|
|
90
93
|
primitive = _options$primitive === void 0 ? gl.TRIANGLES : _options$primitive,
|
|
91
94
|
depth = options.depth,
|
|
@@ -99,6 +102,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
99
102
|
cull: cull
|
|
100
103
|
});
|
|
101
104
|
var cullEnabled = !!(cullParams && cullParams.enable);
|
|
105
|
+
// Disable blend when picking.
|
|
102
106
|
var blendParams = this.getBlendDrawParams({
|
|
103
107
|
blend: blend
|
|
104
108
|
});
|
|
@@ -110,7 +114,19 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
110
114
|
colorAttachmentFormats: [Format.U8_RGBA_RT],
|
|
111
115
|
depthStencilAttachmentFormat: Format.D24_S8,
|
|
112
116
|
megaStateDescriptor: {
|
|
113
|
-
attachmentsState: [{
|
|
117
|
+
attachmentsState: [pick ? {
|
|
118
|
+
channelWriteMask: ChannelWriteMask.ALL,
|
|
119
|
+
rgbBlendState: {
|
|
120
|
+
blendMode: BlendMode.ADD,
|
|
121
|
+
blendSrcFactor: BlendFactor.ONE,
|
|
122
|
+
blendDstFactor: BlendFactor.ZERO
|
|
123
|
+
},
|
|
124
|
+
alphaBlendState: {
|
|
125
|
+
blendMode: BlendMode.ADD,
|
|
126
|
+
blendSrcFactor: BlendFactor.ONE,
|
|
127
|
+
blendDstFactor: BlendFactor.ZERO
|
|
128
|
+
}
|
|
129
|
+
} : {
|
|
114
130
|
channelWriteMask: ChannelWriteMask.ALL,
|
|
115
131
|
rgbBlendState: {
|
|
116
132
|
blendMode: blendEnabled && blendParams.equation.rgb || BlendMode.ADD,
|
|
@@ -120,10 +136,10 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
120
136
|
alphaBlendState: {
|
|
121
137
|
blendMode: blendEnabled && blendParams.equation.alpha || BlendMode.ADD,
|
|
122
138
|
blendSrcFactor: blendEnabled && blendParams.func.srcAlpha || BlendFactor.ONE,
|
|
123
|
-
blendDstFactor: blendEnabled && blendParams.func.dstAlpha || BlendFactor.
|
|
139
|
+
blendDstFactor: blendEnabled && blendParams.func.dstAlpha || BlendFactor.ONE
|
|
124
140
|
}
|
|
125
141
|
}],
|
|
126
|
-
blendConstant: TransparentBlack,
|
|
142
|
+
blendConstant: blendEnabled ? TransparentBlack : undefined,
|
|
127
143
|
depthWrite: depthEnabled,
|
|
128
144
|
depthCompare: depthEnabled && depthParams.func || CompareFunction.LESS,
|
|
129
145
|
cullMode: cullEnabled && cullParams.face || CullMode.NONE,
|
|
@@ -133,20 +149,22 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
133
149
|
}
|
|
134
150
|
}, {
|
|
135
151
|
key: "updateAttributesAndElements",
|
|
136
|
-
value: function updateAttributesAndElements()
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
152
|
+
value: function updateAttributesAndElements() {}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* No need to implement this method, you should update data on `Attribute` like this:
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```ts
|
|
159
|
+
* attribute.updateBuffer({
|
|
160
|
+
* data: [],
|
|
161
|
+
* offset: 0,
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
141
165
|
}, {
|
|
142
166
|
key: "updateAttributes",
|
|
143
|
-
value: function updateAttributes() {
|
|
144
|
-
// TODO: implement
|
|
145
|
-
// Object.keys(attributes).forEach((name: string) => {
|
|
146
|
-
// const attribute = attributes[name] as DeviceAttribute;
|
|
147
|
-
// attribute.updateBuffer();
|
|
148
|
-
// });
|
|
149
|
-
}
|
|
167
|
+
value: function updateAttributes() {}
|
|
150
168
|
}, {
|
|
151
169
|
key: "addUniforms",
|
|
152
170
|
value: function addUniforms(uniforms) {
|
|
@@ -154,11 +172,13 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
154
172
|
}
|
|
155
173
|
}, {
|
|
156
174
|
key: "draw",
|
|
157
|
-
value: function draw(options
|
|
158
|
-
|
|
159
|
-
) {
|
|
175
|
+
value: function draw(options, pick) {
|
|
176
|
+
var _this2 = this;
|
|
160
177
|
var mergedOptions = _objectSpread(_objectSpread({}, this.options), options);
|
|
161
|
-
var _mergedOptions$
|
|
178
|
+
var _mergedOptions$depth = mergedOptions.depth,
|
|
179
|
+
_mergedOptions$depth2 = _mergedOptions$depth === void 0 ? {} : _mergedOptions$depth,
|
|
180
|
+
depthEnabled = _mergedOptions$depth2.enable,
|
|
181
|
+
_mergedOptions$count = mergedOptions.count,
|
|
162
182
|
count = _mergedOptions$count === void 0 ? 0 : _mergedOptions$count,
|
|
163
183
|
instances = mergedOptions.instances,
|
|
164
184
|
elements = mergedOptions.elements,
|
|
@@ -167,20 +187,15 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
167
187
|
uniformBuffers = mergedOptions.uniformBuffers,
|
|
168
188
|
textures = mergedOptions.textures;
|
|
169
189
|
this.uniforms = _objectSpread(_objectSpread({}, this.uniforms), this.extractUniforms(uniforms));
|
|
190
|
+
var _this$service = this.service,
|
|
191
|
+
renderPass = _this$service.renderPass,
|
|
192
|
+
currentFramebuffer = _this$service.currentFramebuffer,
|
|
193
|
+
width = _this$service.width,
|
|
194
|
+
height = _this$service.height;
|
|
170
195
|
|
|
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
196
|
// TODO: Recreate pipeline only when blend / cull changed.
|
|
183
|
-
this.pipeline = this.createPipeline(mergedOptions);
|
|
197
|
+
this.pipeline = this.createPipeline(mergedOptions, pick);
|
|
198
|
+
renderPass.setViewport(0, 0, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['width']) || width, (currentFramebuffer === null || currentFramebuffer === void 0 ? void 0 : currentFramebuffer['height']) || height);
|
|
184
199
|
renderPass.setPipeline(this.pipeline);
|
|
185
200
|
renderPass.setVertexInput(this.inputLayout, this.vertexBuffers.map(function (buffer) {
|
|
186
201
|
return {
|
|
@@ -188,9 +203,8 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
188
203
|
};
|
|
189
204
|
}), elements ? {
|
|
190
205
|
buffer: this.indexBuffer,
|
|
191
|
-
offset: 0
|
|
206
|
+
offset: 0
|
|
192
207
|
} : null);
|
|
193
|
-
renderPass.setViewport(0, 0, width, height);
|
|
194
208
|
if (uniformBuffers) {
|
|
195
209
|
this.bindings = this.device.createBindings({
|
|
196
210
|
pipeline: this.pipeline,
|
|
@@ -213,6 +227,16 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
213
227
|
if (this.bindings) {
|
|
214
228
|
renderPass.setBindings(this.bindings);
|
|
215
229
|
// Compatible to WebGL1.
|
|
230
|
+
Object.keys(this.uniforms).forEach(function (uniformName) {
|
|
231
|
+
var uniform = _this2.uniforms[uniformName];
|
|
232
|
+
if (uniform instanceof DeviceTexture2D) {
|
|
233
|
+
// @ts-ignore
|
|
234
|
+
_this2.uniforms[uniformName] = uniform.get();
|
|
235
|
+
} else if (uniform instanceof DeviceFramebuffer) {
|
|
236
|
+
// @ts-ignore
|
|
237
|
+
_this2.uniforms[uniformName] = uniform.get()['texture'];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
216
240
|
this.program.setUniformsLegacy(this.uniforms);
|
|
217
241
|
}
|
|
218
242
|
if (elements) {
|
|
@@ -363,17 +387,17 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
363
387
|
}, {
|
|
364
388
|
key: "extractUniforms",
|
|
365
389
|
value: function extractUniforms(uniforms) {
|
|
366
|
-
var
|
|
390
|
+
var _this3 = this;
|
|
367
391
|
var extractedUniforms = {};
|
|
368
392
|
Object.keys(uniforms).forEach(function (uniformName) {
|
|
369
|
-
|
|
393
|
+
_this3.extractUniformsRecursively(uniformName, uniforms[uniformName], extractedUniforms, '');
|
|
370
394
|
});
|
|
371
395
|
return extractedUniforms;
|
|
372
396
|
}
|
|
373
397
|
}, {
|
|
374
398
|
key: "extractUniformsRecursively",
|
|
375
399
|
value: function extractUniformsRecursively(uniformName, uniformValue, uniforms, prefix) {
|
|
376
|
-
var
|
|
400
|
+
var _this4 = this;
|
|
377
401
|
if (uniformValue === null || typeof uniformValue === 'number' ||
|
|
378
402
|
// u_A: 1
|
|
379
403
|
typeof uniformValue === 'boolean' ||
|
|
@@ -391,7 +415,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
391
415
|
// u_Struct.a.b.c
|
|
392
416
|
if (isPlainObject(uniformValue)) {
|
|
393
417
|
Object.keys(uniformValue).forEach(function (childName) {
|
|
394
|
-
|
|
418
|
+
_this4.extractUniformsRecursively(childName,
|
|
395
419
|
// @ts-ignore
|
|
396
420
|
uniformValue[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName));
|
|
397
421
|
});
|
|
@@ -401,7 +425,7 @@ var DeviceModel = /*#__PURE__*/function () {
|
|
|
401
425
|
if (Array.isArray(uniformValue)) {
|
|
402
426
|
uniformValue.forEach(function (child, idx) {
|
|
403
427
|
Object.keys(child).forEach(function (childName) {
|
|
404
|
-
|
|
428
|
+
_this4.extractUniformsRecursively(childName,
|
|
405
429
|
// @ts-ignore
|
|
406
430
|
child[childName], uniforms, "".concat(prefix && prefix + '.').concat(uniformName, "[").concat(idx, "]"));
|
|
407
431
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Device, Texture } from '@antv/g-device-api';
|
|
2
|
-
import { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
1
|
+
import type { Device, Texture } from '@antv/g-device-api';
|
|
2
|
+
import type { ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
3
3
|
export declare function isTexture2D(t: any): t is ITexture2D;
|
|
4
4
|
export default class DeviceTexture2D implements ITexture2D {
|
|
5
5
|
private texture;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
-
import { FilterMode, Format, MipmapFilterMode
|
|
5
|
-
import { gl } from '@antv/l7-core';
|
|
4
|
+
import { TextureUsage as DeviceTextureUsage, FilterMode, Format, MipmapFilterMode } from '@antv/g-device-api';
|
|
5
|
+
import { TextureUsage, gl } from '@antv/l7-core';
|
|
6
6
|
import { wrapModeMap } from "./constants";
|
|
7
7
|
export function isTexture2D(t) {
|
|
8
|
-
return
|
|
8
|
+
return !!(t && t['texture']);
|
|
9
9
|
}
|
|
10
10
|
var DeviceTexture2D = /*#__PURE__*/function () {
|
|
11
11
|
function DeviceTexture2D(device, options) {
|
|
@@ -24,36 +24,40 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
24
24
|
wrapS = _options$wrapS === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapS,
|
|
25
25
|
_options$wrapT = options.wrapT,
|
|
26
26
|
wrapT = _options$wrapT === void 0 ? gl.CLAMP_TO_EDGE : _options$wrapT,
|
|
27
|
+
_options$aniso = options.aniso,
|
|
28
|
+
aniso = _options$aniso === void 0 ? 0 : _options$aniso,
|
|
27
29
|
_options$alignment = options.alignment,
|
|
28
|
-
alignment = _options$alignment === void 0 ? 1 : _options$alignment
|
|
30
|
+
alignment = _options$alignment === void 0 ? 1 : _options$alignment,
|
|
31
|
+
_options$usage = options.usage,
|
|
32
|
+
usage = _options$usage === void 0 ? TextureUsage.SAMPLED : _options$usage,
|
|
33
|
+
_options$mipmap = options.mipmap,
|
|
34
|
+
mipmap = _options$mipmap === void 0 ? false : _options$mipmap,
|
|
35
|
+
_options$mag = options.mag,
|
|
36
|
+
mag = _options$mag === void 0 ? gl.NEAREST : _options$mag,
|
|
37
|
+
_options$min = options.min,
|
|
38
|
+
min = _options$min === void 0 ? gl.NEAREST : _options$min;
|
|
29
39
|
this.width = width;
|
|
30
40
|
this.height = height;
|
|
31
41
|
var pixelFormat = Format.U8_RGBA_RT;
|
|
32
42
|
if (type === gl.UNSIGNED_BYTE && format === gl.RGBA) {
|
|
33
43
|
pixelFormat = Format.U8_RGBA_RT;
|
|
34
|
-
} else if (
|
|
35
|
-
pixelFormat = Format.F32_LUMINANCE;
|
|
36
|
-
} else if (format === gl.LUMINANCE && type === gl.UNSIGNED_BYTE) {
|
|
44
|
+
} else if (type === gl.UNSIGNED_BYTE && format === gl.LUMINANCE) {
|
|
37
45
|
pixelFormat = Format.U8_LUMINANCE;
|
|
46
|
+
} else if (type === gl.FLOAT && format === gl.RGB) {
|
|
47
|
+
pixelFormat = Format.F32_RGB;
|
|
38
48
|
} else {
|
|
39
49
|
throw new Error("create texture error, type: ".concat(type, ", format: ").concat(format));
|
|
40
50
|
}
|
|
41
|
-
|
|
42
|
-
// // copy pixels from current bind framebuffer
|
|
43
|
-
// x,
|
|
44
|
-
// y,
|
|
45
|
-
// copy,
|
|
46
|
-
// };
|
|
47
|
-
|
|
48
51
|
this.texture = device.createTexture({
|
|
49
52
|
format: pixelFormat,
|
|
50
53
|
width: width,
|
|
51
54
|
height: height,
|
|
52
|
-
usage: TextureUsage.SAMPLED,
|
|
55
|
+
usage: usage === TextureUsage.SAMPLED ? DeviceTextureUsage.SAMPLED : DeviceTextureUsage.RENDER_TARGET,
|
|
53
56
|
pixelStore: {
|
|
54
57
|
unpackFlipY: flipY,
|
|
55
58
|
packAlignment: alignment
|
|
56
|
-
}
|
|
59
|
+
},
|
|
60
|
+
mipLevelCount: usage === TextureUsage.RENDER_TARGET ? 1 : mipmap ? 1 : 0
|
|
57
61
|
});
|
|
58
62
|
if (data) {
|
|
59
63
|
// @ts-ignore
|
|
@@ -62,13 +66,12 @@ var DeviceTexture2D = /*#__PURE__*/function () {
|
|
|
62
66
|
this.sampler = device.createSampler({
|
|
63
67
|
addressModeU: wrapModeMap[wrapS],
|
|
64
68
|
addressModeV: wrapModeMap[wrapT],
|
|
65
|
-
minFilter: FilterMode.POINT,
|
|
66
|
-
|
|
67
|
-
magFilter: FilterMode.BILINEAR,
|
|
69
|
+
minFilter: min === gl.NEAREST ? FilterMode.POINT : FilterMode.BILINEAR,
|
|
70
|
+
magFilter: mag === gl.NEAREST ? FilterMode.POINT : FilterMode.BILINEAR,
|
|
68
71
|
mipmapFilter: MipmapFilterMode.NO_MIP,
|
|
69
|
-
lodMinClamp: 0,
|
|
70
|
-
lodMaxClamp: 0
|
|
71
|
-
|
|
72
|
+
// lodMinClamp: 0,
|
|
73
|
+
// lodMaxClamp: 0,
|
|
74
|
+
maxAnisotropy: aniso
|
|
72
75
|
});
|
|
73
76
|
}
|
|
74
77
|
_createClass(DeviceTexture2D, [{
|
package/es/device/constants.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AddressMode, BlendFactor, BlendMode, BufferFrequencyHint, CompareFunction, CullMode, Format, PrimitiveTopology } from '@antv/g-device-api';
|
|
2
|
-
import { TypedArray } from './utils/typedarray';
|
|
2
|
+
import type { TypedArray } from './utils/typedarray';
|
|
3
3
|
export declare const typedArrayCtorMap: {
|
|
4
4
|
[key: string]: new (data: number[]) => TypedArray;
|
|
5
5
|
};
|
package/es/device/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { RenderPass, RenderTarget, SwapChain } from '@antv/g-device-api';
|
|
2
|
+
import type { IAttribute, IAttributeInitializationOptions, IBuffer, IBufferInitializationOptions, IClearOptions, IElements, IElementsInitializationOptions, IExtensions, IFramebuffer, IFramebufferInitializationOptions, IModel, IModelInitializationOptions, IReadPixelsOptions, IRenderConfig, IRendererService, ITexture2D, ITexture2DInitializationOptions } from '@antv/l7-core';
|
|
2
3
|
import 'reflect-metadata';
|
|
3
4
|
import DeviceFramebuffer from './DeviceFramebuffer';
|
|
4
5
|
/**
|
|
@@ -8,15 +9,22 @@ export default class DeviceRendererService implements IRendererService {
|
|
|
8
9
|
uniformBuffers: IBuffer[];
|
|
9
10
|
extensionObject: IExtensions;
|
|
10
11
|
private device;
|
|
11
|
-
|
|
12
|
+
swapChain: SwapChain;
|
|
12
13
|
private $container;
|
|
13
14
|
private canvas;
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
16
17
|
private isDirty;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Current render pass.
|
|
20
|
+
*/
|
|
21
|
+
renderPass: RenderPass;
|
|
22
|
+
mainColorRT: RenderTarget;
|
|
23
|
+
mainDepthRT: RenderTarget;
|
|
24
|
+
/**
|
|
25
|
+
* Current FBO.
|
|
26
|
+
*/
|
|
27
|
+
currentFramebuffer: DeviceFramebuffer | null;
|
|
20
28
|
init(canvas: HTMLCanvasElement, cfg: IRenderConfig): Promise<void>;
|
|
21
29
|
beginFrame(): void;
|
|
22
30
|
endFrame(): void;
|
|
@@ -28,18 +36,18 @@ export default class DeviceRendererService implements IRendererService {
|
|
|
28
36
|
createElements: (options: IElementsInitializationOptions) => IElements;
|
|
29
37
|
createTexture2D: (options: ITexture2DInitializationOptions) => ITexture2D;
|
|
30
38
|
createFramebuffer: (options: IFramebufferInitializationOptions) => DeviceFramebuffer;
|
|
31
|
-
useFramebuffer: () => void;
|
|
32
|
-
clear: () => void;
|
|
39
|
+
useFramebuffer: (framebuffer: IFramebuffer | null, drawCommands: () => void) => void;
|
|
40
|
+
clear: (options: IClearOptions) => void;
|
|
33
41
|
viewport: ({ width, height, }: {
|
|
34
42
|
x: number;
|
|
35
43
|
y: number;
|
|
36
44
|
width: number;
|
|
37
45
|
height: number;
|
|
38
46
|
}) => void;
|
|
39
|
-
readPixels: () => Uint8Array;
|
|
47
|
+
readPixels: (options: IReadPixelsOptions) => Uint8Array;
|
|
40
48
|
getViewportSize: () => {
|
|
41
|
-
width:
|
|
42
|
-
height:
|
|
49
|
+
width: number;
|
|
50
|
+
height: number;
|
|
43
51
|
};
|
|
44
52
|
getContainer: () => HTMLElement | null;
|
|
45
53
|
getCanvas: () => HTMLCanvasElement;
|