@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
@@ -369,14 +369,16 @@ export default class WEBGLRenderPipeline extends RenderPipeline {
369
369
  /** Get the primitive type for transform feedback */
370
370
  function getDrawMode(
371
371
  topology: PrimitiveTopology
372
- ): GL.POINTS | GL.LINES | GL.LINE_STRIP | GL.TRIANGLES | GL.TRIANGLE_STRIP {
372
+ ): GL.POINTS | GL.LINES | GL.LINE_STRIP | GL.LINE_LOOP | GL.TRIANGLES | GL.TRIANGLE_STRIP | GL.TRIANGLE_FAN {
373
373
  // prettier-ignore
374
374
  switch (topology) {
375
375
  case 'point-list': return GL.POINTS;
376
376
  case 'line-list': return GL.LINES;
377
377
  case 'line-strip': return GL.LINE_STRIP;
378
+ case 'line-loop': return GL.LINE_LOOP;
378
379
  case 'triangle-list': return GL.TRIANGLES;
379
380
  case 'triangle-strip': return GL.TRIANGLE_STRIP;
381
+ case 'triangle-fan': return GL.TRIANGLE_FAN;
380
382
  default: throw new Error(topology);
381
383
  }
382
384
  }
@@ -388,8 +390,10 @@ function getGLPrimitive(topology: PrimitiveTopology): GL.POINTS | GL.LINES | GL.
388
390
  case 'point-list': return GL.POINTS;
389
391
  case 'line-list': return GL.LINES;
390
392
  case 'line-strip': return GL.LINES;
393
+ case 'line-loop': return GL.LINES;
391
394
  case 'triangle-list': return GL.TRIANGLES;
392
395
  case 'triangle-strip': return GL.TRIANGLES;
396
+ case 'triangle-fan': return GL.TRIANGLES;
393
397
  default: throw new Error(topology);
394
398
  }
395
399
  }
@@ -12,7 +12,11 @@ import {isBrowser} from '@probe.gl/env';
12
12
  import {polyfillContext} from '../context/polyfill/polyfill-context';
13
13
  import {trackContextState} from '../context/state-tracker/track-context-state';
14
14
  import {ContextState} from '../context/context/context-state';
15
- import {createBrowserContext} from '../context/context/create-context';
15
+ import {createBrowserContext} from '../context/context/create-browser-context';
16
+ import {
17
+ createHeadlessContext,
18
+ isHeadlessGLRegistered
19
+ } from '../context/context/create-headless-context';
16
20
  import {getDeviceInfo} from './device-helpers/get-device-info';
17
21
  import {getDeviceFeatures} from './device-helpers/device-features';
18
22
  import {getDeviceLimits, getWebGLLimits, WebGLLimits} from './device-helpers/device-limits';
@@ -60,17 +64,19 @@ let counter = 0;
60
64
 
61
65
  /** WebGPU style Device API for a WebGL context */
