@antv/l7-renderer 2.19.10 → 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,319 @@
|
|
|
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
|
+
import { Format, TextureUsage, TransparentBlack, WebGLDeviceContribution, WebGPUDeviceContribution } from '@antv/g-device-api';
|
|
8
|
+
import { injectable } from 'inversify';
|
|
9
|
+
import 'reflect-metadata';
|
|
10
|
+
import DeviceAttribute from "./DeviceAttribute";
|
|
11
|
+
import DeviceBuffer from "./DeviceBuffer";
|
|
12
|
+
import DeviceElements from "./DeviceElements";
|
|
13
|
+
import DeviceFramebuffer from "./DeviceFramebuffer";
|
|
14
|
+
import DeviceModel from "./DeviceModel";
|
|
15
|
+
import DeviceTexture2D from "./DeviceTexture2D";
|
|
16
|
+
import { isWebGL2 } from "./utils/webgl";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Device API renderer
|
|
20
|
+
*/
|
|
21
|
+
var DeviceRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/function () {
|
|
22
|
+
function DeviceRendererService() {
|
|
23
|
+
var _this = this;
|
|
24
|
+
_classCallCheck(this, DeviceRendererService);
|
|
25
|
+
_defineProperty(this, "uniformBuffers", []);
|
|
26
|
+
_defineProperty(this, "createModel", function (options) {
|
|
27
|
+
return new DeviceModel(_this.device, options);
|
|
28
|
+
});
|
|
29
|
+
_defineProperty(this, "createAttribute", function (options) {
|
|
30
|
+
return new DeviceAttribute(_this.device, options);
|
|
31
|
+
});
|
|
32
|
+
_defineProperty(this, "createBuffer", function (options) {
|
|
33
|
+
return new DeviceBuffer(_this.device, options);
|
|
34
|
+
});
|
|
35
|
+
_defineProperty(this, "createElements", function (options) {
|
|
36
|
+
return new DeviceElements(_this.device, options);
|
|
37
|
+
});
|
|
38
|
+
_defineProperty(this, "createTexture2D", function (options) {
|
|
39
|
+
return new DeviceTexture2D(_this.device, options);
|
|
40
|
+
});
|
|
41
|
+
_defineProperty(this, "createFramebuffer", function (options) {
|
|
42
|
+
return new DeviceFramebuffer(_this.device, options);
|
|
43
|
+
});
|
|
44
|
+
_defineProperty(this, "useFramebuffer", function ()
|
|
45
|
+
// framebuffer: IFramebuffer | null,
|
|
46
|
+
// drawCommands: () => void,
|
|
47
|
+
{
|
|
48
|
+
// if (framebuffer == null) {
|
|
49
|
+
// // @ts-ignore
|
|
50
|
+
// this.device.currentFramebuffer = this.device.onscreenFramebuffer;
|
|
51
|
+
// } else {
|
|
52
|
+
// // @ts-ignore
|
|
53
|
+
// this.device.currentFramebuffer = framebuffer;
|
|
54
|
+
// }
|
|
55
|
+
// drawCommands();
|
|
56
|
+
});
|
|
57
|
+
_defineProperty(this, "clear", function ()
|
|
58
|
+
// options: IClearOptions
|
|
59
|
+
{
|
|
60
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
|
|
61
|
+
// const { color, depth, stencil, framebuffer = null } = options;
|
|
62
|
+
// const reglClearOptions: regl.ClearOptions = {
|
|
63
|
+
// color,
|
|
64
|
+
// depth,
|
|
65
|
+
// stencil,
|
|
66
|
+
// };
|
|
67
|
+
// reglClearOptions.framebuffer =
|
|
68
|
+
// framebuffer === null
|
|
69
|
+
// ? framebuffer
|
|
70
|
+
// : (framebuffer as DeviceFramebuffer).get();
|
|
71
|
+
// this.gl?.clear(reglClearOptions);
|
|
72
|
+
// TODO: clear
|
|
73
|
+
});
|
|
74
|
+
_defineProperty(this, "viewport", function (_ref) {
|
|
75
|
+
var width = _ref.width,
|
|
76
|
+
height = _ref.height;
|
|
77
|
+
// use WebGL context directly
|
|
78
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#unsafe-escape-hatch
|
|
79
|
+
// this.gl._gl.viewport(x, y, width, height);
|
|
80
|
+
_this.width = width;
|
|
81
|
+
_this.height = height;
|
|
82
|
+
// Will be used in `setViewport` from RenderPass later.
|
|
83
|
+
// @ts-ignore
|
|
84
|
+
_this.device.width = width;
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
_this.device.height = height;
|
|
87
|
+
|
|
88
|
+
// this.gl._refresh();
|
|
89
|
+
});
|
|
90
|
+
_defineProperty(this, "readPixels", function ()
|
|
91
|
+
// options: IReadPixelsOptions
|
|
92
|
+
{
|
|
93
|
+
// const { framebuffer, x, y, width, height } = options;
|
|
94
|
+
|
|
95
|
+
// const readback = this.device.createReadback();
|
|
96
|
+
|
|
97
|
+
// if (framebuffer) {
|
|
98
|
+
// readPixelsOptions.framebuffer = (framebuffer as DeviceFramebuffer).get();
|
|
99
|
+
// }
|
|
100
|
+
// return readback.readTextureSync(null, x, y, width, height, new Uint8Array()) as Uint8Array;
|
|
101
|
+
return new Uint8Array();
|
|
102
|
+
});
|
|
103
|
+
_defineProperty(this, "getViewportSize", function () {
|
|
104
|
+
// FIXME: add viewport size in Device API.
|
|
105
|
+
return {
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
width: _this.device.width,
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
height: _this.device.height
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
_defineProperty(this, "getContainer", function () {
|
|
113
|
+
var _this$canvas;
|
|
114
|
+
return (_this$canvas = _this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.parentElement;
|
|
115
|
+
});
|
|
116
|
+
_defineProperty(this, "getCanvas", function () {
|
|
117
|
+
// return this.$container?.getElementsByTagName('canvas')[0] || null;
|
|
118
|
+
return _this.canvas;
|
|
119
|
+
});
|
|
120
|
+
_defineProperty(this, "getGLContext", function () {
|
|
121
|
+
// @ts-ignore
|
|
122
|
+
return _this.device['gl'];
|
|
123
|
+
});
|
|
124
|
+
_defineProperty(this, "destroy", function () {
|
|
125
|
+
var _this$uniformBuffers;
|
|
126
|
+
// this.canvas = null 清除对 webgl 实例的引用
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
_this.canvas = null;
|
|
129
|
+
(_this$uniformBuffers = _this.uniformBuffers) === null || _this$uniformBuffers === void 0 || _this$uniformBuffers.forEach(function (buffer) {
|
|
130
|
+
buffer.destroy();
|
|
131
|
+
});
|
|
132
|
+
_this.device.destroy();
|
|
133
|
+
|
|
134
|
+
// make sure release webgl context
|
|
135
|
+
// this.gl?._gl?.getExtension('WEBGL_lose_context')?.loseContext();
|
|
136
|
+
|
|
137
|
+
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clean-up
|
|
138
|
+
// this.gl.destroy();
|
|
139
|
+
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
// this.gl = null;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
_createClass(DeviceRendererService, [{
|
|
145
|
+
key: "init",
|
|
146
|
+
value: function () {
|
|
147
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(canvas, cfg) {
|
|
148
|
+
var enableWebGPU, shaderCompilerPath, deviceContribution, swapChain, gl, renderTargetTexture;
|
|
149
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
150
|
+
while (1) switch (_context.prev = _context.next) {
|
|
151
|
+
case 0:
|
|
152
|
+
enableWebGPU = cfg.enableWebGPU, shaderCompilerPath = cfg.shaderCompilerPath; // this.$container = $container;
|
|
153
|
+
this.canvas = canvas;
|
|
154
|
+
|
|
155
|
+
// TODO: use antialias from cfg
|
|
156
|
+
deviceContribution = enableWebGPU ? new WebGPUDeviceContribution({
|
|
157
|
+
shaderCompilerPath: shaderCompilerPath
|
|
158
|
+
}) : new WebGLDeviceContribution({
|
|
159
|
+
// Use WebGL2 first and downgrade to WebGL1 if WebGL2 is not supported.
|
|
160
|
+
targets: ['webgl2', 'webgl1'],
|
|
161
|
+
onContextLost: function onContextLost(e) {
|
|
162
|
+
console.warn('context lost', e);
|
|
163
|
+
},
|
|
164
|
+
onContextCreationError: function onContextCreationError(e) {
|
|
165
|
+
console.warn('context creation error', e);
|
|
166
|
+
},
|
|
167
|
+
onContextRestored: function onContextRestored(e) {
|
|
168
|
+
console.warn('context restored', e);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
_context.next = 5;
|
|
172
|
+
return deviceContribution.createSwapChain(canvas);
|
|
173
|
+
case 5:
|
|
174
|
+
swapChain = _context.sent;
|
|
175
|
+
swapChain.configureSwapChain(canvas.width, canvas.height);
|
|
176
|
+
this.device = swapChain.getDevice();
|
|
177
|
+
this.swapChain = swapChain;
|
|
178
|
+
|
|
179
|
+
// Create default RT
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
// this.device.onscreenFramebuffer = this.createFramebuffer({
|
|
182
|
+
// width: canvas.width,
|
|
183
|
+
// height: canvas.height,
|
|
184
|
+
// });
|
|
185
|
+
// // @ts-ignore
|
|
186
|
+
// this.device.onscreenFramebuffer.onscreen = true;
|
|
187
|
+
// // @ts-ignore
|
|
188
|
+
// this.device.currentFramebuffer = this.device.onscreenFramebuffer;
|
|
189
|
+
|
|
190
|
+
// @ts-ignore
|
|
191
|
+
gl = this.device['gl'];
|
|
192
|
+
this.extensionObject = {
|
|
193
|
+
// @ts-ignore
|
|
194
|
+
OES_texture_float: !isWebGL2(gl) && this.device['OES_texture_float']
|
|
195
|
+
};
|
|
196
|
+
renderTargetTexture = this.device.createTexture({
|
|
197
|
+
format: Format.U8_RGBA_RT,
|
|
198
|
+
width: canvas.width,
|
|
199
|
+
height: canvas.height,
|
|
200
|
+
usage: TextureUsage.RENDER_TARGET
|
|
201
|
+
});
|
|
202
|
+
this.renderTarget = this.device.createRenderTargetFromTexture(renderTargetTexture);
|
|
203
|
+
this.mainDepthRT = this.device.createRenderTargetFromTexture(this.device.createTexture({
|
|
204
|
+
format: Format.D24_S8,
|
|
205
|
+
width: canvas.width,
|
|
206
|
+
height: canvas.height,
|
|
207
|
+
usage: TextureUsage.RENDER_TARGET
|
|
208
|
+
}));
|
|
209
|
+
case 14:
|
|
210
|
+
case "end":
|
|
211
|
+
return _context.stop();
|
|
212
|
+
}
|
|
213
|
+
}, _callee, this);
|
|
214
|
+
}));
|
|
215
|
+
function init(_x, _x2) {
|
|
216
|
+
return _init.apply(this, arguments);
|
|
217
|
+
}
|
|
218
|
+
return init;
|
|
219
|
+
}()
|
|
220
|
+
}, {
|
|
221
|
+
key: "beginFrame",
|
|
222
|
+
value: function beginFrame() {
|
|
223
|
+
var onscreenTexture = this.swapChain.getOnscreenTexture();
|
|
224
|
+
this.renderPass = this.device.createRenderPass({
|
|
225
|
+
colorAttachment: [this.renderTarget],
|
|
226
|
+
// colorResolveTo: [onscreen ? onscreenTexture : onscreenTexture],
|
|
227
|
+
colorResolveTo: [onscreenTexture],
|
|
228
|
+
colorClearColor: [TransparentBlack],
|
|
229
|
+
depthStencilAttachment: this.mainDepthRT,
|
|
230
|
+
depthClearValue: 1
|
|
231
|
+
});
|
|
232
|
+
// @ts-ignore
|
|
233
|
+
this.device.renderPass = this.renderPass;
|
|
234
|
+
}
|
|
235
|
+
}, {
|
|
236
|
+
key: "endFrame",
|
|
237
|
+
value: function endFrame() {
|
|
238
|
+
this.device.submitPass(this.renderPass);
|
|
239
|
+
}
|
|
240
|
+
}, {
|
|
241
|
+
key: "getPointSizeRange",
|
|
242
|
+
value: function getPointSizeRange() {
|
|
243
|
+
// @ts-ignore
|
|
244
|
+
var gl = this.device['gl'];
|
|
245
|
+
// FIXME: implement this method in Device API.
|
|
246
|
+
return gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE);
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "testExtension",
|
|
250
|
+
value: function testExtension(name) {
|
|
251
|
+
// OES_texture_float
|
|
252
|
+
return !!this.getGLContext().getExtension(name);
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "setState",
|
|
256
|
+
value:
|
|
257
|
+
// TODO: 临时方法
|
|
258
|
+
function setState() {
|
|
259
|
+
// this.gl({
|
|
260
|
+
// cull: {
|
|
261
|
+
// enable: false,
|
|
262
|
+
// face: 'back',
|
|
263
|
+
// },
|
|
264
|
+
// viewport: {
|
|
265
|
+
// x: 0,
|
|
266
|
+
// y: 0,
|
|
267
|
+
// height: this.width,
|
|
268
|
+
// width: this.height,
|
|
269
|
+
// },
|
|
270
|
+
// blend: {
|
|
271
|
+
// enable: true,
|
|
272
|
+
// equation: 'add',
|
|
273
|
+
// },
|
|
274
|
+
// framebuffer: null,
|
|
275
|
+
// });
|
|
276
|
+
// this.gl._refresh();
|
|
277
|
+
}
|
|
278
|
+
}, {
|
|
279
|
+
key: "setBaseState",
|
|
280
|
+
value: function setBaseState() {
|
|
281
|
+
// this.gl({
|
|
282
|
+
// cull: {
|
|
283
|
+
// enable: false,
|
|
284
|
+
// face: 'back',
|
|
285
|
+
// },
|
|
286
|
+
// viewport: {
|
|
287
|
+
// x: 0,
|
|
288
|
+
// y: 0,
|
|
289
|
+
// height: this.width,
|
|
290
|
+
// width: this.height,
|
|
291
|
+
// },
|
|
292
|
+
// blend: {
|
|
293
|
+
// enable: false,
|
|
294
|
+
// equation: 'add',
|
|
295
|
+
// },
|
|
296
|
+
// framebuffer: null,
|
|
297
|
+
// });
|
|
298
|
+
// this.gl._refresh();
|
|
299
|
+
}
|
|
300
|
+
}, {
|
|
301
|
+
key: "setCustomLayerDefaults",
|
|
302
|
+
value: function setCustomLayerDefaults() {
|
|
303
|
+
// const gl = this.getGLContext();
|
|
304
|
+
// gl.disable(gl.CULL_FACE);
|
|
305
|
+
}
|
|
306
|
+
}, {
|
|
307
|
+
key: "setDirty",
|
|
308
|
+
value: function setDirty(flag) {
|
|
309
|
+
this.isDirty = flag;
|
|
310
|
+
}
|
|
311
|
+
}, {
|
|
312
|
+
key: "getDirty",
|
|
313
|
+
value: function getDirty() {
|
|
314
|
+
return this.isDirty;
|
|
315
|
+
}
|
|
316
|
+
}]);
|
|
317
|
+
return DeviceRendererService;
|
|
318
|
+
}()) || _class);
|
|
319
|
+
export { DeviceRendererService as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function pipelineEquals(): void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function pipelineEquals() {}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var dtypes = {
|
|
2
|
+
'[object Int8Array]': 5120,
|
|
3
|
+
'[object Int16Array]': 5122,
|
|
4
|
+
'[object Int32Array]': 5124,
|
|
5
|
+
'[object Uint8Array]': 5121,
|
|
6
|
+
'[object Uint8ClampedArray]': 5121,
|
|
7
|
+
'[object Uint16Array]': 5123,
|
|
8
|
+
'[object Uint32Array]': 5125,
|
|
9
|
+
'[object Float32Array]': 5126,
|
|
10
|
+
'[object Float64Array]': 5121,
|
|
11
|
+
'[object ArrayBuffer]': 5121
|
|
12
|
+
};
|
|
13
|
+
// eslint-disable-next-line
|
|
14
|
+
export function isTypedArray(x) {
|
|
15
|
+
return Object.prototype.toString.call(x) in dtypes;
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isWebGL2(gl: WebGL2RenderingContext | WebGLRenderingContext): gl is WebGL2RenderingContext;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @see https://github.com/visgl/luma.gl/blob/30a1039573576d73641de7c1ba222e8992eb526e/modules/gltools/src/utils/webgl-checks.ts#L22
|
|
2
|
+
export function isWebGL2(gl) {
|
|
3
|
+
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
|
|
4
|
+
return true;
|
|
5
|
+
}
|
|
6
|
+
// Look for debug contexts, headless gl etc
|
|
7
|
+
// @ts-ignore
|
|
8
|
+
return Boolean(gl && gl._version === 2);
|
|
9
|
+
}
|
package/es/index.d.ts
CHANGED
package/es/index.js
CHANGED
package/es/regl/ReglModel.js
CHANGED
|
@@ -3,7 +3,8 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
3
3
|
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
4
|
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
5
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
-
import {
|
|
6
|
+
import { ClipSpaceNearZ, preprocessShader_GLSL, ViewportOrigin } from '@antv/g-device-api';
|
|
7
|
+
import { gl, removeDuplicateUniforms } from '@antv/l7-core';
|
|
7
8
|
import { lodashUtil } from '@antv/l7-utils';
|
|
8
9
|
import { blendEquationMap, blendFuncMap, cullFaceMap, depthFuncMap, primitiveMap, stencilFuncMap, stencilOpMap } from "./constants";
|
|
9
10
|
var isPlainObject = lodashUtil.isPlainObject,
|
|
@@ -28,6 +29,19 @@ var ReglModel = /*#__PURE__*/function () {
|
|
|
28
29
|
depth = options.depth,
|
|
29
30
|
cull = options.cull,
|
|
30
31
|
instances = options.instances;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* try to compile GLSL 300 to 100
|
|
35
|
+
*/
|
|
36
|
+
var vendorInfo = {
|
|
37
|
+
platformString: 'WebGL1',
|
|
38
|
+
glslVersion: '#version 100',
|
|
39
|
+
explicitBindingLocations: false,
|
|
40
|
+
separateSamplerTextures: false,
|
|
41
|
+
viewportOrigin: ViewportOrigin.LOWER_LEFT,
|
|
42
|
+
clipSpaceNearZ: ClipSpaceNearZ.NEGATIVE_ONE,
|
|
43
|
+
supportMRT: false
|
|
44
|
+
};
|
|
31
45
|
var reglUniforms = {};
|
|
32
46
|
this.options = options;
|
|
33
47
|
if (uniforms) {
|
|
@@ -44,9 +58,9 @@ var ReglModel = /*#__PURE__*/function () {
|
|
|
44
58
|
});
|
|
45
59
|
var drawParams = {
|
|
46
60
|
attributes: reglAttributes,
|
|
47
|
-
frag: fs,
|
|
61
|
+
frag: removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'frag', fs, null, false)),
|
|
48
62
|
uniforms: reglUniforms,
|
|
49
|
-
vert: vs,
|
|
63
|
+
vert: removeDuplicateUniforms(preprocessShader_GLSL(vendorInfo, 'vert', vs, null, false)),
|
|
50
64
|
// @ts-ignore
|
|
51
65
|
colorMask: reGl.prop('colorMask'),
|
|
52
66
|
lineWidth: 1,
|
|
@@ -162,13 +176,13 @@ var ReglModel = /*#__PURE__*/function () {
|
|
|
162
176
|
}, {
|
|
163
177
|
key: "destroy",
|
|
164
178
|
value: function destroy() {
|
|
165
|
-
var _this$drawParams
|
|
179
|
+
var _this$drawParams;
|
|
166
180
|
// @ts-ignore
|
|
167
|
-
(_this$drawParams = this.drawParams) === null || _this$drawParams === void 0
|
|
181
|
+
(_this$drawParams = this.drawParams) === null || _this$drawParams === void 0 || (_this$drawParams = _this$drawParams.elements) === null || _this$drawParams === void 0 || _this$drawParams.destroy();
|
|
168
182
|
if (this.options.attributes) {
|
|
169
183
|
Object.values(this.options.attributes).forEach(function (attr) {
|
|
170
184
|
// @ts-ignore
|
|
171
|
-
attr === null || attr === void 0
|
|
185
|
+
attr === null || attr === void 0 || attr.destroy();
|
|
172
186
|
});
|
|
173
187
|
}
|
|
174
188
|
this.destroyed = true;
|
package/es/regl/ReglTexture2D.js
CHANGED
|
@@ -115,7 +115,7 @@ var ReglTexture2D = /*#__PURE__*/function () {
|
|
|
115
115
|
value: function destroy() {
|
|
116
116
|
if (!this.isDestroy) {
|
|
117
117
|
var _this$texture;
|
|
118
|
-
(_this$texture = this.texture) === null || _this$texture === void 0
|
|
118
|
+
(_this$texture = this.texture) === null || _this$texture === void 0 || _this$texture.destroy();
|
|
119
119
|
}
|
|
120
120
|
this.isDestroy = true;
|
|
121
121
|
}
|
package/es/regl/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import ReglFramebuffer from './ReglFramebuffer';
|
|
|
10
10
|
* regl renderer
|
|
11
11
|
*/
|
|
12
12
|
export default class ReglRendererService implements IRendererService {
|
|
13
|
+
uniformBuffers: IBuffer[];
|
|
13
14
|
extensionObject: IExtensions;
|
|
14
15
|
private gl;
|
|
15
16
|
private $container;
|
|
@@ -48,4 +49,6 @@ export default class ReglRendererService implements IRendererService {
|
|
|
48
49
|
setDirty(flag: boolean): void;
|
|
49
50
|
getDirty(): boolean;
|
|
50
51
|
destroy: () => void;
|
|
52
|
+
beginFrame(): void;
|
|
53
|
+
endFrame(): void;
|
|
51
54
|
}
|
package/es/regl/index.js
CHANGED
|
@@ -26,6 +26,7 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
26
26
|
function ReglRendererService() {
|
|
27
27
|
var _this = this;
|
|
28
28
|
_classCallCheck(this, ReglRendererService);
|
|
29
|
+
_defineProperty(this, "uniformBuffers", []);
|
|
29
30
|
_defineProperty(this, "createModel", function (options) {
|
|
30
31
|
return new ReglModel(_this.gl, options);
|
|
31
32
|
});
|
|
@@ -63,7 +64,7 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
63
64
|
stencil: stencil
|
|
64
65
|
};
|
|
65
66
|
reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
|
|
66
|
-
(_this$gl = _this.gl) === null || _this$gl === void 0
|
|
67
|
+
(_this$gl = _this.gl) === null || _this$gl === void 0 || _this$gl.clear(reglClearOptions);
|
|
67
68
|
});
|
|
68
69
|
_defineProperty(this, "viewport", function (_ref) {
|
|
69
70
|
var x = _ref.x,
|
|
@@ -112,13 +113,13 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
112
113
|
return _this.gl._gl;
|
|
113
114
|
});
|
|
114
115
|
_defineProperty(this, "destroy", function () {
|
|
115
|
-
var _this$gl2
|
|
116
|
+
var _this$gl2;
|
|
116
117
|
// this.canvas = null 清除对 webgl 实例的引用
|
|
117
118
|
// @ts-ignore
|
|
118
119
|
_this.canvas = null;
|
|
119
120
|
|
|
120
121
|
// make sure release webgl context
|
|
121
|
-
(_this$gl2 = _this.gl) === null || _this$gl2 === void 0
|
|
122
|
+
(_this$gl2 = _this.gl) === null || _this$gl2 === void 0 || (_this$gl2 = _this$gl2._gl) === null || _this$gl2 === void 0 || (_this$gl2 = _this$gl2.getExtension('WEBGL_lose_context')) === null || _this$gl2 === void 0 || _this$gl2.loseContext();
|
|
122
123
|
|
|
123
124
|
// @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clean-up
|
|
124
125
|
_this.gl.destroy();
|
|
@@ -265,6 +266,12 @@ var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/funct
|
|
|
265
266
|
value: function getDirty() {
|
|
266
267
|
return this.isDirty;
|
|
267
268
|
}
|
|
269
|
+
}, {
|
|
270
|
+
key: "beginFrame",
|
|
271
|
+
value: function beginFrame() {}
|
|
272
|
+
}, {
|
|
273
|
+
key: "endFrame",
|
|
274
|
+
value: function endFrame() {}
|
|
268
275
|
}]);
|
|
269
276
|
return ReglRendererService;
|
|
270
277
|
}()) || _class);
|
|
@@ -0,0 +1,58 @@
|
|
|
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/device/DeviceAttribute.ts
|
|
20
|
+
var DeviceAttribute_exports = {};
|
|
21
|
+
__export(DeviceAttribute_exports, {
|
|
22
|
+
default: () => DeviceAttribute
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(DeviceAttribute_exports);
|
|
25
|
+
var DeviceAttribute = class {
|
|
26
|
+
constructor(device, options) {
|
|
27
|
+
const {
|
|
28
|
+
buffer,
|
|
29
|
+
offset,
|
|
30
|
+
stride,
|
|
31
|
+
normalized,
|
|
32
|
+
size,
|
|
33
|
+
divisor,
|
|
34
|
+
shaderLocation
|
|
35
|
+
} = options;
|
|
36
|
+
this.buffer = buffer;
|
|
37
|
+
this.attribute = {
|
|
38
|
+
shaderLocation,
|
|
39
|
+
buffer: buffer.get(),
|
|
40
|
+
offset: offset || 0,
|
|
41
|
+
stride: stride || 0,
|
|
42
|
+
normalized: normalized || false,
|
|
43
|
+
divisor: divisor || 0
|
|
44
|
+
};
|
|
45
|
+
if (size) {
|
|
46
|
+
this.attribute.size = size;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
get() {
|
|
50
|
+
return this.buffer;
|
|
51
|
+
}
|
|
52
|
+
updateBuffer(options) {
|
|
53
|
+
this.buffer.subData(options);
|
|
54
|
+
}
|
|
55
|
+
destroy() {
|
|
56
|
+
this.buffer.destroy();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
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/device/DeviceBuffer.ts
|
|
20
|
+
var DeviceBuffer_exports = {};
|
|
21
|
+
__export(DeviceBuffer_exports, {
|
|
22
|
+
default: () => DeviceBuffer
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(DeviceBuffer_exports);
|
|
25
|
+
var import_g_device_api = require("@antv/g-device-api");
|
|
26
|
+
var import_l7_core = require("@antv/l7-core");
|
|
27
|
+
var import_constants = require("./constants");
|
|
28
|
+
var import_typedarray = require("./utils/typedarray");
|
|
29
|
+
var DeviceBuffer = class {
|
|
30
|
+
constructor(device, options) {
|
|
31
|
+
this.isDestroyed = false;
|
|
32
|
+
const { data, usage, type, isUBO } = options;
|
|
33
|
+
let typed;
|
|
34
|
+
if ((0, import_typedarray.isTypedArray)(data)) {
|
|
35
|
+
typed = data;
|
|
36
|
+
} else {
|
|
37
|
+
typed = new import_constants.typedArrayCtorMap[this.type || import_l7_core.gl.FLOAT](data);
|
|
38
|
+
}
|
|
39
|
+
this.type = type;
|
|
40
|
+
this.size = typed.byteLength;
|
|
41
|
+
this.buffer = device.createBuffer({
|
|
42
|
+
viewOrSize: typed,
|
|
43
|
+
usage: isUBO ? import_g_device_api.BufferUsage.UNIFORM : import_g_device_api.BufferUsage.VERTEX,
|
|
44
|
+
hint: import_constants.hintMap[usage || import_l7_core.gl.STATIC_DRAW]
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
get() {
|
|
48
|
+
return this.buffer;
|
|
49
|
+
}
|
|
50
|
+
destroy() {
|
|
51
|
+
if (!this.isDestroyed) {
|
|
52
|
+
this.buffer.destroy();
|
|
53
|
+
}
|
|
54
|
+
this.isDestroyed = true;
|
|
55
|
+
}
|
|
56
|
+
subData({
|
|
57
|
+
data,
|
|
58
|
+
offset
|
|
59
|
+
}) {
|
|
60
|
+
let typed;
|
|
61
|
+
if ((0, import_typedarray.isTypedArray)(data)) {
|
|
62
|
+
typed = data;
|
|
63
|
+
} else {
|
|
64
|
+
typed = new import_constants.typedArrayCtorMap[this.type || import_l7_core.gl.FLOAT](data);
|
|
65
|
+
}
|
|
66
|
+
this.buffer.setSubData(offset, new Uint8Array(typed.buffer));
|
|
67
|
+
}
|
|
68
|
+
};
|