@antv/l7-renderer 2.9.36 → 2.9.37-alpha.2

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.
@@ -1,51 +0,0 @@
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 regl from 'l7regl';
7
- import 'reflect-metadata';
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 DELETED
@@ -1,313 +0,0 @@
1
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
- import _createClass from "@babel/runtime/helpers/createClass";
4
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
-
6
- var _dec, _class;
7
-
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
-
10
- /**
11
- * render w/ regl
12
- * @see https://github.com/regl-project/regl/blob/gh-pages/API.md
13
- */
14
- import { isMini } from '@antv/l7-utils';
15
- import { injectable } from 'inversify';
16
- import regl from 'l7regl';
17
- import 'reflect-metadata';
18
- import ReglAttribute from "./ReglAttribute";
19
- import ReglBuffer from "./ReglBuffer";
20
- import ReglElements from "./ReglElements";
21
- import ReglFramebuffer from "./ReglFramebuffer";
22
- import ReglModel from "./ReglModel";
23
- import ReglTexture2D from "./ReglTexture2D";
24
- /**
25
- * regl renderer
26
- */
27
-
28
- var ReglRendererService = (_dec = injectable(), _dec(_class = /*#__PURE__*/function () {
29
- function ReglRendererService() {
30
- var _this = this;
31
-
32
- _classCallCheck(this, ReglRendererService);
33
-
34
- _defineProperty(this, "createModel", function (options) {
35
- return new ReglModel(_this.gl, options);
36
- });
37
-
38
- _defineProperty(this, "createAttribute", function (options) {
39
- return new ReglAttribute(_this.gl, options);
40
- });
41
-
42
- _defineProperty(this, "createBuffer", function (options) {
43
- return new ReglBuffer(_this.gl, options);
44
- });
45
-
46
- _defineProperty(this, "createElements", function (options) {
47
- return new ReglElements(_this.gl, options);
48
- });
49
-
50
- _defineProperty(this, "createTexture2D", function (options) {
51
- return new ReglTexture2D(_this.gl, options);
52
- });
53
-
54
- _defineProperty(this, "createFramebuffer", function (options) {
55
- return new ReglFramebuffer(_this.gl, options);
56
- });
57
-
58
- _defineProperty(this, "useFramebuffer", function (framebuffer, drawCommands) {
59
- _this.gl({
60
- framebuffer: framebuffer ? framebuffer.get() : null
61
- })(drawCommands);
62
- });
63
-
64
- _defineProperty(this, "clear", function (options) {
65
- var _this$gl;
66
-
67
- // @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clear-the-draw-buffer
68
- var color = options.color,
69
- depth = options.depth,
70
- stencil = options.stencil,
71
- _options$framebuffer = options.framebuffer,
72
- framebuffer = _options$framebuffer === void 0 ? null : _options$framebuffer;
73
- var reglClearOptions = {
74
- color: color,
75
- depth: depth,
76
- stencil: stencil
77
- };
78
- reglClearOptions.framebuffer = framebuffer === null ? framebuffer : framebuffer.get();
79
- (_this$gl = _this.gl) === null || _this$gl === void 0 ? void 0 : _this$gl.clear(reglClearOptions);
80
- });
81
-
82
- _defineProperty(this, "viewport", function (_ref) {
83
- var x = _ref.x,
84
- y = _ref.y,
85
- width = _ref.width,
86
- height = _ref.height;
87
-
88
- // use WebGL context directly
89
- // @see https://github.com/regl-project/regl/blob/gh-pages/API.md#unsafe-escape-hatch
90
- _this.gl._gl.viewport(x, y, width, height);
91
-
92
- _this.width = width;
93
- _this.height = height;
94
-
95
- _this.gl._refresh();
96
- });
97
-
98
- _defineProperty(this, "readPixels", function (options) {
99
- var framebuffer = options.framebuffer,
100
- x = options.x,
101
- y = options.y,
102
- width = options.width,
103
- height = options.height;
104
- var readPixelsOptions = {
105
- x: x,
106
- y: y,
107
- width: width,
108
- height: height
109
- };
110
-
111
- if (framebuffer) {
112
- readPixelsOptions.framebuffer = framebuffer.get();
113
- }
114
-
115
- return _this.gl.read(readPixelsOptions);
116
- });
117
-
118
- _defineProperty(this, "getViewportSize", function () {
119
- return {
120
- width: _this.gl._gl.drawingBufferWidth,
121
- height: _this.gl._gl.drawingBufferHeight
122
- };
123
- });
124
-
125
- _defineProperty(this, "getContainer", function () {
126
- if (isMini) {
127
- return _this.canvas;
128
- } else {
129
- var _this$canvas;
130
-
131
- return (_this$canvas = _this.canvas) === null || _this$canvas === void 0 ? void 0 : _this$canvas.parentElement;
132
- }
133
- });
134
-
135
- _defineProperty(this, "getCanvas", function () {
136
- // return this.$container?.getElementsByTagName('canvas')[0] || null;
137
- return _this.canvas;
138
- });
139
-
140
- _defineProperty(this, "getGLContext", function () {
141
- return _this.gl._gl;
142
- });
143
-
144
- _defineProperty(this, "destroy", function () {
145
- var _this$gl2, _this$gl2$_gl, _this$gl2$_gl$getExte;
146
-
147
- // this.canvas = null 清除对 webgl 实例的引用
148
- // @ts-ignore
149
- _this.canvas = null; // make sure release webgl context
150
-
151
- (_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(); // @see https://github.com/regl-project/regl/blob/gh-pages/API.md#clean-up
152
-
153
- _this.gl.destroy(); // @ts-ignore
154
-
155
-
156
- _this.gl = null;
157
- });
158
- }
159
-
160
- _createClass(ReglRendererService, [{
161
- key: "init",
162
- value: function () {
163
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(canvas, cfg, gl) {
164
- var _this2 = this;
165
-
166
- return _regeneratorRuntime.wrap(function _callee$(_context) {
167
- while (1) {
168
- switch (_context.prev = _context.next) {
169
- case 0:
170
- // this.$container = $container;
171
- this.canvas = canvas;
172
-
173
- if (!gl) {
174
- _context.next = 5;
175
- break;
176
- }
177
-
178
- this.gl = gl;
179
- _context.next = 8;
180
- break;
181
-
182
- case 5:
183
- _context.next = 7;
184
- return new Promise(function (resolve, reject) {
185
- regl({
186
- canvas: _this2.canvas,
187
- attributes: {
188
- alpha: true,
189
- // use TAA instead of MSAA
190
- // @see https://www.khronos.org/registry/webgl/specs/1.0/#5.2.1
191
- antialias: cfg.antialias,
192
- premultipliedAlpha: true,
193
- preserveDrawingBuffer: cfg.preserveDrawingBuffer,
194
- stencil: cfg.stencil
195
- },
196
- // TODO: use extensions
197
- extensions: ['OES_element_index_uint', 'OES_standard_derivatives', // wireframe
198
- 'ANGLE_instanced_arrays' // VSM shadow map
199
- ],
200
- optionalExtensions: ['oes_texture_float_linear', 'OES_texture_float', 'EXT_texture_filter_anisotropic', 'EXT_blend_minmax', 'WEBGL_depth_texture'],
201
- profile: true,
202
- onDone: function onDone(err, r) {
203
- if (err || !r) {
204
- reject(err);
205
- } // @ts-ignore
206
-
207
-
208
- resolve(r);
209
- }
210
- });
211
- });
212
-
213
- case 7:
214
- this.gl = _context.sent;
215
-
216
- case 8:
217
- this.extensionObject = {
218
- OES_texture_float: this.testExtension('OES_texture_float')
219
- };
220
-
221
- case 9:
222
- case "end":
223
- return _context.stop();
224
- }
225
- }
226
- }, _callee, this);
227
- }));
228
-
229
- function init(_x, _x2, _x3) {
230
- return _init.apply(this, arguments);
231
- }
232
-
233
- return init;
234
- }()
235
- }, {
236
- key: "getPointSizeRange",
237
- value: function getPointSizeRange() {
238
- return this.gl._gl.getParameter(this.gl._gl.ALIASED_POINT_SIZE_RANGE);
239
- }
240
- }, {
241
- key: "testExtension",
242
- value: function testExtension(name) {
243
- // OES_texture_float
244
- return !!this.getGLContext().getExtension(name);
245
- }
246
- }, {
247
- key: "setState",
248
- value: // TODO: 临时方法
249
- function setState() {
250
- this.gl({
251
- cull: {
252
- enable: false,
253
- face: 'back'
254
- },
255
- viewport: {
256
- x: 0,
257
- y: 0,
258
- height: this.width,
259
- width: this.height
260
- },
261
- blend: {
262
- enable: true,
263
- equation: 'add'
264
- },
265
- framebuffer: null
266
- });
267
-
268
- this.gl._refresh();
269
- }
270
- }, {
271
- key: "setBaseState",
272
- value: function setBaseState() {
273
- this.gl({
274
- cull: {
275
- enable: false,
276
- face: 'back'
277
- },
278
- viewport: {
279
- x: 0,
280
- y: 0,
281
- height: this.width,
282
- width: this.height
283
- },
284
- blend: {
285
- enable: false,
286
- equation: 'add'
287
- },
288
- framebuffer: null
289
- });
290
-
291
- this.gl._refresh();
292
- }
293
- }, {
294
- key: "setCustomLayerDefaults",
295
- value: function setCustomLayerDefaults() {
296
- var gl = this.getGLContext();
297
- gl.disable(gl.CULL_FACE);
298
- }
299
- }, {
300
- key: "setDirty",
301
- value: function setDirty(flag) {
302
- this.isDirty = flag;
303
- }
304
- }, {
305
- key: "getDirty",
306
- value: function getDirty() {
307
- return this.isDirty;
308
- }
309
- }]);
310
-
311
- return ReglRendererService;
312
- }()) || _class);
313
- export { ReglRendererService as default };
package/lib/index.js DELETED
@@ -1,32 +0,0 @@
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
-
22
- // src/index.ts
23
- var src_exports = {};
24
- __export(src_exports, {
25
- ReglRendererService: () => import_regl.default
26
- });
27
- module.exports = __toCommonJS(src_exports);
28
- var import_regl = __toESM(require("./regl"));
29
- // Annotate the CommonJS export names for ESM import in node:
30
- 0 && (module.exports = {
31
- ReglRendererService
32
- });
@@ -1,51 +0,0 @@
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
- };
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {});
@@ -1,50 +0,0 @@
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/ReglBuffer.ts
20
- var ReglBuffer_exports = {};
21
- __export(ReglBuffer_exports, {
22
- default: () => ReglBuffer
23
- });
24
- module.exports = __toCommonJS(ReglBuffer_exports);
25
- var import_l7_core = require("@antv/l7-core");
26
- var import_constants = require("./constants");
27
- var ReglBuffer = class {
28
- constructor(reGl, options) {
29
- const { data, usage, type } = options;
30
- this.buffer = reGl.buffer({
31
- data,
32
- usage: import_constants.usageMap[usage || import_l7_core.gl.STATIC_DRAW],
33
- type: import_constants.dataTypeMap[type || import_l7_core.gl.UNSIGNED_BYTE]
34
- });
35
- }
36
- get() {
37
- return this.buffer;
38
- }
39
- destroy() {
40
- this.buffer.destroy();
41
- }
42
- subData({
43
- data,
44
- offset
45
- }) {
46
- this.buffer.subdata(data, offset);
47
- }
48
- };
49
- // Annotate the CommonJS export names for ESM import in node:
50
- 0 && (module.exports = {});
@@ -1,49 +0,0 @@
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/ReglElements.ts
20
- var ReglElements_exports = {};
21
- __export(ReglElements_exports, {
22
- default: () => ReglElements
23
- });
24
- module.exports = __toCommonJS(ReglElements_exports);
25
- var import_l7_core = require("@antv/l7-core");
26
- var import_constants = require("./constants");
27
- var ReglElements = class {
28
- constructor(reGl, options) {
29
- const { data, usage, type, count } = options;
30
- this.elements = reGl.elements({
31
- data,
32
- usage: import_constants.usageMap[usage || import_l7_core.gl.STATIC_DRAW],
33
- type: import_constants.dataTypeMap[type || import_l7_core.gl.UNSIGNED_BYTE],
34
- count
35
- });
36
- }
37
- get() {
38
- return this.elements;
39
- }
40
- subData({
41
- data
42
- }) {
43
- this.elements.subdata(data);
44
- }
45
- destroy() {
46
- }
47
- };
48
- // Annotate the CommonJS export names for ESM import in node:
49
- 0 && (module.exports = {});
@@ -1,51 +0,0 @@
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/ReglFramebuffer.ts
20
- var ReglFramebuffer_exports = {};
21
- __export(ReglFramebuffer_exports, {
22
- default: () => ReglFramebuffer
23
- });
24
- module.exports = __toCommonJS(ReglFramebuffer_exports);
25
- var ReglFramebuffer = class {
26
- constructor(reGl, options) {
27
- const { width, height, color, colors, depth, stencil } = options;
28
- const framebufferOptions = {
29
- width,
30
- height
31
- };
32
- if (Array.isArray(colors)) {
33
- framebufferOptions.colors = colors.map((c) => c.get());
34
- }
35
- if (color && typeof color !== "boolean") {
36
- framebufferOptions.color = color.get();
37
- }
38
- this.framebuffer = reGl.framebuffer(framebufferOptions);
39
- }
40
- get() {
41
- return this.framebuffer;
42
- }
43
- destroy() {
44
- this.framebuffer.destroy();
45
- }
46
- resize({ width, height }) {
47
- this.framebuffer.resize(width, height);
48
- }
49
- };
50
- // Annotate the CommonJS export names for ESM import in node:
51
- 0 && (module.exports = {});