62
66
  export default class WebGLDevice extends Device implements ContextState {
63
- // Public API
67
+ //
68
+ // Public `Device` API
69
+ //
64
70
 
65
71
  static type: string = 'webgl';
66
72
 
67
73
  static isSupported(): boolean {
68
- return typeof WebGLRenderingContext !== 'undefined';
74
+ return typeof WebGLRenderingContext !== 'undefined' || isHeadlessGLRegistered();
69
75
  }
70
76
 
71
77
  readonly info: DeviceInfo;
72
78
  readonly canvasContext: WebGLCanvasContext;
73
- readonly lost: Promise<{reason: 'destroyed'; message: string}>;
79
+
74
80
  readonly handle: WebGLRenderingContext;
75
81
 
76
82
  get features(): Set<DeviceFeature> {
@@ -83,12 +89,20 @@ export default class WebGLDevice extends Device implements ContextState {
83
89
  return this._limits;
84
90
  }
85
91
 
86
- // WebGL specific API
92
+ readonly lost: Promise<{reason: 'destroyed'; message: string}>;
93
+
94
+ private _resolveContextLost?: (value: {reason: 'destroyed'; message: string}) => void;
95
+ private _features?: Set<DeviceFeature>;
96
+ private _limits?: DeviceLimits;
97
+
98
+ //
99
+ // WebGL-only API (not part of `Device` API)
100
+ //
87
101
 
88
102
  /** WebGL1 typed context. Can always be used. */
89
103
  readonly gl: WebGLRenderingContext;
90
104
  /** WebGL2 typed context. Need to check isWebGL2 or isWebGL1 before using. */
91
- readonly gl2: WebGL2RenderingContext;
105
+ readonly gl2: WebGL2RenderingContext | null = null;
92
106
  readonly debug: boolean = false;
93
107
 
94
108
  /** `true` if this is a WebGL1 context. @note `false` if WebGL2 */
@@ -101,9 +115,7 @@ export default class WebGLDevice extends Device implements ContextState {
101
115
  return this._webglLimits;
102
116
  }
103
117
 
104
- private _features: Set<DeviceFeature>;
105
- private _limits: DeviceLimits;
106
- private _webglLimits: WebGLLimits;
118
+ private _webglLimits?: WebGLLimits;
107
119
 
108
120
  /** State used by luma.gl classes: TODO - move to canvasContext*/
109
121
  readonly _canvasSizeInfo = {clientWidth: 0, clientHeight: 0, devicePixelRatio: 1};
@@ -114,6 +126,10 @@ export default class WebGLDevice extends Device implements ContextState {
114
126
  /** Instance of Spector.js (if initialized) */
115
127
  spector;
116
128
 
129
+ //
130
+ // Static methods, expected to be present by `luma.createDevice()`
131
+ //
132
+
117
133
  /**
118
134
  * Get a device instance from a GL context
119
135
  * Creates and instruments the device if not already created
@@ -135,7 +151,7 @@ export default class WebGLDevice extends Device implements ContextState {
135
151
  return new WebGLDevice({gl: gl as WebGLRenderingContext});
136
152
  }
137
153
 
138
- static async create(props?: DeviceProps): Promise<WebGLDevice> {
154
+ static async create(props: DeviceProps = {}): Promise<WebGLDevice> {
139
155
  log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created');
140
156
 
141
157
  // Wait for page to load. Only wait when props. canvas is string
@@ -153,10 +169,20 @@ export default class WebGLDevice extends Device implements ContextState {
153
169
  await loadSpectorJS();
154
170
  }
155
171
 
156
- log.probe(LOG_LEVEL, 'DOM is loaded')();
172
+ log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
173
+
174
+ // @ts-expect-error
175
+ if (props.gl && props.gl.device) {
176
+ return WebGLDevice.attach(props.gl);
177
+ }
178
+
157
179
  return new WebGLDevice(props);
158
180
  }
159
181
 
182
+ //
183
+ // Public API
184
+ //
185
+
160
186
  constructor(props: DeviceProps) {
161
187
  super(props);
162
188
 
@@ -164,14 +190,33 @@ export default class WebGLDevice extends Device implements ContextState {
164
190
  // @ts-expect-error device is attached to context
165
191
  const device: WebGLDevice | undefined = props.gl?.device;
166
192
  if (device) {
167
- log.warn(`WebGL context already attached to device ${device.id}`);
168
- return device;
193
+ throw new Error(`WebGL context already attached to device ${device.id}`);
169
194
  }
170
195
 
171
196
  // Create and instrument context
172
197
  this.canvasContext = new WebGLCanvasContext(this, props);
173
198
 
174
- this.handle = props.gl || createBrowserContext(this.canvasContext.canvas, props);
199
+ this.lost = new Promise<{reason: 'destroyed'; message: string}>((resolve) => {
200
+ this._resolveContextLost = resolve;
201
+ });
202
+
203
+ const onContextLost = (event: Event) =>
204
+ this._resolveContextLost?.({
205
+ reason: 'destroyed',
206
+ message: 'Computer entered sleep mode, or too many apps or browser tabs are using the GPU.'
207
+ });
208
+
209
+ let gl: WebGLRenderingContext | WebGL2RenderingContext | null = props.gl;
210
+ gl =
211
+ gl ||
212
+ (isBrowser() ? createBrowserContext(this.canvasContext.canvas, {...props, onContextLost}) : null);
213
+ gl = gl || (!isBrowser() ? createHeadlessContext({...props, onContextLost}) : null);
214
+
215
+ if (!gl) {
216
+ throw new Error('WebGL context creation failed');
217
+ }
218
+
219
+ this.handle = gl;
175
220
  this.gl = this.handle;
176
221
  this.gl2 = this.gl as WebGL2RenderingContext;
177
222
  this.isWebGL2 = isWebGL2(this.gl);
@@ -182,13 +227,20 @@ export default class WebGLDevice extends Device implements ContextState {
182
227
 
183
228
  // @ts-expect-error Link webgl context back to device
184
229
  this.gl.device = this;
185
- // @ts-expect-error Annotate webgl context to handle
230
+ // @ts-expect-error Annotate webgl context to handle
186
231
  this.gl._version = this.isWebGL2 ? 2 : 1;
187
232
 
188
233
  // Add subset of WebGL2 methods to WebGL1 context
189
234
  polyfillContext(this.gl);
235
+
190
236
  // Install context state tracking
191
- trackContextState(this.gl, {copyState: false, log: (...args: any[]) => log.log(1, ...args)()});
237
+ // @ts-expect-error - hidden parameters
238
+ const {enable = true, copyState = false} = props;
239
+ trackContextState(this.gl, {
240
+ enable,
241
+ copyState,
242
+ log: (...args: any[]) => log.log(1, ...args)()
243
+ });
192
244
 
193
245
  // DEBUG contexts: Add debug instrumentation to the context, force log level to at least 1
194
246
  if (isBrowser() && props.debug) {
@@ -219,15 +271,26 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
219
271
  * @note Has no effect for browser contexts, there is no browser API for destroying contexts
220
272
  */
221
273
  destroy() {
222
- let ext = this.gl.getExtension('STACKGL_destroy_context');
274
+ const ext = this.gl.getExtension('STACKGL_destroy_context');
223
275
  if (ext) {
224
276
  ext.destroy();
225
277
  }
226
- // ext = this.gl.getExtension('WEBGL_lose_context');
227
- // if (ext) {
228
- // // TODO - disconnect context lost callbacks?
229
- // ext.loseContext();
230
- // }
278
+ }
279
+
280
+ /**
281
+ * Loses the context
282
+ * @note Triggers context loss, mainly for testing
283
+ */
284
+ loseDevice() {
285
+ const ext = this.gl.getExtension('WEBGL_lose_context');
286
+ if (ext) {
287
+ ext.loseContext();
288
+ }
289
+ // loseContext should trigger context loss callback but
290
+ this._resolveContextLost?.({
291
+ reason: 'destroyed',
292
+ message: 'Application triggered context loss'
293
+ });
231
294
  }
232
295
 
233
296
  get isLost(): boolean {
@@ -254,7 +317,9 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
254
317
 
255
318
  /** Returns a WebGL2RenderingContext or throws an error */
256
319
  assertWebGL2(): WebGL2RenderingContext {
257
- assert(this.isWebGL2, 'Requires WebGL2');
320
+ if (!this.gl2) {
321
+ throw new Error('Requires WebGL2');
322
+ }
258
323
  return this.gl2;
259
324
  }
260
325
 
@@ -304,7 +369,7 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
304
369
  throw new Error('compute shaders not supported in WebGL');
305
370
  }
306
371
 
307
- private renderPass: WEBGLRenderPass;
372
+ private renderPass: WEBGLRenderPass | null = null;
308
373
 
309
374
  getDefaultRenderPass(): WEBGLRenderPass {
310
375
  this.renderPass =
@@ -321,7 +386,7 @@ ${this.info.vendor}, ${this.info.renderer} for canvas: ${this.canvasContext.id}`
321
386
  * Chrome's offscreen canvas does not require gl.commit
322
387
  */
323
388
  submit(): void {
324
- this.renderPass.endPass();
389
+ this.renderPass?.endPass();
325
390
  this.renderPass = null;
326
391
  // this.canvasContext.commit();
327
392
  }
@@ -339,7 +404,6 @@ function isWebGL(gl: any): boolean {
339
404
  return Boolean(gl && Number.isFinite(gl._version));
340
405
  }
341
406
 
342
-
343
407
  /** Check if supplied parameter is a WebGL2RenderingContext */
344
408
  function isWebGL2(gl: any): boolean {
345
409
  if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
@@ -2,19 +2,6 @@ import {assert, checkProps, Buffer, AccessorObject} from '@luma.gl/api';
2
2
  import GL from '@luma.gl/constants';
3
3
  import {getTypedArrayFromGLType} from './typed-array-utils';
4
4
 
5
- // export interface AccessorObject {
6
- // offset?: number;
7
- // stride?: number;
8
- // type?: number;
9
- // size?: number;
10
- // divisor?: number;
11
- // normalized?: boolean;
12
- // integer?: boolean;
13
-
14
- // buffer?: Buffer;
15
- // index?: number;
16
- // }
17
-
18
5
  const DEFAULT_ACCESSOR_VALUES = {
19
6
  offset: 0,
20
7
  stride: 0,
@@ -1,4 +1,6 @@
1
- import {TypedArray} from '@luma.gl/api/types';
1
+ // luma.gl, MIT license
2
+
3
+ import {TypedArray} from '@luma.gl/api';
2
4
  import GL from '@luma.gl/constants';
3
5
  import {GLType} from '../types/webgl'
4
6
 
@@ -84,10 +84,14 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
84
84
  }
85
85
 
86
86
  if (props.onContextLost) {
87
- canvas.addEventListener('webglcontextlost', props.onContextLost, false);
87
+ // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
88
+ const {onContextLost} = props;
89
+ canvas.addEventListener('webglcontextlost',(event: Event) => onContextLost(event), false);
88
90
  }
89
91
  if (props.onContextRestored) {
90
- canvas.addEventListener('webglcontextrestored', props.onContextRestored, false);
92
+ // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
93
+ const {onContextRestored} = props;
94
+ canvas.addEventListener('webglcontextrestored', (event: Event) => onContextRestored(event), false);
91
95
  }
92
96
 
93
97
  return gl;
@@ -0,0 +1,48 @@
1
+ const ERR_HEADLESSGL_FAILED =
2
+ 'Failed to create WebGL context in Node.js, headless gl returned null';
3
+
4
+ const ERR_HEADLESSGL_LOAD = `\
5
+ luma.gl: loaded under Node.js without headless gl installed, meaning that WebGL \
6
+ contexts can not be created. This may not be an error. For example, this is a \
7
+ typical configuration for isorender applications running on the server.`;
8
+
9
+ const CONTEXT_DEFAULTS = {
10
+ width: 1,
11
+ height: 1,
12
+ debug: true,
13
+ throwOnError: false
14
+ };
15
+
16
+ /** Duck typing for the main headless gl export, a function to create contexts */
17
+ export type HeadlessGL = (width: number, height: number, options: Record<string, unknown>) => WebGLRenderingContext;
18
+
19
+ let headlessGL: HeadlessGL | null = null;
20
+
21
+ /** By importing `gl` and registering it with this function, contexts can be created under Node.js */
22
+ export function registerHeadlessGL(headlessgl: HeadlessGL) {
23
+ headlessGL = headlessgl;
24
+ }
25
+
26
+ /** @returns true if headless gl is registered */
27
+ export function isHeadlessGLRegistered(): boolean {
28
+ return headlessGL !== null;
29
+ }
30
+
31
+ /** Create headless gl context (for running under Node.js) */
32
+ export function createHeadlessContext(options?: Record<string, any>): WebGLRenderingContext {
33
+ options = {...CONTEXT_DEFAULTS, ...options};
34
+
35
+ const {width, height, webgl1, webgl2} = options;
36
+
37
+ if (webgl2 && !webgl1) {
38
+ throw new Error('headless-gl does not support WebGL2');
39
+ }
40
+ if (!headlessGL) {
41
+ throw new Error(ERR_HEADLESSGL_LOAD);
42
+ }
43
+ const gl = headlessGL(width, height, options);
44
+ if (!gl) {
45
+ throw new Error(ERR_HEADLESSGL_FAILED);
46
+ }
47
+ return gl;
48
+ }
@@ -46,7 +46,7 @@ export async function loadWebGLDeveloperTools(): Promise<void> {
46
46
 
47
47
  // Returns (a potentially new) context with debug instrumentation turned off or on.
48
48
  // Note that this actually returns a new context
49
- export function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext {
49
+ export function makeDebugContext(gl: WebGLRenderingContext, props: DebugContextProps = {}): WebGLRenderingContext | null {
50
50
  // Return null to ensure we don't try to create a context in this case (TODO what case is that?)
51
51
  if (!gl) {
52
52
  return null;
@@ -133,7 +133,7 @@ function onGLError(props: DebugContextProps, err, functionName: string, args: an
133
133
 
134
134
  // Don't generate function string until it is needed
135
135
  function onValidateGLFunc(props: DebugContextProps, functionName: string, functionArgs: any[]): void {
136
- let functionString: string;
136
+ let functionString: string = '';
137
137
  if (log.level >= 1) {
138
138
  functionString = getFunctionString(functionName, functionArgs);
139
139
  log.log(1, functionString)();
@@ -38,8 +38,6 @@ function initializeExtensions(gl: WebGLRenderingContext): void {
38
38
  for (const extensionName of EXTENSIONS) {
39
39
  const extension = gl.getExtension(extensionName);
40
40
  contextState._extensions[extensionName] = extension;
41
- // TODO - this looks like a mistake?
42
- contextState[extensionName] = extension;
43
41
  }
44
42
  }
45
43
 
package/src/index.ts CHANGED
@@ -11,6 +11,8 @@ import './init'
11
11
  // Types
12
12
  export type {WebGLLimits} from './adapter/device-helpers/device-limits';
13
13
 
14
+ export {registerHeadlessGL} from './context/context/create-headless-context';
15
+
14
16
  // WebGL adapter classes
15
17
  export {default as WebGLDevice} from './adapter/webgl-device';
16
18
  export {default as WebGLCanvasContext} from './adapter/webgl-canvas-context';
@@ -37,6 +39,7 @@ export {default as WEBGLVertexArrayObject} from './adapter/objects/webgl-vertex-
37
39
 
38
40
  // WebGL adapter classes (Legacy, will be moved to gltools)
39
41
  export {default as Accessor} from './classic/accessor';
42
+ export type {AccessorObject} from './types';
40
43
  export type {ClassicBufferProps, ClassicBufferProps as BufferProps} from './classic/buffer';
41
44
  export {default as ClassicBuffer, default as Buffer} from './classic/buffer';
42
45
 
@@ -241,7 +241,7 @@ export type GLFunctionParameters = {
241
241
  clearDepth?: number;
242
242
  clearStencil?: number;
243
243
 
244
- colorMask?: [boolean, boolean, boolean, boolean];
244
+ colorMask?: [boolean, boolean, boolean, boolean] | boolean[];
245
245
 
246
246
  cull?: boolean;
247
247
  cullFace?: GL.FRONT | GL.BACK | GL.FRONT_AND_BACK;
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-context.d.ts","sourceRoot":"","sources":["../../../src/context/context/create-context.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;EAgBE;AACF,aAAK,YAAY,GAAG;IAClB,IAAI,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IAC9C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACvC,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAC3C,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,4BAA4B,CAAC,EAAE,OAAO,CAAC;IACvC,eAAe,CAAC,EAAE,SAAS,GAAI,kBAAkB,GAAG,WAAW,CAAC;IAChE,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAA;CAChC,CAAC;AAUF;;;;GAIG;AACF,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAAE,KAAK,EAAE,YAAY,GAAG,qBAAqB,CA6C7H"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/context/context/create-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"],"mappings":"AAmCA,MAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE,MAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAJqB;AAK1CC,EAAAA,iBAAiB,EAAE,MAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb;AALiB,CAA5C;AAaC,OAAO,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,GAAG,EAAC,GAAGX,qBAAJ;AAA2B,OAAGW;AAA9B,GAAR;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,QAAMC,aAAa,GAAIP,KAAD,IAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAxE;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;AAGA,MAAIG,EAAgC,GAAG,IAAvC;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWT,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWV,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAED,MAAID,KAAK,CAACP,aAAV,EAAyB;AACvBM,IAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACD;;AACD,MAAIO,KAAK,CAACJ,iBAAV,EAA6B;AAC3BG,IAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AACD;;AAED,SAAOS,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 canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n }\n if (props.onContextRestored) {\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, 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-context.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/context/context/create-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"],"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;AAGA,MAAIG,EAAgC,GAAG,IAAvC;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,mCAAOA,KAAP;AAAcT,MAAAA,MAAM,EAAE;AAAtB,MAAL;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,mCAAOA,KAAP;AAAcV,MAAAA,MAAM,EAAE;AAAtB,MAAL;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAED,MAAID,KAAK,CAACP,aAAV,EAAyB;AACvBM,IAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACD;;AACD,MAAIO,KAAK,CAACJ,iBAAV,EAA6B;AAC3BG,IAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AACD;;AAED,SAAOS,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 canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n }\n if (props.onContextRestored) {\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, 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-context.js"}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/context/context/create-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"],"mappings":"AAmCA,MAAMA,qBAAmC,GAAG;AAC1CC,EAAAA,MAAM,EAAE,IADkC;AAE1CC,EAAAA,MAAM,EAAE,IAFkC;AAG1CC,EAAAA,eAAe,EAAE,kBAHyB;AAI1CC,EAAAA,aAAa,EAAE,MAAMC,OAAO,CAACC,KAAR,CAAc,oBAAd,CAJqB;AAK1CC,EAAAA,iBAAiB,EAAE,MAAMF,OAAO,CAACG,IAAR,CAAa,wBAAb;AALiB,CAA5C;AAaC,OAAO,SAASC,oBAAT,CAA8BC,MAA9B,EAA2EC,KAA3E,EAAuH;AAC5HA,EAAAA,KAAK,GAAG,EAAC,GAAGX,qBAAJ;AAA2B,OAAGW;AAA9B,GAAR;AAGD,MAAIC,YAAY,GAAG,IAAnB;;AACA,QAAMC,aAAa,GAAIP,KAAD,IAAYM,YAAY,GAAGN,KAAK,CAACQ,aAAN,IAAuBF,YAAxE;;AACAF,EAAAA,MAAM,CAACK,gBAAP,CAAwB,2BAAxB,EAAqDF,aAArD,EAAoE,KAApE;AAGA,MAAIG,EAAgC,GAAG,IAAvC;;AAEA,MAAIL,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWT,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AACD,MAAIS,KAAK,CAACM,IAAN,KAAe,QAAnB,EAA6B;AAC3BN,IAAAA,KAAK,GAAG,EAAC,GAAGA,KAAJ;AAAWV,MAAAA,MAAM,EAAE;AAAnB,KAAR;AACD;;AAGD,MAAIU,KAAK,CAACV,MAAV,EAAkB;AAChBe,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,QAAlB,EAA4BP,KAA5B,CAAX;AACD;;AACD,MAAIA,KAAK,CAACT,MAAV,EAAkB;AAChBc,IAAAA,EAAE,GAAGA,EAAE,IAAIN,MAAM,CAACQ,UAAP,CAAkB,OAAlB,EAA2BP,KAA3B,CAAX;AACD;;AAGDD,EAAAA,MAAM,CAACS,mBAAP,CAA2B,2BAA3B,EAAwDN,aAAxD,EAAuE,KAAvE;;AAEA,MAAI,CAACG,EAAL,EAAS;AACP,UAAM,IAAII,KAAJ,4BACgBT,KAAK,CAACV,MAAN,IAAgB,CAACU,KAAK,CAACT,MAAvB,GAAgC,QAAhC,GAA2C,OAD3D,uBAEFU,YAAY,IAAI,eAFd,EAAN;AAKD;;AAED,MAAID,KAAK,CAACP,aAAV,EAAyB;AACvBM,IAAAA,MAAM,CAACK,gBAAP,CAAwB,kBAAxB,EAA4CJ,KAAK,CAACP,aAAlD,EAAiE,KAAjE;AACD;;AACD,MAAIO,KAAK,CAACJ,iBAAV,EAA6B;AAC3BG,IAAAA,MAAM,CAACK,gBAAP,CAAwB,sBAAxB,EAAgDJ,KAAK,CAACJ,iBAAtD,EAAyE,KAAzE;AACD;;AAED,SAAOS,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 canvas.addEventListener('webglcontextlost', props.onContextLost, false);\n }\n if (props.onContextRestored) {\n canvas.addEventListener('webglcontextrestored', props.onContextRestored, 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-context.js"}