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