@luma.gl/webgl 9.0.0-alpha.6 → 9.0.0-alpha.8

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.
Files changed (81) hide show
  1. package/dist/adapter/resources/webgl-render-pipeline.js +12 -0
  2. package/dist/adapter/resources/webgl-render-pipeline.js.map +1 -1
  3. package/dist/adapter/webgl-device.d.ts +13 -7
  4. package/dist/adapter/webgl-device.d.ts.map +1 -1
  5. package/dist/adapter/webgl-device.js +76 -19
  6. package/dist/adapter/webgl-device.js.map +1 -1
  7. package/dist/classic/accessor.d.ts.map +1 -1
  8. package/dist/classic/accessor.js.map +1 -1
  9. package/dist/classic/typed-array-utils.d.ts +1 -1
  10. package/dist/classic/typed-array-utils.d.ts.map +1 -1
  11. package/dist/classic/typed-array-utils.js.map +1 -1
  12. package/dist/context/context/{create-context.d.ts → create-browser-context.d.ts} +1 -1
  13. package/dist/context/context/create-browser-context.d.ts.map +1 -0
  14. package/dist/context/context/{create-context.js → create-browser-context.js} +9 -3
  15. package/dist/context/context/create-browser-context.js.map +1 -0
  16. package/dist/context/context/create-headless-context.d.ts +9 -0
  17. package/dist/context/context/create-headless-context.d.ts.map +1 -0
  18. package/dist/context/context/create-headless-context.js +43 -0
  19. package/dist/context/context/create-headless-context.js.map +1 -0
  20. package/dist/context/debug/webgl-developer-tools.d.ts +1 -1
  21. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  22. package/dist/context/debug/webgl-developer-tools.js +1 -1
  23. package/dist/context/debug/webgl-developer-tools.js.map +1 -1
  24. package/dist/context/polyfill/polyfill-context.js +0 -1
  25. package/dist/context/polyfill/polyfill-context.js.map +1 -1
  26. package/dist/es5/adapter/resources/webgl-render-pipeline.js +12 -0
  27. package/dist/es5/adapter/resources/webgl-render-pipeline.js.map +1 -1
  28. package/dist/es5/adapter/webgl-device.js +91 -27
  29. package/dist/es5/adapter/webgl-device.js.map +1 -1
  30. package/dist/es5/classic/accessor.js.map +1 -1
  31. package/dist/es5/classic/typed-array-utils.js.map +1 -1
  32. package/dist/es5/context/context/{create-context.js → create-browser-context.js} +11 -3
  33. package/dist/es5/context/context/create-browser-context.js.map +1 -0
  34. package/dist/es5/context/context/create-headless-context.js +60 -0
  35. package/dist/es5/context/context/create-headless-context.js.map +1 -0
  36. package/dist/es5/context/debug/webgl-developer-tools.js +1 -1
  37. package/dist/es5/context/debug/webgl-developer-tools.js.map +1 -1
  38. package/dist/es5/context/polyfill/polyfill-context.js +0 -1
  39. package/dist/es5/context/polyfill/polyfill-context.js.map +1 -1
  40. package/dist/es5/index.js +8 -0
  41. package/dist/es5/index.js.map +1 -1
  42. package/dist/es5/types/webgl.js.map +1 -1
  43. package/dist/esm/adapter/resources/webgl-render-pipeline.js +12 -0
  44. package/dist/esm/adapter/resources/webgl-render-pipeline.js.map +1 -1
  45. package/dist/esm/adapter/webgl-device.js +76 -19
  46. package/dist/esm/adapter/webgl-device.js.map +1 -1
  47. package/dist/esm/classic/accessor.js.map +1 -1
  48. package/dist/esm/classic/typed-array-utils.js.map +1 -1
  49. package/dist/esm/context/context/{create-context.js → create-browser-context.js} +9 -3
  50. package/dist/esm/context/context/create-browser-context.js.map +1 -0
  51. package/dist/esm/context/context/create-headless-context.js +43 -0
  52. package/dist/esm/context/context/create-headless-context.js.map +1 -0
  53. package/dist/esm/context/debug/webgl-developer-tools.js +1 -1
  54. package/dist/esm/context/debug/webgl-developer-tools.js.map +1 -1
  55. package/dist/esm/context/polyfill/polyfill-context.js +0 -1
  56. package/dist/esm/context/polyfill/polyfill-context.js.map +1 -1
  57. package/dist/esm/index.js +1 -0
  58. package/dist/esm/index.js.map +1 -1
  59. package/dist/esm/types/webgl.js.map +1 -1
  60. package/dist/index.d.ts +2 -0
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js +1 -0
  63. package/dist/index.js.map +1 -1
  64. package/dist/types/webgl.d.ts +1 -1
  65. package/dist/types/webgl.d.ts.map +1 -1
  66. package/dist/types/webgl.js.map +1 -1
  67. package/package.json +4 -7
  68. package/src/adapter/resources/webgl-render-pipeline.ts +5 -1
  69. package/src/adapter/webgl-device.ts +90 -26
  70. package/src/classic/accessor.ts +0 -13
  71. package/src/classic/typed-array-utils.ts +3 -1
  72. package/src/context/context/{create-context.ts → create-browser-context.ts} +6 -2
  73. package/src/context/context/create-headless-context.ts +48 -0
  74. package/src/context/debug/webgl-developer-tools.ts +2 -2
  75. package/src/context/polyfill/polyfill-context.ts +0 -2
  76. package/src/index.ts +3 -0
  77. package/src/types/webgl.ts +1 -1
  78. package/dist/context/context/create-context.d.ts.map +0 -1
  79. package/dist/context/context/create-context.js.map +0 -1
  80. package/dist/es5/context/context/create-context.js.map +0 -1
  81. package/dist/esm/context/context/create-context.js.map +0 -1
@@ -33,7 +33,9 @@ var _polyfillContext = require("../context/polyfill/polyfill-context");
33
33
 
34
34
  var _trackContextState = require("../context/state-tracker/track-context-state");
35
35
 
36
- var _createContext = require("../context/context/create-context");
36
+ var _createBrowserContext = require("../context/context/create-browser-context");
37
+
38
+ var _createHeadlessContext = require("../context/context/create-headless-context");
37
39
 
38
40
  var _getDeviceInfo = require("./device-helpers/get-device-info");
39
41
 
@@ -88,15 +90,16 @@ var WebGLDevice = function (_Device) {
88
90
  _this = _super.call(this, props);
89
91
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "info", void 0);
90
92
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "canvasContext", void 0);
91
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lost", void 0);
92
93
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "handle", void 0);
94
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "lost", void 0);
95
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_resolveContextLost", void 0);
96
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_features", void 0);
97
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_limits", void 0);
93
98
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gl", void 0);
94
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gl2", void 0);
99
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "gl2", null);
95
100
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "debug", false);
96
101
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isWebGL1", void 0);
97
102
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "isWebGL2", void 0);
98
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_features", void 0);
99
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_limits", void 0);
100
103
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_webglLimits", void 0);
101
104
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_canvasSizeInfo", {
102
105
  clientWidth: 0,
@@ -106,17 +109,40 @@ var WebGLDevice = function (_Device) {
106
109
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_extensions", {});
107
110
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "_polyfilled", false);
108
111
  (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "spector", void 0);
109
- (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderPass", void 0);
112
+ (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "renderPass", null);
110
113
  var device = (_props$gl = props.gl) === null || _props$gl === void 0 ? void 0 : _props$gl.device;
111
114
 
112
115
  if (device) {
113
- _api.log.warn("WebGL context already attached to device ".concat(device.id));
114
-
115
- return (0, _possibleConstructorReturn2.default)(_this, device);
116
+ throw new Error("WebGL context already attached to device ".concat(device.id));
116
117
  }
117
118
 
118
119
  _this.canvasContext = new _webglCanvasContext.default((0, _assertThisInitialized2.default)(_this), props);
119
- _this.handle = props.gl || (0, _createContext.createBrowserContext)(_this.canvasContext.canvas, props);
120
+ _this.lost = new Promise(function (resolve) {
121
+ _this._resolveContextLost = resolve;
122
+ });
123
+
124
+ var onContextLost = function onContextLost(event) {
125
+ var _this$_resolveContext, _this2;
126
+
127
+ return (_this$_resolveContext = (_this2 = _this)._resolveContextLost) === null || _this$_resolveContext === void 0 ? void 0 : _this$_resolveContext.call(_this2, {
128
+ reason: 'destroyed',
129
+ message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
130
+ });
131
+ };
132
+
133
+ var gl = props.gl;
134
+ gl = gl || ((0, _env.isBrowser)() ? (0, _createBrowserContext.createBrowserContext)(_this.canvasContext.canvas, _objectSpread(_objectSpread({}, props), {}, {
135
+ onContextLost: onContextLost
136
+ })) : null);
137
+ gl = gl || (!(0, _env.isBrowser)() ? (0, _createHeadlessContext.createHeadlessContext)(_objectSpread(_objectSpread({}, props), {}, {
138
+ onContextLost: onContextLost
139
+ })) : null);
140
+
141
+ if (!gl) {
142
+ throw new Error('WebGL context creation failed');
143
+ }
144
+
145
+ _this.handle = gl;
120
146
  _this.gl = _this.handle;
121
147
  _this.gl2 = _this.gl;
122
148
  _this.isWebGL2 = isWebGL2(_this.gl);
@@ -125,8 +151,13 @@ var WebGLDevice = function (_Device) {
125
151
  _this.gl.device = (0, _assertThisInitialized2.default)(_this);
126
152
  _this.gl._version = _this.isWebGL2 ? 2 : 1;
127
153
  (0, _polyfillContext.polyfillContext)(_this.gl);
154
+ var _props$enable = props.enable,
155
+ enable = _props$enable === void 0 ? true : _props$enable,
156
+ _props$copyState = props.copyState,
157
+ copyState = _props$copyState === void 0 ? false : _props$copyState;
128
158
  (0, _trackContextState.trackContextState)(_this.gl, {
129
- copyState: false,
159
+ enable: enable,
160
+ copyState: copyState,
130
161
  log: function log() {
131
162
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
132
163
  args[_key] = arguments[_key];
@@ -191,6 +222,22 @@ var WebGLDevice = function (_Device) {
191
222
  ext.destroy();
192
223
  }
193
224
  }
225
+ }, {
226
+ key: "loseDevice",
227
+ value: function loseDevice() {
228
+ var _this$_resolveContext2;
229
+
230
+ var ext = this.gl.getExtension('WEBGL_lose_context');
231
+
232
+ if (ext) {
233
+ ext.loseContext();
234
+ }
235
+
236
+ (_this$_resolveContext2 = this._resolveContextLost) === null || _this$_resolveContext2 === void 0 ? void 0 : _this$_resolveContext2.call(this, {
237
+ reason: 'destroyed',
238
+ message: 'Application triggered context loss'
239
+ });
240
+ }
194
241
  }, {
195
242
  key: "isLost",
196
243
  get: function get() {
@@ -219,7 +266,10 @@ var WebGLDevice = function (_Device) {
219
266
  }, {
220
267
  key: "assertWebGL2",
221
268
  value: function assertWebGL2() {
222
- (0, _api.assert)(this.isWebGL2, 'Requires WebGL2');
269
+ if (!this.gl2) {
270
+ throw new Error('Requires WebGL2');
271
+ }
272
+
223
273
  return this.gl2;
224
274
  }
225
275
  }, {
@@ -288,13 +338,15 @@ var WebGLDevice = function (_Device) {
288
338
  }, {
289
339
  key: "submit",
290
340
  value: function submit() {
291
- this.renderPass.endPass();
341
+ var _this$renderPass;
342
+
343
+ (_this$renderPass = this.renderPass) === null || _this$renderPass === void 0 ? void 0 : _this$renderPass.endPass();
292
344
  this.renderPass = null;
293
345
  }
294
346
  }], [{
295
347
  key: "isSupported",
296
348
  value: function isSupported() {
297
- return typeof WebGLRenderingContext !== 'undefined';
349
+ return typeof WebGLRenderingContext !== 'undefined' || (0, _createHeadlessContext.isHeadlessGLRegistered)();
298
350
  }
299
351
  }, {
300
352
  key: "attach",
@@ -318,45 +370,57 @@ var WebGLDevice = function (_Device) {
318
370
  }, {
319
371
  key: "create",
320
372
  value: function () {
321
- var _create = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee(props) {
373
+ var _create = (0, _asyncToGenerator2.default)(_regenerator.default.mark(function _callee() {
374
+ var props,
375
+ _args = arguments;
322
376
  return _regenerator.default.wrap(function _callee$(_context) {
323
377
  while (1) {
324
378
  switch (_context.prev = _context.next) {
325
379
  case 0:
380
+ props = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
381
+
326
382
  _api.log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');
327
383
 
328
384
  if (!(typeof props.canvas === 'string')) {
329
- _context.next = 4;
385
+ _context.next = 5;
330
386
  break;
331
387
  }
332
388
 
333
- _context.next = 4;
389
+ _context.next = 5;
334
390
  return _api.CanvasContext.pageLoaded;
335
391
 
336
- case 4:
392
+ case 5:
337
393
  if (!props.debug) {
338
- _context.next = 7;
394
+ _context.next = 8;
339
395
  break;
340
396
  }
341
397
 
342
- _context.next = 7;
398
+ _context.next = 8;
343
399
  return (0, _webglDeveloperTools.loadWebGLDeveloperTools)();
344
400
 
345
- case 7:
401
+ case 8:
346
402
  if (!props.spector) {
347
- _context.next = 10;
403
+ _context.next = 11;
348
404
  break;
349
405
  }
350
406
 
351
- _context.next = 10;
407
+ _context.next = 11;
352
408
  return (0, _spector.loadSpectorJS)();
353
409
 
354
- case 10:
355
- _api.log.probe(LOG_LEVEL, 'DOM is loaded')();
410
+ case 11:
411
+ _api.log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
412
+
413
+ if (!(props.gl && props.gl.device)) {
414
+ _context.next = 14;
415
+ break;
416
+ }
417
+
418
+ return _context.abrupt("return", WebGLDevice.attach(props.gl));
356
419
 
420
+ case 14:
357
421
  return _context.abrupt("return", new WebGLDevice(props));
358
422
 
359
- case 12:
423
+ case 15:
360
424
  case "end":
361
425
  return _context.stop();
362
426
  }
@@ -364,7 +428,7 @@ var WebGLDevice = function (_Device) {
364
428
  }, _callee);
365
429
  }));
366
430
 
367
- function create(_x) {
431
+ function create() {
368
432
  return _create.apply(this, arguments);
369
433
  }
370
434
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/adapter/webgl-device.ts"],"names":["LOG_LEVEL","counter","WebGLDevice","props","clientWidth","clientHeight","devicePixelRatio","device","gl","log","warn","id","canvasContext","WebGLCanvasContext","handle","canvas","gl2","isWebGL2","isWebGL1","info","_version","copyState","args","debug","webgl2","throwOnError","level","Math","max","spector","message","type","vendor","renderer","probe","groupEnd","_features","_limits","_webglLimits","ext","getExtension","destroy","isContextLost","drawingBufferWidth","drawingBufferHeight","format","Error","ClassicBuffer","WEBGLTexture","WEBGLSampler","WEBGLShader","WEBGLFramebuffer","WEBGLRenderPipeline","WEBGLRenderPass","renderPass","beginRenderPass","framebuffer","getCurrentFramebuffer","endPass","WebGLRenderingContext","Device","isWebGL","groupCollapsed","CanvasContext","pageLoaded","WebGL2RenderingContext","Boolean","Number","isFinite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AA0BA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;;;AAEA,IAAMA,SAAS,GAAG,CAAlB;AAEA,IAAIC,OAAO,GAAG,CAAd;;IAGqBC,W;;;;;AAkGnB,uBAAYC,KAAZ,EAAgC;AAAA;;AAAA;;AAAA;AAC9B,8BAAMA,KAAN;AAD8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wFApEN,KAoEM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kGAnDL;AAACC,MAAAA,WAAW,EAAE,CAAd;AAAiBC,MAAAA,YAAY,EAAE,CAA/B;AAAkCC,MAAAA,gBAAgB,EAAE;AAApD,KAmDK;AAAA,8FAjDY,EAiDZ;AAAA,8FAhDT,KAgDS;AAAA;AAAA;AAK9B,QAAMC,MAA+B,gBAAGJ,KAAK,CAACK,EAAT,8CAAG,UAAUD,MAAlD;;AACA,QAAIA,MAAJ,EAAY;AACVE,eAAIC,IAAJ,oDAAqDH,MAAM,CAACI,EAA5D;;AACA,6DAAOJ,MAAP;AACD;;AAGD,UAAKK,aAAL,GAAqB,IAAIC,2BAAJ,8CAA6BV,KAA7B,CAArB;AAEA,UAAKW,MAAL,GAAcX,KA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;AAkBEpB,yBAAIyB,KAAJ,CAAUlC,SAAV,EAAqB,eAArB;;AAlBF,iDAmBS,IAAIE,WAAJ,CAAgBC,KAAhB,CAnBT;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,O;;;;;;;;;;EA5EuCyD,W;;;8BAApB1D,W,UAGG,O;;AA0QxB,SAAS2D,OAAT,CAAiBrD,EAAjB,EAAmC;AACjC,MAAI,OAAOmD,qBAAP,KAAiC,WAAjC,IAAgDnD,EAAE,YAAYmD,qBAAlE,EAAyF;AACvF,WAAO,IAAP;AACD;;AACD,MAAI,OAAOM,sBAAP,KAAkC,WAAlC,IAAiDzD,EAAE,YAAYyD,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAAC1D,EAAE,IAAI2D,MAAM,CAACC,QAAP,CAAgB5D,EAAE,CAACY,QAAnB,CAAP,CAAd;AACD;;AAID,SAASH,QAAT,CAAkBT,EAAlB,EAAoC;AAClC,MAAI,OAAOyD,sBAAP,KAAkC,WAAlC,IAAiDzD,EAAE,YAAYyD,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAAC1D,EAAE,IAAIA,EAAE,CAACY,QAAH,KAAgB,CAAvB,CAAd;AACD","sourcesContent":["// luma.gl, MIT license\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, assert} from '@luma.gl/api';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {trackContextState} from '../context/state-tracker/track-context-state';\nimport {ContextState} from '../context/context/context-state';\nimport {createBrowserContext} from '../context/context/create-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport WebGLCanvasContext from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps\n} from '@luma.gl/api';\n\nimport ClassicBuffer from '../classic/buffer';\nimport WEBGLBuffer from './resources/webgl-buffer';\nimport WEBGLShader from './resources/webgl-shader';\nimport WEBGLSampler from './resources/webgl-sampler';\nimport WEBGLTexture from './resources/webgl-texture';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\nimport WEBGLRenderPass from './resources/webgl-render-pass';\nimport WEBGLRenderPipeline from './resources/webgl-render-pipeline';\n\nconst LOG_LEVEL = 1;\n\nlet counter = 0;\n\n/** WebGPU style Device API for a WebGL context */\nexport default class WebGLDevice extends Device implements ContextState {\n // Public API\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined';\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n // WebGL specific API\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n get webglLimits(): WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n private _features: Set<DeviceFeature>;\n private _limits: DeviceLimits;\n private _webglLimits: WebGLLimits;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n /** State used by luma.gl classes */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props?: DeviceProps): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (props.debug) {\n await loadWebGLDeveloperTools();\n }\n // @ts-expect-error spector not on props\n if (props.spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL, 'DOM is loaded')();\n return new WebGLDevice(props);\n }\n\n constructor(props: DeviceProps) {\n super(props);\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n log.warn(`WebGL context already attached to device ${device.id}`);\n return device;\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.handle = props.gl || createBrowserContext(this.canvasContext.canvas, props);\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle \n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n // Install context state tracking\n trackContextState(this.gl, {copyState: false, log: (...args: any[]) => log.log(1, ...args)()});\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy() {\n let ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n // ext = this.gl.getExtension('WEBGL_lose_context');\n // if (ext) {\n // // TODO - disconnect context lost callbacks?\n // ext.loseContext();\n // }\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n assert(this.isWebGL2, 'Requires WebGL2');\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n _createBuffer(props: BufferProps): WEBGLBuffer {\n return new ClassicBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('compute shaders not supported in WebGL');\n }\n\n private renderPass: WEBGLRenderPass;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass.endPass();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n"],"file":"webgl-device.js"}
1
+ {"version":3,"sources":["../../../src/adapter/webgl-device.ts"],"names":["LOG_LEVEL","counter","WebGLDevice","props","clientWidth","clientHeight","devicePixelRatio","device","gl","Error","id","canvasContext","WebGLCanvasContext","lost","Promise","resolve","_resolveContextLost","onContextLost","event","reason","message","canvas","handle","gl2","isWebGL2","isWebGL1","info","_version","enable","copyState","log","args","debug","webgl2","throwOnError","level","Math","max","warn","spector","type","vendor","renderer","probe","groupEnd","_features","_limits","_webglLimits","ext","getExtension","destroy","loseContext","isContextLost","drawingBufferWidth","drawingBufferHeight","format","ClassicBuffer","WEBGLTexture","WEBGLSampler","WEBGLShader","WEBGLFramebuffer","WEBGLRenderPipeline","WEBGLRenderPass","renderPass","beginRenderPass","framebuffer","getCurrentFramebuffer","endPass","WebGLRenderingContext","Device","isWebGL","groupCollapsed","CanvasContext","pageLoaded","attach","WebGL2RenderingContext","Boolean","Number","isFinite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;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nE,W,UAKG,O;;AAqUxB,SAASoE,OAAT,CAAiB9D,EAAjB,EAAmC;AACjC,MAAI,OAAO4D,qBAAP,KAAiC,WAAjC,IAAgD5D,EAAE,YAAY4D,qBAAlE,EAAyF;AACvF,WAAO,IAAP;AACD;;AACD,MAAI,OAAOO,sBAAP,KAAkC,WAAlC,IAAiDnE,EAAE,YAAYmE,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAACpE,EAAE,IAAIqE,MAAM,CAACC,QAAP,CAAgBtE,EAAE,CAACmB,QAAnB,CAAP,CAAd;AACD;;AAGD,SAASH,QAAT,CAAkBhB,EAAlB,EAAoC;AAClC,MAAI,OAAOmE,sBAAP,KAAkC,WAAlC,IAAiDnE,EAAE,YAAYmE,sBAAnE,EAA2F;AACzF,WAAO,IAAP;AACD;;AAED,SAAOC,OAAO,CAACpE,EAAE,IAAIA,EAAE,CAACmB,QAAH,KAAgB,CAAvB,CAAd;AACD","sourcesContent":["// luma.gl, MIT license\nimport type {\n DeviceProps,\n DeviceInfo,\n DeviceLimits,\n DeviceFeature,\n CanvasContextProps,\n TextureFormat\n} from '@luma.gl/api';\nimport {Device, CanvasContext, log, assert} from '@luma.gl/api';\nimport {isBrowser} from '@probe.gl/env';\nimport {polyfillContext} from '../context/polyfill/polyfill-context';\nimport {trackContextState} from '../context/state-tracker/track-context-state';\nimport {ContextState} from '../context/context/context-state';\nimport {createBrowserContext} from '../context/context/create-browser-context';\nimport {\n createHeadlessContext,\n isHeadlessGLRegistered\n} from '../context/context/create-headless-context';\nimport {getDeviceInfo} from './device-helpers/get-device-info';\nimport {getDeviceFeatures} from './device-helpers/device-features';\nimport {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';\nimport WebGLCanvasContext from './webgl-canvas-context';\nimport {loadSpectorJS, initializeSpectorJS} from '../context/debug/spector';\nimport {loadWebGLDeveloperTools, makeDebugContext} from '../context/debug/webgl-developer-tools';\nimport {\n isTextureFormatSupported,\n isTextureFormatRenderable,\n isTextureFormatFilterable\n} from './converters/texture-formats';\n\n// WebGL classes\nimport type {\n BufferProps,\n ShaderProps,\n Sampler,\n SamplerProps,\n TextureProps,\n ExternalTexture,\n ExternalTextureProps,\n FramebufferProps,\n RenderPipeline,\n RenderPipelineProps,\n ComputePipeline,\n ComputePipelineProps,\n RenderPass,\n RenderPassProps,\n ComputePass,\n ComputePassProps\n} from '@luma.gl/api';\n\nimport ClassicBuffer from '../classic/buffer';\nimport WEBGLBuffer from './resources/webgl-buffer';\nimport WEBGLShader from './resources/webgl-shader';\nimport WEBGLSampler from './resources/webgl-sampler';\nimport WEBGLTexture from './resources/webgl-texture';\nimport WEBGLFramebuffer from './resources/webgl-framebuffer';\nimport WEBGLRenderPass from './resources/webgl-render-pass';\nimport WEBGLRenderPipeline from './resources/webgl-render-pipeline';\n\nconst LOG_LEVEL = 1;\n\nlet counter = 0;\n\n/** WebGPU style Device API for a WebGL context */\nexport default class WebGLDevice extends Device implements ContextState {\n //\n // Public `Device` API\n //\n\n static type: string = 'webgl';\n\n static isSupported(): boolean {\n return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();\n }\n\n readonly info: DeviceInfo;\n readonly canvasContext: WebGLCanvasContext;\n\n readonly handle: WebGLRenderingContext;\n\n get features(): Set<DeviceFeature> {\n this._features = this._features || getDeviceFeatures(this.gl);\n return this._features;\n }\n\n get limits(): DeviceLimits {\n this._limits = this._limits || getDeviceLimits(this.gl);\n return this._limits;\n }\n\n readonly lost: Promise<{reason: 'destroyed'; message: string}>;\n\n private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;\n private _features?: Set<DeviceFeature>;\n private _limits?: DeviceLimits;\n\n //\n // WebGL-only API (not part of `Device` API)\n //\n\n /** WebGL1 typed context. Can always be used. */\n readonly gl: WebGLRenderingContext;\n /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */\n readonly gl2: WebGL2RenderingContext | null = null;\n readonly debug: boolean = false;\n\n /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */\n readonly isWebGL1: boolean;\n /** `true` if this is a WebGL2 context. @note `false` if WebGL1 */\n readonly isWebGL2: boolean;\n\n get webglLimits(): WebGLLimits {\n this._webglLimits = this._webglLimits || getWebGLLimits(this.gl);\n return this._webglLimits;\n }\n\n private _webglLimits?: WebGLLimits;\n\n /** State used by luma.gl classes: TODO - move to canvasContext*/\n readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};\n /** State used by luma.gl classes */\n readonly _extensions: Record<string, any> = {};\n _polyfilled: boolean = false;\n\n /** Instance of Spector.js (if initialized) */\n spector;\n\n //\n // Static methods, expected to be present by `luma.createDevice()`\n //\n\n /**\n * Get a device instance from a GL context\n * Creates and instruments the device if not already created\n * @param gl\n * @returns\n */\n static attach(gl: Device | WebGLRenderingContext | WebGL2RenderingContext): WebGLDevice {\n if (gl instanceof WebGLDevice) {\n return gl;\n }\n // @ts-expect-error\n if (gl?.device instanceof Device) {\n // @ts-expect-error\n return gl.device as WebGLDevice;\n }\n if (!isWebGL(gl)) {\n throw new Error('Invalid WebGLRenderingContext');\n }\n return new WebGLDevice({gl: gl as WebGLRenderingContext});\n }\n\n static async create(props: DeviceProps = {}): Promise<WebGLDevice> {\n log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');\n\n // Wait for page to load. Only wait when props. canvas is string\n // to avoid setting page onload callback unless necessary\n if (typeof props.canvas === 'string') {\n await CanvasContext.pageLoaded;\n }\n\n // Load webgl and spector debug scripts from CDN if requested\n if (props.debug) {\n await loadWebGLDeveloperTools();\n }\n // @ts-expect-error spector not on props\n if (props.spector) {\n await loadSpectorJS();\n }\n\n log.probe(LOG_LEVEL + 1, 'DOM is loaded')();\n\n // @ts-expect-error\n if (props.gl && props.gl.device) {\n return WebGLDevice.attach(props.gl);\n }\n\n return new WebGLDevice(props);\n }\n\n //\n // Public API\n //\n\n constructor(props: DeviceProps) {\n super(props);\n\n // If attaching to an already attached context, return the attached device\n // @ts-expect-error device is attached to context\n const device: WebGLDevice | undefined = props.gl?.device;\n if (device) {\n throw new Error(`WebGL context already attached to device ${device.id}`);\n }\n\n // Create and instrument context\n this.canvasContext = new WebGLCanvasContext(this, props);\n\n this.lost = new Promise<{reason: 'destroyed'; message: string}>((resolve) => {\n this._resolveContextLost = resolve;\n });\n\n const onContextLost = (event: Event) =>\n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'\n });\n\n let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl;\n gl =\n gl ||\n (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost}) : null);\n gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);\n\n if (!gl) {\n throw new Error('WebGL context creation failed');\n }\n\n this.handle = gl;\n this.gl = this.handle;\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.isWebGL2 = isWebGL2(this.gl);\n this.isWebGL1 = !this.isWebGL2;\n\n // luma Device fields\n this.info = getDeviceInfo(this.gl);\n\n // @ts-expect-error Link webgl context back to device\n this.gl.device = this;\n // @ts-expect-error Annotate webgl context to handle\n this.gl._version = this.isWebGL2 ? 2 : 1;\n\n // Add subset of WebGL2 methods to WebGL1 context\n polyfillContext(this.gl);\n\n // Install context state tracking\n // @ts-expect-error - hidden parameters\n const {enable = true, copyState = false} = props;\n trackContextState(this.gl, {\n enable,\n copyState,\n log: (...args: any[]) => log.log(1, ...args)()\n });\n\n // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1\n if (isBrowser() && props.debug) {\n this.gl = makeDebugContext(this.gl, {...props, webgl2: this.isWebGL2, throwOnError: true});\n this.gl2 = this.gl as WebGL2RenderingContext;\n this.debug = true;\n log.level = Math.max(log.level, 1);\n log.warn('WebGL debug mode activated. Performance reduced.')();\n }\n\n // @ts-expect-error spector not on props\n if (isBrowser() && props.spector) {\n const canvas = this.handle.canvas || (props.canvas as HTMLCanvasElement);\n this.spector = initializeSpectorJS({...this.props, canvas});\n }\n\n // Log some debug info about the newly created context\n const message = `\\\nCreated ${this.info.type}${this.debug ? ' debug' : ''} context: \\\n${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`;\n log.probe(LOG_LEVEL, message)();\n\n log.groupEnd(LOG_LEVEL)();\n }\n\n /**\n * Destroys the context\n * @note Has no effect for browser contexts, there is no browser API for destroying contexts\n */\n destroy() {\n const ext = this.gl.getExtension('STACKGL_destroy_context');\n if (ext) {\n ext.destroy();\n }\n }\n\n /**\n * Loses the context\n * @note Triggers context loss, mainly for testing\n */\n loseDevice() {\n const ext = this.gl.getExtension('WEBGL_lose_context');\n if (ext) {\n ext.loseContext();\n }\n // loseContext should trigger context loss callback but \n this._resolveContextLost?.({\n reason: 'destroyed',\n message: 'Application triggered context loss'\n });\n }\n\n get isLost(): boolean {\n return this.gl.isContextLost();\n }\n\n getSize(): [number, number] {\n return [this.gl.drawingBufferWidth, this.gl.drawingBufferHeight];\n }\n\n isTextureFormatSupported(format: TextureFormat): boolean {\n return isTextureFormatSupported(this.gl, format);\n }\n\n isTextureFormatFilterable(format: TextureFormat): boolean {\n return isTextureFormatFilterable(this.gl, format);\n }\n\n isTextureFormatRenderable(format: TextureFormat): boolean {\n return isTextureFormatRenderable(this.gl, format);\n }\n\n // WEBGL SPECIFIC METHODS\n\n /** Returns a WebGL2RenderingContext or throws an error */\n assertWebGL2(): WebGL2RenderingContext {\n if (!this.gl2) {\n throw new Error('Requires WebGL2');\n }\n return this.gl2;\n }\n\n // IMPLEMENTATION OF ABSTRACT DEVICE\n\n createCanvasContext(props?: CanvasContextProps): CanvasContext {\n throw new Error('WebGL only supports a single canvas');\n }\n\n _createBuffer(props: BufferProps): WEBGLBuffer {\n return new ClassicBuffer(this, props);\n }\n\n _createTexture(props: TextureProps): WEBGLTexture {\n return new WEBGLTexture(this, props);\n }\n\n createExternalTexture(props: ExternalTextureProps): ExternalTexture {\n throw new Error('createExternalTexture() not implemented'); // return new Program(props);\n }\n\n createSampler(props: SamplerProps): WEBGLSampler {\n return new WEBGLSampler(this, props);\n }\n\n createShader(props: ShaderProps): WEBGLShader {\n return new WEBGLShader(this, props);\n }\n\n createFramebuffer(props: FramebufferProps): WEBGLFramebuffer {\n return new WEBGLFramebuffer(this, props);\n }\n\n createRenderPipeline(props: RenderPipelineProps): WEBGLRenderPipeline {\n return new WEBGLRenderPipeline(this, props);\n }\n\n beginRenderPass(props: RenderPassProps): WEBGLRenderPass {\n return new WEBGLRenderPass(this, props);\n }\n\n createComputePipeline(props?: ComputePipelineProps): ComputePipeline {\n throw new Error('ComputePipeline not supported in WebGL');\n }\n\n beginComputePass(props: ComputePassProps): ComputePass {\n throw new Error('compute shaders not supported in WebGL');\n }\n\n private renderPass: WEBGLRenderPass | null = null;\n\n getDefaultRenderPass(): WEBGLRenderPass {\n this.renderPass =\n this.renderPass ||\n this.beginRenderPass({\n framebuffer: this.canvasContext.getCurrentFramebuffer()\n });\n return this.renderPass;\n }\n\n /**\n * Offscreen Canvas Support: Commit the frame\n * https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/commit\n * Chrome's offscreen canvas does not require gl.commit\n */\n submit(): void {\n this.renderPass?.endPass();\n this.renderPass = null;\n // this.canvasContext.commit();\n }\n}\n\n/** Check if supplied parameter is a WebGLRenderingContext */\nfunction isWebGL(gl: any): boolean {\n if (typeof WebGLRenderingContext !== 'undefined' && gl instanceof WebGLRenderingContext) {\n return true;\n }\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && Number.isFinite(gl._version));\n}\n\n/** Check if supplied parameter is a WebGL2RenderingContext */\nfunction isWebGL2(gl: any): boolean {\n if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {\n return true;\n }\n // Look for debug contexts, headless gl etc\n return Boolean(gl && gl._version === 2);\n}\n"],"file":"webgl-device.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/classic/accessor.ts"],"names":["DEFAULT_ACCESSOR_VALUES","offset","stride","type","GL","FLOAT","size","divisor","normalized","integer","PROP_CHECKS","deprecatedProps","instanced","isInstanced","Accessor","accessors","forEach","accessor","_assign","Object","freeze","JSON","stringify","getBytesPerElement","getBytesPerVertex","props","undefined","INT","UNSIGNED_INT","normalize","buffer","index","ArrayType","BYTES_PER_ELEMENT"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAeA,IAAMA,uBAAuB,GAAG;AAC9BC,EAAAA,MAAM,EAAE,CADsB;AAE9BC,EAAAA,MAAM,EAAE,CAFsB;AAG9BC,EAAAA,IAAI,EAAEC,mBAAGC,KAHqB;AAI9BC,EAAAA,IAAI,EAAE,CAJwB;AAK9BC,EAAAA,OAAO,EAAE,CALqB;AAM9BC,EAAAA,UAAU,EAAE,KANkB;AAO9BC,EAAAA,OAAO,EAAE;AAPqB,CAAhC;;AAUA,IAAMC,WAAW,GAAG;AAClBC,EAAAA,eAAe,EAAE;AACfC,IAAAA,SAAS,EAAE,SADI;AAEfC,IAAAA,WAAW,EAAE;AAFE;AADC,CAApB;;IAOqBC,Q;AAmCnB,sBAA4C;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA,sCAA7BC,SAA6B;AAA7BA,MAAAA,SAA6B;AAAA;;AAC1CA,IAAAA,SAAS,CAACC,OAAV,CAAkB,UAACC,QAAD;AAAA,aAAc,KAAI,CAACC,OAAL,CAAaD,QAAb,CAAd;AAAA,KAAlB;AACAE,IAAAA,MAAM,CAACC,MAAP,CAAc,IAAd;AACD;;;;WAED,oBAAmB;AACjB,aAAOC,IAAI,CAACC,SAAL,CAAe,IAAf,CAAP;AACD;;;SAKD,eAAgC;AAC9B,aAAOR,QAAQ,CAACS,kBAAT,CAA4B,IAA5B,CAAP;AACD;;;SAED,eAA+B;AAC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AAnB,EAA8B,OAAO,KAAKK,KAAZ;AAE9B,aAAO,IAAP;AACD;;;WA1HD,4BAA0Bd,QAA1B,EAAuE;AAGrE,UAAMe,SAAS,GAAG,8CAAwBf,QAAQ,CAACd,IAAT,IAAiBC,mBAAGC,KAA5C,CAAlB;AACA,aAAO2B,SAAS,CAACC,iBAAjB;AACD;;;WAED,2BAAyBhB,QAAzB,EAA2D;AACzD,uBAAOA,QAAQ,CAACX,IAAhB;AAGA,UAAM0B,SAAS,GAAG,8CAAwBf,QAAQ,CAACd,IAAT,IAAiBC,mBAAGC,KAA5C,CAAlB;AACA,aAAO2B,SAAS,CAACC,iBAAV,GAA8BhB,QAAQ,CAACX,IAA9C;AACD;;;WAMD,mBAAyD;AAAA,yCAAvCS,SAAuC;AAAvCA,QAAAA,SAAuC;AAAA;;AACvD,sCAAWD,QAAX,GAAwBd,uBAAxB,SAAoDe,SAApD;AACD","sourcesContent":["import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\nimport {getTypedArrayFromGLType} from './typed-array-utils';\n\n// export interface AccessorObject {\n// offset?: number;\n// stride?: number;\n// type?: number;\n// size?: number;\n// divisor?: number;\n// normalized?: boolean;\n// integer?: boolean;\n\n// buffer?: Buffer;\n// index?: number;\n// }\n\nconst DEFAULT_ACCESSOR_VALUES = {\n offset: 0,\n stride: 0,\n type: GL.FLOAT,\n size: 1,\n divisor: 0,\n normalized: false,\n integer: false\n};\n\nconst PROP_CHECKS = {\n deprecatedProps: {\n instanced: 'divisor',\n isInstanced: 'divisor'\n }\n};\n\nexport default class Accessor implements AccessorObject {\n offset?: number;\n stride?: number;\n type?: number;\n size?: number;\n divisor?: number;\n normalized?: boolean;\n integer?: boolean;\n\n buffer?: Buffer;\n index?: number;\n\n static getBytesPerElement(accessor: Accessor | AccessorObject): number {\n // TODO: using `FLOAT` when type is not specified,\n // ensure this assumption is valid or force API to specify type.\n const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);\n return ArrayType.BYTES_PER_ELEMENT;\n }\n\n static getBytesPerVertex(accessor: AccessorObject): number {\n assert(accessor.size);\n // TODO: using `FLOAT` when type is not specified,\n // ensure this assumption is valid or force API to specify type.\n const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);\n return ArrayType.BYTES_PER_ELEMENT * accessor.size;\n }\n\n // Combines (merges) a list of accessors. On top of default values\n // Usually [programAccessor, bufferAccessor, appAccessor]\n // All props will be set in the returned object.\n // TODO check for conflicts between values in the supplied accessors\n static resolve(...accessors: AccessorObject[]): Accessor {\n return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]); // Default values\n }\n\n constructor(...accessors: AccessorObject[]) {\n accessors.forEach((accessor) => this._assign(accessor)); // Merge in sequence\n Object.freeze(this);\n }\n\n toString(): string {\n return JSON.stringify(this);\n }\n\n // ACCESSORS\n\n // TODO - remove>\n get BYTES_PER_ELEMENT(): number {\n return Accessor.getBytesPerElement(this);\n }\n\n get BYTES_PER_VERTEX(): number {\n return Accessor.getBytesPerVertex(this);\n }\n\n // PRIVATE\n\n // eslint-disable-next-line complexity, max-statements\n _assign(props: AccessorObject = {}): this {\n props = checkProps('Accessor', props, PROP_CHECKS);\n\n if (props.type !== undefined) {\n this.type = props.type;\n\n // Auto-deduce integer type?\n if (props.type === GL.INT || props.type === GL.UNSIGNED_INT) {\n this.integer = true;\n }\n }\n if (props.size !== undefined) {\n this.size = props.size;\n }\n if (props.offset !== undefined) {\n this.offset = props.offset;\n }\n if (props.stride !== undefined) {\n this.stride = props.stride;\n }\n // @ts-expect-error\n if (props.normalize !== undefined) {\n // @ts-expect-error\n this.normalized = props.normalize;\n }\n if (props.normalized !== undefined) {\n this.normalized = props.normalized;\n }\n if (props.integer !== undefined) {\n this.integer = props.integer;\n }\n\n // INSTANCE DIVISOR\n if (props.divisor !== undefined) {\n this.divisor = props.divisor;\n }\n\n // Buffer is optional\n if (props.buffer !== undefined) {\n this.buffer = props.buffer;\n }\n\n // The binding index (for binding e.g. Transform feedbacks and Uniform buffers)\n // TODO - should this be part of accessor?\n if (props.index !== undefined) {\n if (typeof props.index === 'boolean') {\n this.index = props.index ? 1 : 0;\n } else {\n this.index = props.index;\n }\n }\n\n // DEPRECATED\n // @ts-expect-error\n if (props.instanced !== undefined) {\n // @ts-expect-error\n this.divisor = props.instanced ? 1 : 0;\n }\n // @ts-expect-error\n if (props.isInstanced !== undefined) {\n // @ts-expect-error\n this.divisor = props.isInstanced ? 1 : 0;\n }\n\n if (this.offset === undefined) delete this.offset;\n if (this.stride === undefined) delete this.stride;\n if (this.type === undefined) delete this.type;\n if (this.size === undefined) delete this.size;\n if (this.divisor === undefined) delete this.divisor;\n if (this.normalized === undefined) delete this.normalized;\n if (this.integer === undefined) delete this.integer;\n \n if (this.buffer === undefined) delete this.buffer;\n if (this.index === undefined) delete this.index;\n \n return this;\n }\n}\n\n// TEST EXPORTS\nexport {DEFAULT_ACCESSOR_VALUES};\n"],"file":"accessor.js"}
1
+ {"version":3,"sources":["../../../src/classic/accessor.ts"],"names":["DEFAULT_ACCESSOR_VALUES","offset","stride","type","GL","FLOAT","size","divisor","normalized","integer","PROP_CHECKS","deprecatedProps","instanced","isInstanced","Accessor","accessors","forEach","accessor","_assign","Object","freeze","JSON","stringify","getBytesPerElement","getBytesPerVertex","props","undefined","INT","UNSIGNED_INT","normalize","buffer","index","ArrayType","BYTES_PER_ELEMENT"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AAEA,IAAMA,uBAAuB,GAAG;AAC9BC,EAAAA,MAAM,EAAE,CADsB;AAE9BC,EAAAA,MAAM,EAAE,CAFsB;AAG9BC,EAAAA,IAAI,EAAEC,mBAAGC,KAHqB;AAI9BC,EAAAA,IAAI,EAAE,CAJwB;AAK9BC,EAAAA,OAAO,EAAE,CALqB;AAM9BC,EAAAA,UAAU,EAAE,KANkB;AAO9BC,EAAAA,OAAO,EAAE;AAPqB,CAAhC;;AAUA,IAAMC,WAAW,G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ArrayFromGLType} from './typed-array-utils';\n\nconst DEFAULT_ACCESSOR_VALUES = {\n offset: 0,\n stride: 0,\n type: GL.FLOAT,\n size: 1,\n divisor: 0,\n normalized: false,\n integer: false\n};\n\nconst PROP_CHECKS = {\n deprecatedProps: {\n instanced: 'divisor',\n isInstanced: 'divisor'\n }\n};\n\nexport default class Accessor implements AccessorObject {\n offset?: number;\n stride?: number;\n type?: number;\n size?: number;\n divisor?: number;\n normalized?: boolean;\n integer?: boolean;\n\n buffer?: Buffer;\n index?: number;\n\n static getBytesPerElement(accessor: Accessor | AccessorObject): number {\n // TODO: using `FLOAT` when type is not specified,\n // ensure this assumption is valid or force API to specify type.\n const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);\n return ArrayType.BYTES_PER_ELEMENT;\n }\n\n static getBytesPerVertex(accessor: AccessorObject): number {\n assert(accessor.size);\n // TODO: using `FLOAT` when type is not specified,\n // ensure this assumption is valid or force API to specify type.\n const ArrayType = getTypedArrayFromGLType(accessor.type || GL.FLOAT);\n return ArrayType.BYTES_PER_ELEMENT * accessor.size;\n }\n\n // Combines (merges) a list of accessors. On top of default values\n // Usually [programAccessor, bufferAccessor, appAccessor]\n // All props will be set in the returned object.\n // TODO check for conflicts between values in the supplied accessors\n static resolve(...accessors: AccessorObject[]): Accessor {\n return new Accessor(...[DEFAULT_ACCESSOR_VALUES, ...accessors]); // Default values\n }\n\n constructor(...accessors: AccessorObject[]) {\n accessors.forEach((accessor) => this._assign(accessor)); // Merge in sequence\n Object.freeze(this);\n }\n\n toString(): string {\n return JSON.stringify(this);\n }\n\n // ACCESSORS\n\n // TODO - remove>\n get BYTES_PER_ELEMENT(): number {\n return Accessor.getBytesPerElement(this);\n }\n\n get BYTES_PER_VERTEX(): number {\n return Accessor.getBytesPerVertex(this);\n }\n\n // PRIVATE\n\n // eslint-disable-next-line complexity, max-statements\n _assign(props: AccessorObject = {}): this {\n props = checkProps('Accessor', props, PROP_CHECKS);\n\n if (props.type !== undefined) {\n this.type = props.type;\n\n // Auto-deduce integer type?\n if (props.type === GL.INT || props.type === GL.UNSIGNED_INT) {\n this.integer = true;\n }\n }\n if (props.size !== undefined) {\n this.size = props.size;\n }\n if (props.offset !== undefined) {\n this.offset = props.offset;\n }\n if (props.stride !== undefined) {\n this.stride = props.stride;\n }\n // @ts-expect-error\n if (props.normalize !== undefined) {\n // @ts-expect-error\n this.normalized = props.normalize;\n }\n if (props.normalized !== undefined) {\n this.normalized = props.normalized;\n }\n if (props.integer !== undefined) {\n this.integer = props.integer;\n }\n\n // INSTANCE DIVISOR\n if (props.divisor !== undefined) {\n this.divisor = props.divisor;\n }\n\n // Buffer is optional\n if (props.buffer !== undefined) {\n this.buffer = props.buffer;\n }\n\n // The binding index (for binding e.g. Transform feedbacks and Uniform buffers)\n // TODO - should this be part of accessor?\n if (props.index !== undefined) {\n if (typeof props.index === 'boolean') {\n this.index = props.index ? 1 : 0;\n } else {\n this.index = props.index;\n }\n }\n\n // DEPRECATED\n // @ts-expect-error\n if (props.instanced !== undefined) {\n // @ts-expect-error\n this.divisor = props.instanced ? 1 : 0;\n }\n // @ts-expect-error\n if (props.isInstanced !== undefined) {\n // @ts-expect-error\n this.divisor = props.isInstanced ? 1 : 0;\n }\n\n if (this.offset === undefined) delete this.offset;\n if (this.stride === undefined) delete this.stride;\n if (this.type === undefined) delete this.type;\n if (this.size === undefined) delete this.size;\n if (this.divisor === undefined) delete this.divisor;\n if (this.normalized === undefined) delete this.normalized;\n if (this.integer === undefined) delete this.integer;\n \n if (this.buffer === undefined) delete this.buffer;\n if (this.index === undefined) delete this.index;\n \n return this;\n }\n}\n\n// TEST EXPORTS\nexport {DEFAULT_ACCESSOR_VALUES};\n"],"file":"accessor.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/classic/typed-array-utils.ts"],"names":["ERR_TYPE_DEDUCTION","getGLTypeFromTypedArray","arrayOrType","type","ArrayBuffer","isView","constructor","Float32Array","GL","FLOAT","Uint16Array","UNSIGNED_SHORT","Uint32Array","UNSIGNED_INT","Uint8Array","UNSIGNED_BYTE","Uint8ClampedArray","Int8Array","BYTE","Int16Array","SHORT","Int32Array","INT","Error","getTypedArrayFromGLType","glType","options","clamped","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","flipRows","data","width","height","bytesPerPixel","temp","bytesPerRow","tempBuffer","y","topOffset","bottomOffset","set","subarray","copyWithin","scalePixels","newWidth","Math","round","newHeight","newData","x","c"],"mappings":";;;;;;;;;;;;AACA;;AAGA,IAAMA,kBAAkB,GAAG,+CAA3B;;AAkBO,SAASC,uBAAT,CAAiCC,WAAjC,EAAkE;AAEvE,MAAMC,IAAI,GAAGC,WAAW,CAACC,MAAZ,CAAmBH,WAAnB,IAAkCA,WAAW,CAACI,WAA9C,GAA4DJ,WAAzE;;AACA,UAAQC,IAAR;AACE,SAAKI,YAAL;AACE,aAAOC,mBAAGC,KAAV;;AACF,SAAKC,WAAL;AACE,aAAOF,mBAAGG,cAAV;;AACF,SAAKC,WAAL;AACE,aAAOJ,mBAAGK,YAAV;;AACF,SAAKC,UAAL;AACE,aAAON,mBAAGO,aAAV;;AACF,SAAKC,iBAAL;AACE,aAAOR,mBAAGO,aAAV;;AACF,SAAKE,SAAL;AACE,aAAOT,mBAAGU,IAAV;;AACF,SAAKC,UAAL;AACE,aAAOX,mBAAGY,KAAV;;AACF,SAAKC,UAAL;AACE,aAAOb,mBAAGc,GAAV;;AACF;AACE,YAAM,IAAIC,KAAJ,CAAUvB,kBAAV,CAAN;AAlBJ;AAoBD;;AAUM,SAASwB,uBAAT,CACLC,MADK,EAELC,OAFK,EAKkB;AACvB,aAAyBA,OAAO,IAAI,EAApC;AAAA,0BAAOC,OAAP;AAAA,MAAOA,OAAP,6BAAiB,IAAjB;;AAEA,UAAQF,MAAR;AACE,SAAKjB,mBAAGC,KAAR;AACE,aAAOF,YAAP;;AACF,SAAKC,mBAAGG,cAAR;AACA,SAAKH,m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Array} from '@luma.gl/api/types';\nimport GL from '@luma.gl/constants';\nimport {GLType} from '../types/webgl'\n\nconst ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';\n\ntype TypedArrayConstructor =\n | Float32ArrayConstructor\n | Uint16ArrayConstructor\n | Uint32ArrayConstructor\n | Uint8ArrayConstructor\n | Uint8ClampedArrayConstructor\n | Int8ArrayConstructor\n | Int16ArrayConstructor\n | Int32ArrayConstructor;\n\n/**\n * Converts TYPED ARRAYS to corresponding GL constant\n * Used to auto deduce gl parameter types\n * @param {*} arrayOrType\n * @returns\n */\nexport function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {\n // If typed array, look up constructor\n const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;\n switch (type) {\n case Float32Array:\n return GL.FLOAT;\n case Uint16Array:\n return GL.UNSIGNED_SHORT;\n case Uint32Array:\n return GL.UNSIGNED_INT;\n case Uint8Array:\n return GL.UNSIGNED_BYTE;\n case Uint8ClampedArray:\n return GL.UNSIGNED_BYTE;\n case Int8Array:\n return GL.BYTE;\n case Int16Array:\n return GL.SHORT;\n case Int32Array:\n return GL.INT;\n default:\n throw new Error(ERR_TYPE_DEDUCTION);\n }\n}\n\n/**\n * Converts GL constant to corresponding TYPED ARRAY\n * Used to auto deduce gl parameter types\n * @param {*} glType\n * @param {*} param1\n * @returns\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayFromGLType(\n glType: any,\n options?: {\n clamped?: boolean;\n }\n): TypedArrayConstructor {\n const {clamped = true} = options || {};\n // Sorted in some order of likelihood to reduce amount of comparisons\n switch (glType) {\n case GL.FLOAT:\n return Float32Array;\n case GL.UNSIGNED_SHORT:\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return Uint16Array;\n case GL.UNSIGNED_INT:\n return Uint32Array;\n case GL.UNSIGNED_BYTE:\n return clamped ? Uint8ClampedArray : Uint8Array;\n case GL.BYTE:\n return Int8Array;\n case GL.SHORT:\n return Int16Array;\n case GL.INT:\n return Int32Array;\n default:\n throw new Error('Failed to deduce typed array type from GL constant');\n }\n}\n\n/**\n * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)\n * https: *stackoverflow.com/questions/41969562/\n * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels\n * @param {*} param0\n */\n export function flipRows(options: {\n data: any;\n width: any;\n height: any;\n bytesPerPixel?: number;\n temp?: any;\n}): void {\n const {data, width, height, bytesPerPixel = 4, temp} = options;\n const bytesPerRow = width * bytesPerPixel;\n\n // make a temp buffer to hold one row\n const tempBuffer = temp || new Uint8Array(bytesPerRow);\n for (let y = 0; y < height / 2; ++y) {\n const topOffset = y * bytesPerRow;\n const bottomOffset = (height - y - 1) * bytesPerRow;\n // make copy of a row on the top half\n tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));\n // copy a row from the bottom half to the top\n data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);\n // copy the copy of the top half row to the bottom half\n data.set(tempBuffer, bottomOffset);\n }\n}\n\n\nexport function scalePixels(options: {\n data: any;\n width: any;\n height: any;\n}): {\n data: Uint8Array;\n width: number;\n height: number;\n} {\n const {data, width, height} = options;\n const newWidth = Math.round(width / 2);\n const newHeight = Math.round(height / 2);\n const newData = new Uint8Array(newWidth * newHeight * 4);\n for (let y = 0; y < newHeight; y++) {\n for (let x = 0; x < newWidth; x++) {\n for (let c = 0; c < 4; c++) {\n newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];\n }\n }\n }\n return {data: newData, width: newWidth, height: newHeight};\n}\n"],"file":"typed-array-utils.js"}
1
+ {"version":3,"sources":["../../../src/classic/typed-array-utils.ts"],"names":["ERR_TYPE_DEDUCTION","getGLTypeFromTypedArray","arrayOrType","type","ArrayBuffer","isView","constructor","Float32Array","GL","FLOAT","Uint16Array","UNSIGNED_SHORT","Uint32Array","UNSIGNED_INT","Uint8Array","UNSIGNED_BYTE","Uint8ClampedArray","Int8Array","BYTE","Int16Array","SHORT","Int32Array","INT","Error","getTypedArrayFromGLType","glType","options","clamped","UNSIGNED_SHORT_5_6_5","UNSIGNED_SHORT_4_4_4_4","UNSIGNED_SHORT_5_5_5_1","flipRows","data","width","height","bytesPerPixel","temp","bytesPerRow","tempBuffer","y","topOffset","bottomOffset","set","subarray","copyWithin","scalePixels","newWidth","Math","round","newHeight","newData","x","c"],"mappings":";;;;;;;;;;;;AAGA;;AAGA,IAAMA,kBAAkB,GAAG,+CAA3B;;AAkBO,SAASC,uBAAT,CAAiCC,WAAjC,EAAkE;AAEvE,MAAMC,IAAI,GAAGC,WAAW,CAACC,MAAZ,CAAmBH,WAAnB,IAAkCA,WAAW,CAACI,WAA9C,GAA4DJ,WAAzE;;AACA,UAAQC,IAAR;AACE,SAAKI,YAAL;AACE,aAAOC,mBAAGC,KAAV;;AACF,SAAKC,WAAL;AACE,aAAOF,mBAAGG,cAAV;;AACF,SAAKC,WAAL;AACE,aAAOJ,mBAAGK,YAAV;;AACF,SAAKC,UAAL;AACE,aAAON,mBAAGO,aAAV;;AACF,SAAKC,iBAAL;AACE,aAAOR,mBAAGO,aAAV;;AACF,SAAKE,SAAL;AACE,aAAOT,mBAAGU,IAAV;;AACF,SAAKC,UAAL;AACE,aAAOX,mBAAGY,KAAV;;AACF,SAAKC,UAAL;AACE,aAAOb,mBAAGc,GAAV;;AACF;AACE,YAAM,IAAIC,KAAJ,CAAUvB,kBAAV,CAAN;AAlBJ;AAoBD;;AAUM,SAASwB,uBAAT,CACLC,MADK,EAELC,OAFK,EAKkB;AACvB,aAAyBA,OAAO,IAAI,EAApC;AAAA,0BAAOC,OAAP;AAAA,MAAOA,OAAP,6BAAiB,IAAjB;;AAEA,UAAQF,MAAR;AACE,SAAKjB,mBAAGC,KAAR;AACE,aAAOF,YAAP;;AACF,SAAKC,mBAAGG,cAAR;AACA,SAAKH,mBAAGoB,oBAAR;A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ypedArray} from '@luma.gl/api';\nimport GL from '@luma.gl/constants';\nimport {GLType} from '../types/webgl'\n\nconst ERR_TYPE_DEDUCTION = 'Failed to deduce GL constant from typed array';\n\ntype TypedArrayConstructor =\n | Float32ArrayConstructor\n | Uint16ArrayConstructor\n | Uint32ArrayConstructor\n | Uint8ArrayConstructor\n | Uint8ClampedArrayConstructor\n | Int8ArrayConstructor\n | Int16ArrayConstructor\n | Int32ArrayConstructor;\n\n/**\n * Converts TYPED ARRAYS to corresponding GL constant\n * Used to auto deduce gl parameter types\n * @param {*} arrayOrType\n * @returns\n */\nexport function getGLTypeFromTypedArray(arrayOrType: TypedArray): GLType {\n // If typed array, look up constructor\n const type = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;\n switch (type) {\n case Float32Array:\n return GL.FLOAT;\n case Uint16Array:\n return GL.UNSIGNED_SHORT;\n case Uint32Array:\n return GL.UNSIGNED_INT;\n case Uint8Array:\n return GL.UNSIGNED_BYTE;\n case Uint8ClampedArray:\n return GL.UNSIGNED_BYTE;\n case Int8Array:\n return GL.BYTE;\n case Int16Array:\n return GL.SHORT;\n case Int32Array:\n return GL.INT;\n default:\n throw new Error(ERR_TYPE_DEDUCTION);\n }\n}\n\n/**\n * Converts GL constant to corresponding TYPED ARRAY\n * Used to auto deduce gl parameter types\n * @param {*} glType\n * @param {*} param1\n * @returns\n */\n// eslint-disable-next-line complexity\nexport function getTypedArrayFromGLType(\n glType: any,\n options?: {\n clamped?: boolean;\n }\n): TypedArrayConstructor {\n const {clamped = true} = options || {};\n // Sorted in some order of likelihood to reduce amount of comparisons\n switch (glType) {\n case GL.FLOAT:\n return Float32Array;\n case GL.UNSIGNED_SHORT:\n case GL.UNSIGNED_SHORT_5_6_5:\n case GL.UNSIGNED_SHORT_4_4_4_4:\n case GL.UNSIGNED_SHORT_5_5_5_1:\n return Uint16Array;\n case GL.UNSIGNED_INT:\n return Uint32Array;\n case GL.UNSIGNED_BYTE:\n return clamped ? Uint8ClampedArray : Uint8Array;\n case GL.BYTE:\n return Int8Array;\n case GL.SHORT:\n return Int16Array;\n case GL.INT:\n return Int32Array;\n default:\n throw new Error('Failed to deduce typed array type from GL constant');\n }\n}\n\n/**\n * Flip rows (can be used on arrays returned from `Framebuffer.readPixels`)\n * https: *stackoverflow.com/questions/41969562/\n * how-can-i-flip-the-result-of-webglrenderingcontext-readpixels\n * @param {*} param0\n */\n export function flipRows(options: {\n data: any;\n width: any;\n height: any;\n bytesPerPixel?: number;\n temp?: any;\n}): void {\n const {data, width, height, bytesPerPixel = 4, temp} = options;\n const bytesPerRow = width * bytesPerPixel;\n\n // make a temp buffer to hold one row\n const tempBuffer = temp || new Uint8Array(bytesPerRow);\n for (let y = 0; y < height / 2; ++y) {\n const topOffset = y * bytesPerRow;\n const bottomOffset = (height - y - 1) * bytesPerRow;\n // make copy of a row on the top half\n tempBuffer.set(data.subarray(topOffset, topOffset + bytesPerRow));\n // copy a row from the bottom half to the top\n data.copyWithin(topOffset, bottomOffset, bottomOffset + bytesPerRow);\n // copy the copy of the top half row to the bottom half\n data.set(tempBuffer, bottomOffset);\n }\n}\n\n\nexport function scalePixels(options: {\n data: any;\n width: any;\n height: any;\n}): {\n data: Uint8Array;\n width: number;\n height: number;\n} {\n const {data, width, height} = options;\n const newWidth = Math.round(width / 2);\n const newHeight = Math.round(height / 2);\n const newData = new Uint8Array(newWidth * newHeight * 4);\n for (let y = 0; y < newHeight; y++) {\n for (let x = 0; x < newWidth; x++) {\n for (let c = 0; c < 4; c++) {\n newData[(y * newWidth + x) * 4 + c] = data[(y * 2 * width + x * 2) * 4 + c];\n }\n }\n }\n return {data: newData, width: newWidth, height: newHeight};\n}\n"],"file":"typed-array-utils.js"}
@@ -63,13 +63,21 @@ function createBrowserContext(canvas, props) {
63
63
  }
64
64
 
65
65
  if (props.onContextLost) {
66
- canvas.addEventListener('webglcontextlost', props.onContextLost, false);
66
+ var _props = props,
67
+ onContextLost = _props.onContextLost;
68
+ canvas.addEventListener('webglcontextlost', function (event) {
69
+ return onContextLost(event);
70
+ }, false);
67
71
  }
68
72
 
69
73
  if (props.onContextRestored) {
70
- canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);
74
+ var _props2 = props,
75
+ onContextRestored = _props2.onContextRestored;
76
+ canvas.addEventListener('webglcontextrestored', function (event) {
77
+ return onContextRestored(event);
78
+ }, false);
71
79
  }
72
80
 
73
81
  return gl;
74
82
  }
75
- //# sourceMappingURL=create-context.js.map
83
+ //# sourceMappingURL=create-browser-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/context/context/create-browser-context.ts"],"names":["DEFAULT_CONTEXT_PROPS","webgl2","webgl1","powerPreference","onContextLost","console","error","onContextRestored","info","createBrowserContext","canvas","props","errorMessage","onCreateError","statusMessage","addEventListener","gl","type","getContext","removeEventListener","Error","event"],"mappings":";;;;;;;;;;;;;;;AAmCA,IAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE;AAAA,WAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAAN;AAAA,GAJ2B;AAK1CC,EAAAA,iBAAiB,EAAE;AAAA,WAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb,CAAN;AAAA;AALuB,CAA5C;;AAaQ,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,mCAAOX,qBAAP,GAAiCW,KAAjC,CAAL;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,MAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACP,KAAD;AAAA,WAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAlD;AAAA,GAAtB;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;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D,UAACM,KAAD;AAAA,aAAkBd,iBAAiB,CAACc,KAAD,CAAnC;AAAA,KAAhD,EAA4F,KAA5F;AACD;;AAED,SAAOL,EAAP;AACD","sourcesContent":["// luma.gl, MIT license\n\n/**\n * ContextProps\n* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)\n* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)\n* @param onContextLost\n* @param onContextRestored\n*\n* BROWSER CONTEXT PARAMETERS\n* @param debug Instrument context (at the expense of performance).\n* @param alpha Default render target has an alpha buffer.\n* @param depth Default render target has a depth buffer of at least 16 bits.\n* @param stencil Default render target has a stencil buffer of at least 8 bits.\n* @param antialias Boolean that indicates whether or not to perform anti-aliasing.\n* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten\n* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.\n*/\ntype ContextProps = {\n type?: 'webgl' | 'webgl1' | 'webgl2' | string;\n webgl1?: boolean;\n webgl2?: boolean;\n onContextLost?: (event: Event) => void;\n onContextRestored?: (event: Event) => void;\n alpha?: boolean; // indicates if the canvas contains an alpha buffer.\n desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop\n antialias?: boolean; // indicates whether or not to perform anti-aliasing.\n depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.\n failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.\n powerPreference?: 'default' | 'high-performance' | 'low-power',\n premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.\n preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.\n};\n\nconst DEFAULT_CONTEXT_PROPS: ContextProps = {\n webgl2: true, // Attempt to create a WebGL2 context\n webgl1: true, // Attempt to create a WebGL1 context (false to fail if webgl2 not available)\n powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons\n onContextLost: () => console.error('WebGL context lost'),\n onContextRestored: () => console.info('WebGL context restored'),\n};\n\n/**\n * Create a WebGL context for a canvas\n * Note calling this multiple time on the same canvas does return the same context\n* @param canvas A canvas element or offscreen canvas\n */\n export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n // Create the desired context\n let gl: WebGLRenderingContext | null = null;\n\n if (props.type === 'webgl2') {\n props = {...props, webgl1: false};\n }\n if (props.type === 'webgl1') {\n props = {...props, webgl2: false};\n }\n\n // Prefer webgl2 over webgl1 if both are acceptable\n if (props.webgl2) {\n gl = gl || canvas.getContext('webgl2', props) as WebGL2RenderingContext | null;\n }\n if (props.webgl1) {\n gl = gl || canvas.getContext('webgl', props) as WebGLRenderingContext | null;\n }\n\n // TODO are we removing this listener before giving it a chance to fire?\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n if (!gl) {\n throw new Error(\n `Failed to create ${props.webgl2 && !props.webgl1 ? 'WebGL2' : 'WebGL'} context: ${\n errorMessage || 'Unknown error'\n }`\n );\n }\n\n if (props.onContextLost) {\n // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.\n const {onContextLost} = props;\n canvas.addEventListener('webglcontextlost',(event: Event) => onContextLost(event), false);\n }\n if (props.onContextRestored) {\n // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.\n const {onContextRestored} = props;\n canvas.addEventListener('webglcontextrestored', (event: Event) => onContextRestored(event), false);\n }\n\n return gl;\n}\n\n/* TODO - can we call this asynchronously to catch the error events?\nexport async function createBrowserContextAsync(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): Promise<WebGLRenderingContext> {\n props = {...DEFAULT_CONTEXT_PROPS, ...props};\n\n // Try to extract any extra information about why context creation failed\n let errorMessage = null;\n const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);\n canvas.addEventListener('webglcontextcreationerror', onCreateError, false);\n\n const gl = createBrowserContext(canvas, props);\n\n // Give the listener a chance to fire\n await new Promise(resolve => setTimeout(resolve, 0));\n\n canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);\n\n return gl;\n}\n*/\n"],"file":"create-browser-context.js"}
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.registerHeadlessGL = registerHeadlessGL;
9
+ exports.isHeadlessGLRegistered = isHeadlessGLRegistered;
10
+ exports.createHeadlessContext = createHeadlessContext;
11
+
12
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
+
14
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
15
+
16
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
17
+
18
+ var ERR_HEADLESSGL_FAILED = 'Failed to create WebGL context in Node.js, headless gl returned null';
19
+ var ERR_HEADLESSGL_LOAD = " luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL contexts can not be created. This may not be an error. For example, this is a typical configuration for isorender applications running on the server.";
20
+ var CONTEXT_DEFAULTS = {
21
+ width: 1,
22
+ height: 1,
23
+ debug: true,
24
+ throwOnError: false
25
+ };
26
+ var headlessGL = null;
27
+
28
+ function registerHeadlessGL(headlessgl) {
29
+ headlessGL = headlessgl;
30
+ }
31
+
32
+ function isHeadlessGLRegistered() {
33
+ return headlessGL !== null;
34
+ }
35
+
36
+ function createHeadlessContext(options) {
37
+ options = _objectSpread(_objectSpread({}, CONTEXT_DEFAULTS), options);
38
+ var _options = options,
39
+ width = _options.width,
40
+ height = _options.height,
41
+ webgl1 = _options.webgl1,
42
+ webgl2 = _options.webgl2;
43
+
44
+ if (webgl2 && !webgl1) {
45
+ throw new Error('headless-gl does not support WebGL2');
46
+ }
47
+
48
+ if (!headlessGL) {
49
+ throw new Error(ERR_HEADLESSGL_LOAD);
50
+ }
51
+
52
+ var gl = headlessGL(width, height, options);
53
+
54
+ if (!gl) {
55
+ throw new Error(ERR_HEADLESSGL_FAILED);
56
+ }
57
+
58
+ return gl;
59
+ }
60
+ //# sourceMappingURL=create-headless-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/context/context/create-headless-context.ts"],"names":["ERR_HEADLESSGL_FAILED","ERR_HEADLESSGL_LOAD","CONTEXT_DEFAULTS","width","height","debug","throwOnError","headlessGL","registerHeadlessGL","headlessgl","isHeadlessGLRegistered","createHeadlessContext","options","webgl1","webgl2","Error","gl"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAMA,qBAAqB,GACzB,sEADF;AAGA,IAAMC,mBAAmB,gPAAzB;AAKA,IAAMC,gBAAgB,GAAG;AACvBC,EAAAA,KAAK,EAAE,CADgB;AAEvBC,EAAAA,MAAM,EAAE,CAFe;AAGvBC,EAAAA,KAAK,EAAE,IAHgB;AAIvBC,EAAAA,YAAY,EAAE;AAJS,CAAzB;AAUA,IAAIC,UAA6B,GAAG,IAApC;;AAGO,SAASC,kBAAT,CAA4BC,UAA5B,EAAoD;AACzDF,EAAAA,UAAU,GAAGE,UAAb;AACD;;AAGM,SAASC,sBAAT,GAA2C;AAChD,SAAOH,UAAU,KAAK,IAAtB;AACD;;AAGM,SAASI,qBAAT,CAA+BC,OAA/B,EAAqF;AAC1FA,EAAAA,OAAO,mCAAOV,gBAAP,GAA4BU,OAA5B,CAAP;AAEA,iBAAwCA,OAAxC;AAAA,MAAOT,KAAP,YAAOA,KAAP;AAAA,MAAcC,MAAd,YAAcA,MAAd;AAAA,MAAsBS,MAAtB,YAAsBA,MAAtB;AAAA,MAA8BC,MAA9B,YAA8BA,MAA9B;;AAEA,MAAIA,MAAM,IAAI,CAACD,MAAf,EAAuB;AACrB,UAAM,IAAIE,KAAJ,CAAU,qCAAV,CAAN;AACD;;AACD,MAAI,CAACR,UAAL,EAAiB;AACf,UAAM,IAAIQ,KAAJ,CAAUd,mBAAV,CAAN;AACD;;AACD,MAAMe,EAAE,GAAGT,UAAU,CAACJ,KAAD,EAAQC,MAAR,EAAgBQ,OAAhB,CAArB;;AACA,MAAI,CAACI,EAAL,EAAS;AACP,UAAM,IAAID,KAAJ,CAAUf,qBAAV,CAAN;AACD;;AACD,SAAOgB,EAAP;AACD","sourcesContent":["const ERR_HEADLESSGL_FAILED =\n 'Failed to create WebGL context in Node.js, headless gl returned null';\n\nconst ERR_HEADLESSGL_LOAD = `\\\n luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \\\n contexts can not be created. This may not be an error. For example, this is a \\\n typical configuration for isorender applications running on the server.`;\n\nconst CONTEXT_DEFAULTS = {\n width: 1,\n height: 1,\n debug: true,\n throwOnError: false\n};\n\n/** Duck typing for the main headless gl export, a function to create contexts */\nexport type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;\n\nlet headlessGL: HeadlessGL | null = null; \n\n/** By importing `gl` and registering it with this function, contexts can be created under Node.js */\nexport function registerHeadlessGL(headlessgl: HeadlessGL) {\n headlessGL = headlessgl;\n}\n\n/** @returns true if headless gl is registered */\nexport function isHeadlessGLRegistered(): boolean {\n return headlessGL !== null;\n}\n\n/** Create headless gl context (for running under Node.js) */\nexport function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext {\n options = {...CONTEXT_DEFAULTS, ...options};\n\n const {width, height, webgl1, webgl2} = options;\n\n if (webgl2 && !webgl1) {\n throw new Error('headless-gl does not support WebGL2');\n }\n if (!headlessGL) {\n throw new Error(ERR_HEADLESSGL_LOAD);\n }\n const gl = headlessGL(width, height, options);\n if (!gl) {\n throw new Error(ERR_HEADLESSGL_FAILED);\n }\n return gl;\n}\n"],"file":"create-headless-context.js"}
@@ -151,7 +151,7 @@ function onGLError(props, err, functionName, args) {
151
151
  }
152
152
 
153
153
  function onValidateGLFunc(props, functionName, functionArgs) {
154
- var functionString;
154
+ var functionString = '';
155
155
 
156
156
  if (_api.log.level >= 1) {
157
157
  functionString = getFunctionString(functionName, functionArgs);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/context/debug/webgl-developer-tools.ts"],"names":["WEBGL_DEBUG_CDN_URL","DEFAULT_DEBUG_CONTEXT_PROPS","debug","throwOnError","break","webgl2","getContextData","gl","luma","loadWebGLDeveloperTools","globalThis","WebGLDebugUtils","global","module","makeDebugContext","props","getDebugContext","getRealContext","data","realContext","log","warn","debugContext","init","GL","glDebug","onGLError","bind","onValidateGLFunc","key","WebGLDebugContext","Object","setPrototypeOf","getPrototypeOf","create","getFunctionString","functionName","functionArgs","Array","from","map","arg","undefined","args","glFunctionArgsToString","slice","length","err","errorMessage","glEnumToString","glName","message","error","Error","functionString","level","isBreakpoint","every","breakOn","indexOf"],"mappings":";;;;;;;;;;;;;;;;;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,mBAAmB,GAAG,8CAA5B;AASA,IAAMC,2BAAwD,GAAG;AAC/DC,EAAAA,KAAK,EAAE,IADwD;AAE/DC,EAAAA,YAAY,EAAE,KAFiD;AAG/DC,EAAAA,KAAK,EAAE,EAHwD;AAI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AAQ,CAAR,EAAWkC,cAAX;AACD;;AAED,MAAIvC,KAAK,CAACX,KAAV,EAAiB;AACfkD,IAAAA,cAAc,GAAGA,cAAc,IAAInB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;AACA,QAAMmB,YAAY,GAChBzC,KAAK,CAACX,KAAN,IAAeW,KAAK,CAACX,KAAN,CAAYqD,KAAZ,CAAkB,UAACC,OAAD;AAAA,aAAqBJ,cAAc,CAACK,OAAf,CAAuBD,OAAvB,MAAoC,CAAC,CAA1D;AAAA,KAAlB,CADjB;;AAEA,QAAIF,YAAJ,EAAkB;AAChB;AACD;AACF;;AAdkG,6CAgBjFnB,YAhBiF;AAAA;;AAAA;AAgBnG,wDAAgC;AAAA,UAArBI,GAAqB;;AAC9B,UAAIA,GAAG,KAAKC,SAAZ,EAAuB;AACrBY,QAAAA,cAAc,GAAGA,cAAc,IAAInB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;;AACA,YAAItB,KAAK,CAACZ,YAAV,EAAwB;AACtB,gBAAM,IAAIkD,KAAJ,+BAAiCC,cAAjC,EAAN;AACD,SAFD,MAEO;AACLlC,mBAAIgC,KAAJ,+BAAiCE,cAAjC;;AACA;AACD;AACF;AACF;AA1BkG;AAAA;AAAA;AAAA;AAAA;AA2BpG","sourcesContent":["// luma.gl, MIT license\nimport {log, loadScript} from '@luma.gl/api/';\nimport GL from '@luma.gl/constants';\n\nconst WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';\n\ntype DebugContextProps = {\n debug?: boolean;\n throwOnError?: boolean;\n break?: string[];\n webgl2?: boolean;\n};\n\nconst DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {\n debug: true,\n throwOnError: false,\n break: [],\n webgl2: false,\n}\n\n// Helper to get shared context data\nfunction getContextData(gl: any) {\n gl.luma = gl.luma || {};\n return gl.luma;\n}\n\ndeclare global {\n var WebGLDebugUtils: any;\n}\n\n/**\n * Loads Khronos WebGLDeveloperTools from CDN if not already installed \n * const WebGLDebugUtils = require('webgl-debug');\n * @see https://github.com/KhronosGroup/WebGLDeveloperTools\n * @see https://github.com/vorg/webgl-debug\n */\nexport async function loadWebGLDeveloperTools(): Promise<void> {\n if (!globalThis.WebGLDebugUtils) {\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global = globalThis.global || globalThis;\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global.module = {};\n await loadScript(WEBGL_DEBUG_CDN_URL);\n }\n}\n\n// Returns (a potentially new) context with debug instrumentation turned off or on.\n// Note that this actually returns a new context\nexport function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext {\n // Return null to ensure we don't try to create a context in this case (TODO what case is that?)\n if (!gl) {\n return null;\n }\n\n return props.debug ? getDebugContext(gl, props) : getRealContext(gl);\n}\n\n// Returns the real context from either of the real/debug contexts\nfunction getRealContext(gl: WebGLRenderingContext): WebGLRenderingContext {\n const data = getContextData(gl);\n // If the context has a realContext member, it is a debug context so return the realContext\n return data.realContext ? data.realContext : gl;\n}\n\n// Returns the debug context from either of the real/debug contexts\nfunction getDebugContext(gl: WebGLRenderingContext, props: DebugContextProps): WebGLRenderingContext {\n if (!globalThis.WebGLDebugUtils) {\n log.warn('webgl-debug not loaded')();\n return gl;\n }\n\n const data = getContextData(gl);\n\n // If this already has a debug context, return it.\n if (data.debugContext) {\n return data.debugContext;\n }\n\n // Create a new debug context\n globalThis.WebGLDebugUtils.init({...GL, ...gl});\n const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(\n gl,\n onGLError.bind(null, props),\n onValidateGLFunc.bind(null, props)\n );\n\n // Make sure we have all WebGL2 and extension constants (todo dynamic import to circumvent minification?)\n for (const key in GL) {\n if (!(key in glDebug) && typeof GL[key] === 'number') {\n glDebug[key] = GL[key];\n }\n }\n \n // Ensure we have a clean prototype on the instrumented object\n // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction\n // by synchronizing the WebGL errors after each WebGL call.\n class WebGLDebugContext {}\n Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));\n Object.setPrototypeOf(WebGLDebugContext, glDebug);\n const debugContext = Object.create(WebGLDebugContext);\n // Store the debug context\n data.realContext = gl;\n data.debugContext = debugContext;\n debugContext.debug = true;\n\n // Return it\n return debugContext;\n}\n\n// DEBUG TRACING\n\nfunction getFunctionString(functionName: string, functionArgs): string {\n // Cover bug in webgl-debug-tools\n functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg);\n let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);\n args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;\n return `gl.${functionName}(${args})`;\n}\n\nfunction onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {\n // Cover bug in webgl-debug-tools\n args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);\n const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);\n const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);\n const glName = props.webgl2 ? 'gl2' : 'gl1';\n const message = `${errorMessage} in ${glName}.${functionName}(${functionArgs})`;\n log.error(message)();\n debugger; // eslint-disable-line\n if (props.throwOnError) {\n throw new Error(message);\n }\n}\n\n// Don't generate function string until it is needed\nfunction onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {\n let functionString: string;\n if (log.level >= 1) {\n functionString = getFunctionString(functionName, functionArgs);\n log.log(1, functionString)();\n }\n\n if (props.break) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n const isBreakpoint =\n props.break && props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1);\n if (isBreakpoint) {\n debugger; // eslint-disable-line\n }\n }\n\n for (const arg of functionArgs) {\n if (arg === undefined) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n if (props.throwOnError) {\n throw new Error(`Undefined argument: ${functionString}`);\n } else {\n log.error(`Undefined argument: ${functionString}`)();\n debugger; // eslint-disable-line\n }\n }\n }\n}\n"],"file":"webgl-developer-tools.js"}
1
+ {"version":3,"sources":["../../../../src/context/debug/webgl-developer-tools.ts"],"names":["WEBGL_DEBUG_CDN_URL","DEFAULT_DEBUG_CONTEXT_PROPS","debug","throwOnError","break","webgl2","getContextData","gl","luma","loadWebGLDeveloperTools","globalThis","WebGLDebugUtils","global","module","makeDebugContext","props","getDebugContext","getRealContext","data","realContext","log","warn","debugContext","init","GL","glDebug","onGLError","bind","onValidateGLFunc","key","WebGLDebugContext","Object","setPrototypeOf","getPrototypeOf","create","getFunctionString","functionName","functionArgs","Array","from","map","arg","undefined","args","glFunctionArgsToString","slice","length","err","errorMessage","glEnumToString","glName","message","error","Error","functionString","level","isBreakpoint","every","breakOn","indexOf"],"mappings":";;;;;;;;;;;;;;;;;;AACA;;AACA;;;;;;;;;;;;AAEA,IAAMA,mBAAmB,GAAG,8CAA5B;AASA,IAAMC,2BAAwD,GAAG;AAC/DC,EAAAA,KAAK,EAAE,IADwD;AAE/DC,EAAAA,YAAY,EAAE,KAFiD;AAG/DC,EAAAA,KAAK,EAAE,EAHwD;AAI/DC,EAAAA,MAAM,EAAE;AAJuD,CAAjE;;AAQA,SAASC,cAAT,CAAwBC,EAAxB,EAAiC;AAC/BA,EAAAA,EAAE,CAACC,IAAH,GAAUD,EAAE,CAACC,IAAH,IAAW,EAArB;AACA,SAAOD,EAAE,CAACC,IAAV;AACD;;SAYqBC,uB;;;;;uFAAf;AAAA;AAAA;AAAA;AAAA;AAAA,gBACAC,UAAU,CAACC,eADX;AAAA;AAAA;AAAA;;AAGHD,YAAAA,UAAU,CAACE,MAAX,GAAoBF,UAAU,CAACE,MAAX,IAAqBF,UAAzC;AAEAA,YAAAA,UAAU,CAACE,MAAX,CAAkBC,MAAlB,GAA2B,EAA3B;AALG;AAAA,mBAMG,qBAAWb,mBAAX,CANH;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,G;;;;AAYA,SAASc,gBAAT,CA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Y,QAAAA,cAAc,GAAGA,cAAc,IAAInB,iBAAiB,CAACC,YAAD,EAAeC,YAAf,CAApD;;AACA,YAAItB,KAAK,CAACZ,YAAV,EAAwB;AACtB,gBAAM,IAAIkD,KAAJ,+BAAiCC,cAAjC,EAAN;AACD,SAFD,MAEO;AACLlC,mBAAIgC,KAAJ,+BAAiCE,cAAjC;;AACA;AACD;AACF;AACF;AA1BkG;AAAA;AAAA;AAAA;AAAA;AA2BpG","sourcesContent":["// luma.gl, MIT license\nimport {log, loadScript} from '@luma.gl/api/';\nimport GL from '@luma.gl/constants';\n\nconst WEBGL_DEBUG_CDN_URL = 'https://unpkg.com/webgl-debug@2.0.1/index.js';\n\ntype DebugContextProps = {\n debug?: boolean;\n throwOnError?: boolean;\n break?: string[];\n webgl2?: boolean;\n};\n\nconst DEFAULT_DEBUG_CONTEXT_PROPS: Required<DebugContextProps> = {\n debug: true,\n throwOnError: false,\n break: [],\n webgl2: false,\n}\n\n// Helper to get shared context data\nfunction getContextData(gl: any) {\n gl.luma = gl.luma || {};\n return gl.luma;\n}\n\ndeclare global {\n var WebGLDebugUtils: any;\n}\n\n/**\n * Loads Khronos WebGLDeveloperTools from CDN if not already installed \n * const WebGLDebugUtils = require('webgl-debug');\n * @see https://github.com/KhronosGroup/WebGLDeveloperTools\n * @see https://github.com/vorg/webgl-debug\n */\nexport async function loadWebGLDeveloperTools(): Promise<void> {\n if (!globalThis.WebGLDebugUtils) {\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global = globalThis.global || globalThis;\n // @ts-expect-error Developer tools expects global to be set\n globalThis.global.module = {};\n await loadScript(WEBGL_DEBUG_CDN_URL);\n }\n}\n\n// Returns (a potentially new) context with debug instrumentation turned off or on.\n// Note that this actually returns a new context\nexport function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext | null {\n // Return null to ensure we don't try to create a context in this case (TODO what case is that?)\n if (!gl) {\n return null;\n }\n\n return props.debug ? getDebugContext(gl, props) : getRealContext(gl);\n}\n\n// Returns the real context from either of the real/debug contexts\nfunction getRealContext(gl: WebGLRenderingContext): WebGLRenderingContext {\n const data = getContextData(gl);\n // If the context has a realContext member, it is a debug context so return the realContext\n return data.realContext ? data.realContext : gl;\n}\n\n// Returns the debug context from either of the real/debug contexts\nfunction getDebugContext(gl: WebGLRenderingContext, props: DebugContextProps): WebGLRenderingContext {\n if (!globalThis.WebGLDebugUtils) {\n log.warn('webgl-debug not loaded')();\n return gl;\n }\n\n const data = getContextData(gl);\n\n // If this already has a debug context, return it.\n if (data.debugContext) {\n return data.debugContext;\n }\n\n // Create a new debug context\n globalThis.WebGLDebugUtils.init({...GL, ...gl});\n const glDebug = globalThis.WebGLDebugUtils.makeDebugContext(\n gl,\n onGLError.bind(null, props),\n onValidateGLFunc.bind(null, props)\n );\n\n // Make sure we have all WebGL2 and extension constants (todo dynamic import to circumvent minification?)\n for (const key in GL) {\n if (!(key in glDebug) && typeof GL[key] === 'number') {\n glDebug[key] = GL[key];\n }\n }\n \n // Ensure we have a clean prototype on the instrumented object\n // Note: setPrototypeOf does come with perf warnings, but we already take a bigger perf reduction\n // by synchronizing the WebGL errors after each WebGL call.\n class WebGLDebugContext {}\n Object.setPrototypeOf(glDebug, Object.getPrototypeOf(gl));\n Object.setPrototypeOf(WebGLDebugContext, glDebug);\n const debugContext = Object.create(WebGLDebugContext);\n // Store the debug context\n data.realContext = gl;\n data.debugContext = debugContext;\n debugContext.debug = true;\n\n // Return it\n return debugContext;\n}\n\n// DEBUG TRACING\n\nfunction getFunctionString(functionName: string, functionArgs): string {\n // Cover bug in webgl-debug-tools\n functionArgs = Array.from(functionArgs).map(arg => arg === undefined ? 'undefined' : arg);\n let args = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, functionArgs);\n args = `${args.slice(0, 100)}${args.length > 100 ? '...' : ''}`;\n return `gl.${functionName}(${args})`;\n}\n\nfunction onGLError(props: DebugContextProps, err, functionName: string, args: any[]): void {\n // Cover bug in webgl-debug-tools\n args = Array.from(args).map(arg => arg === undefined ? 'undefined' : arg);\n const errorMessage = globalThis.WebGLDebugUtils.glEnumToString(err);\n const functionArgs = globalThis.WebGLDebugUtils.glFunctionArgsToString(functionName, args);\n const glName = props.webgl2 ? 'gl2' : 'gl1';\n const message = `${errorMessage} in ${glName}.${functionName}(${functionArgs})`;\n log.error(message)();\n debugger; // eslint-disable-line\n if (props.throwOnError) {\n throw new Error(message);\n }\n}\n\n// Don't generate function string until it is needed\nfunction onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {\n let functionString: string = '';\n if (log.level >= 1) {\n functionString = getFunctionString(functionName, functionArgs);\n log.log(1, functionString)();\n }\n\n if (props.break) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n const isBreakpoint =\n props.break && props.break.every((breakOn: string) => functionString.indexOf(breakOn) !== -1);\n if (isBreakpoint) {\n debugger; // eslint-disable-line\n }\n }\n\n for (const arg of functionArgs) {\n if (arg === undefined) {\n functionString = functionString || getFunctionString(functionName, functionArgs);\n if (props.throwOnError) {\n throw new Error(`Undefined argument: ${functionString}`);\n } else {\n log.error(`Undefined argument: ${functionString}`)();\n debugger; // eslint-disable-line\n }\n }\n }\n}\n"],"file":"webgl-developer-tools.js"}
@@ -48,7 +48,6 @@ function initializeExtensions(gl) {
48
48
  var extensionName = _step.value;
49
49
  var extension = gl.getExtension(extensionName);
50
50
  contextState._extensions[extensionName] = extension;
51
- contextState[extensionName] = extension;
52
51
  }
53
52
  } catch (err) {
54
53
  _iterator.e(err);