@luma.gl/webgl 9.1.0-alpha.15 → 9.1.0-alpha.16

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 (43) hide show
  1. package/dist/adapter/converters/device-parameters.d.ts +3 -3
  2. package/dist/adapter/converters/device-parameters.d.ts.map +1 -1
  3. package/dist/adapter/helpers/webgl-texture-utils.d.ts +24 -22
  4. package/dist/adapter/helpers/webgl-texture-utils.d.ts.map +1 -1
  5. package/dist/adapter/helpers/webgl-texture-utils.js +6 -224
  6. package/dist/adapter/resources/webgl-command-buffer.js +15 -15
  7. package/dist/adapter/resources/webgl-render-pipeline.d.ts +1 -1
  8. package/dist/adapter/resources/webgl-render-pipeline.d.ts.map +1 -1
  9. package/dist/adapter/resources/webgl-render-pipeline.js +24 -11
  10. package/dist/adapter/resources/webgl-shader.d.ts +1 -0
  11. package/dist/adapter/resources/webgl-shader.d.ts.map +1 -1
  12. package/dist/adapter/resources/webgl-shader.js +6 -4
  13. package/dist/adapter/webgl-adapter.d.ts.map +1 -1
  14. package/dist/adapter/webgl-adapter.js +4 -10
  15. package/dist/adapter/webgl-device.d.ts +1 -2
  16. package/dist/adapter/webgl-device.d.ts.map +1 -1
  17. package/dist/adapter/webgl-device.js +33 -14
  18. package/dist/context/debug/spector-types.js +1 -1
  19. package/dist/context/debug/spector.d.ts +5 -5
  20. package/dist/context/debug/spector.d.ts.map +1 -1
  21. package/dist/context/debug/spector.js +6 -6
  22. package/dist/context/debug/webgl-developer-tools.d.ts +1 -3
  23. package/dist/context/debug/webgl-developer-tools.d.ts.map +1 -1
  24. package/dist/context/debug/webgl-developer-tools.js +4 -19
  25. package/dist/context/helpers/create-browser-context.d.ts +6 -22
  26. package/dist/context/helpers/create-browser-context.d.ts.map +1 -1
  27. package/dist/context/helpers/create-browser-context.js +26 -32
  28. package/dist/dist.dev.js +147 -135
  29. package/dist/dist.min.js +2 -2
  30. package/dist/index.cjs +129 -123
  31. package/dist/index.cjs.map +3 -3
  32. package/package.json +3 -3
  33. package/src/adapter/converters/device-parameters.ts +3 -3
  34. package/src/adapter/helpers/webgl-texture-utils.ts +33 -30
  35. package/src/adapter/resources/webgl-command-buffer.ts +16 -16
  36. package/src/adapter/resources/webgl-render-pipeline.ts +26 -11
  37. package/src/adapter/resources/webgl-shader.ts +7 -5
  38. package/src/adapter/webgl-adapter.ts +4 -12
  39. package/src/adapter/webgl-device.ts +67 -40
  40. package/src/context/debug/spector-types.ts +1 -1
  41. package/src/context/debug/spector.ts +11 -11
  42. package/src/context/debug/webgl-developer-tools.ts +5 -31
  43. package/src/context/helpers/create-browser-context.ts +39 -64
@@ -1,7 +1,7 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- import { Adapter, Device, CanvasContext, log } from '@luma.gl/core';
4
+ import { Adapter, Device, log } from '@luma.gl/core';
5
5
  import { WebGLDevice } from "./webgl-device.js";
6
6
  import { enforceWebGL2 } from "../context/polyfills/polyfill-webgl1-extensions.js";
7
7
  import { loadSpectorJS, DEFAULT_SPECTOR_PROPS } from "../context/debug/spector.js";
@@ -43,23 +43,18 @@ export class WebGLAdapter extends Adapter {
43
43
  if (!isWebGL(gl)) {
44
44
  throw new Error('Invalid WebGL2RenderingContext');
45
45
  }
46
- return new WebGLDevice({ gl: gl });
46
+ return new WebGLDevice({ _handle: gl });
47
47
  }
48
48
  async create(props = {}) {
49
49
  log.groupCollapsed(LOG_LEVEL, 'WebGLDevice created')();
50
50
  const promises = [];
51
51
  // Load webgl and spector debug scripts from CDN if requested
52
- if (props.debug) {
52
+ if (props.debugWebGL) {
53
53
  promises.push(loadWebGLDeveloperTools());
54
54
  }
55
- if (props.debugWithSpectorJS) {
55
+ if (props.debugSpectorJS) {
56
56
  promises.push(loadSpectorJS(props));
57
57
  }
58
- // Wait for page to load: if canvas is a string we need to query the DOM for the canvas element.
59
- // We only wait when props.canvas is string to avoids setting the global page onload callback unless necessary.
60
- if (typeof props.canvas === 'string') {
61
- promises.push(CanvasContext.pageLoaded);
62
- }
63
58
  // Wait for all the loads to settle before creating the context.
64
59
  // The Device.create() functions are async, so in contrast to the constructor, we can `await` here.
65
60
  const results = await Promise.allSettled(promises);
@@ -68,7 +63,6 @@ export class WebGLAdapter extends Adapter {
68
63
  log.error(`Failed to initialize debug libraries ${result.reason}`)();
69
64
  }
70
65
  }
71
- log.probe(LOG_LEVEL + 1, 'DOM is loaded')();
72
66
  const device = new WebGLDevice(props);
73
67
  // Log some debug info about the newly created context
74
68
  const message = `\
@@ -1,12 +1,11 @@
1
1
  import type { TypedArray } from '@math.gl/types';
2
- import type { DeviceProps, DeviceInfo, CanvasContextProps, TextureFormat, Buffer, Texture, Framebuffer, VertexArray, VertexArrayProps } from '@luma.gl/core';
2
+ import type { DeviceProps, DeviceInfo, CanvasContextProps, TextureFormat, Buffer, Texture, Framebuffer, VertexArray, VertexArrayProps, BufferProps, ShaderProps, SamplerProps, TextureProps, ExternalTexture, ExternalTextureProps, FramebufferProps, RenderPipelineProps, ComputePipeline, ComputePipelineProps, RenderPassProps, ComputePass, ComputePassProps, CommandEncoderProps, TransformFeedbackProps, QuerySetProps } from '@luma.gl/core';
3
3
  import { Device, CanvasContext } from '@luma.gl/core';
4
4
  import type { GLExtensions } from '@luma.gl/constants';
5
5
  import { WebGLDeviceFeatures } from "./device-helpers/webgl-device-features.js";
6
6
  import { WebGLDeviceLimits } from "./device-helpers/webgl-device-limits.js";
7
7
  import { WebGLCanvasContext } from "./webgl-canvas-context.js";
8
8
  import type { Spector } from "../context/debug/spector-types.js";
9
- import type { BufferProps, ShaderProps, SamplerProps, TextureProps, ExternalTexture, ExternalTextureProps, FramebufferProps, RenderPipelineProps, ComputePipeline, ComputePipelineProps, RenderPassProps, ComputePass, ComputePassProps, CommandEncoderProps, TransformFeedbackProps, QuerySetProps } from '@luma.gl/core';
10
9
  import { WEBGLBuffer } from "./resources/webgl-buffer.js";
11
10
  import { WEBGLShader } from "./resources/webgl-shader.js";
12
11
  import { WEBGLSampler } from "./resources/webgl-sampler.js";
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-device.d.ts","sourceRoot":"","sources":["../../src/adapter/webgl-device.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,aAAa,EACb,MAAM,EACN,OAAO,EACP,WAAW,EACX,WAAW,EACX,gBAAgB,EACjB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAC,MAAM,EAAE,aAAa,EAAM,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAIrD,OAAO,EAAC,mBAAmB,EAAC,kDAA+C;AAC3E,OAAO,EAAC,iBAAiB,EAAC,gDAA6C;AACvE,OAAO,EAAC,kBAAkB,EAAC,kCAA+B;AAC1D,OAAO,KAAK,EAAC,OAAO,EAAC,0CAAuC;AAW5D,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EAEX,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,oBAAoB,EACpB,gBAAgB,EAEhB,mBAAmB,EACnB,eAAe,EACf,oBAAoB,EAEpB,eAAe,EACf,WAAW,EACX,gBAAgB,EAEhB,mBAAmB,EACnB,sBAAsB,EACtB,aAAa,EACd,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAC,WAAW,EAAC,oCAAiC;AACrD,OAAO,EAAC,WAAW,EAAC,oCAAiC;AACrD,OAAO,EAAC,YAAY,EAAC,qCAAkC;AACvD,OAAO,EAAC,YAAY,EAAC,qCAAkC;AACvD,OAAO,EAAC,gBAAgB,EAAC,yCAAsC;AAC/D,OAAO,EAAC,eAAe,EAAC,yCAAsC;AAC9D,OAAO,EAAC,mBAAmB,EAAC,6CAA0C;AACtE,OAAO,EAAC,mBAAmB,EAAC,6CAA0C;AAEtE,OAAO,EAAC,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AAE,QAAQ,EAAE,UAAU,GAAG,IAAI;IA2BvE,gDAAgD;IAChD,YAAY,CAAC,IAAI,EAAE,MAAM,YAAY,GAAG,YAAY;CAIrD"}
@@ -58,29 +58,48 @@ export class WebGLDevice extends Device {
58
58
  //
59
59
  constructor(props) {
60
60
  super({ ...props, id: props.id || uid('webgl-device') });
61
+ // WebGL requires a canvas to be created before creating the context
62
+ if (!props.createCanvasContext) {
63
+ throw new Error('WebGLDevice requires props.createCanvasContext to be set');
64
+ }
65
+ const canvasContextProps = props.createCanvasContext === true ? {} : props.createCanvasContext;
61
66
  // If attaching to an already attached context, return the attached device
62
67
  // @ts-expect-error device is attached to context
63
- const device = props.gl?.device;
68
+ let device = canvasContextProps.canvas?.gl?.device;
64
69
  if (device) {
65
70
  throw new Error(`WebGL context already attached to device ${device.id}`);
66
71
  }
67
72
  // Create and instrument context
68
- const canvas = props.gl?.canvas || props.canvas;
69
- this.canvasContext = new WebGLCanvasContext(this, { ...props, canvas });
73
+ this.canvasContext = new WebGLCanvasContext(this, canvasContextProps);
70
74
  this.lost = new Promise(resolve => {
71
75
  this._resolveContextLost = resolve;
72
76
  });
73
- this.handle = createBrowserContext(this.canvasContext.canvas, {
74
- ...props,
77
+ const webglContextAttributes = { ...props.webgl };
78
+ // Copy props from CanvasContextProps
79
+ if (canvasContextProps.alphaMode === 'premultiplied') {
80
+ webglContextAttributes.premultipliedAlpha = true;
81
+ }
82
+ if (props.powerPreference !== undefined) {
83
+ webglContextAttributes.powerPreference = props.powerPreference;
84
+ }
85
+ const gl = createBrowserContext(this.canvasContext.canvas, {
75
86
  onContextLost: (event) => this._resolveContextLost?.({
76
87
  reason: 'destroyed',
77
88
  message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
78
- })
79
- });
80
- this.gl = this.handle;
81
- if (!this.handle) {
89
+ }),
90
+ // eslint-disable-next-line no-console
91
+ onContextRestored: (event) => console.log('WebGL context restored')
92
+ }, webglContextAttributes);
93
+ if (!gl) {
82
94
  throw new Error('WebGL context creation failed');
83
95
  }
96
+ // @ts-expect-error device is attached to context
97
+ device = gl.device;
98
+ if (device) {
99
+ throw new Error(`WebGL context already attached to device ${device.id}`);
100
+ }
101
+ this.handle = gl;
102
+ this.gl = gl;
84
103
  // Add spector debug instrumentation to context
85
104
  // We need to trust spector integration to decide if spector should be initialized
86
105
  // We also run spector instrumentation first, otherwise spector can clobber luma instrumentation.
@@ -91,8 +110,8 @@ export class WebGLDevice extends Device {
91
110
  // initialize luma Device fields
92
111
  this.info = getDeviceInfo(this.gl, this._extensions);
93
112
  this.limits = new WebGLDeviceLimits(this.gl);
94
- this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props.disabledFeatures);
95
- if (this.props.initalizeFeatures) {
113
+ this.features = new WebGLDeviceFeatures(this.gl, this._extensions, this.props._disabledFeatures);
114
+ if (this.props._initializeFeatures) {
96
115
  this.features.initializeFeatures();
97
116
  }
98
117
  this.canvasContext.resize();
@@ -102,8 +121,8 @@ export class WebGLDevice extends Device {
102
121
  });
103
122
  glState.trackState(this.gl, { copyState: false });
104
123
  // DEBUG contexts: Add luma debug instrumentation to the context, force log level to at least 1
105
- if (props.debug) {
106
- this.gl = makeDebugContext(this.gl, { ...props, throwOnError: true });
124
+ if (props.debugWebGL) {
125
+ this.gl = makeDebugContext(this.gl, { ...props });
107
126
  this.debug = true;
108
127
  log.level = Math.max(log.level, 1);
109
128
  log.warn('WebGL debug mode activated. Performance reduced.')();
@@ -131,7 +150,7 @@ export class WebGLDevice extends Device {
131
150
  throw new Error('WebGL only supports a single canvas');
132
151
  }
133
152
  createBuffer(props) {
134
- const newProps = this._getBufferProps(props);
153
+ const newProps = this._normalizeBufferProps(props);
135
154
  return new WEBGLBuffer(this, newProps);
136
155
  }
137
156
  createTexture(props) {
@@ -1,5 +1,5 @@
1
1
  // Forked from https://github.com/BabylonJS/Spector.js/blob/master/dist/spector.d.ts
2
- /* eslint-disable camelcase */
2
+ /* eslint-disable camelcase, no-shadow */
3
3
  var LogLevel;
4
4
  (function (LogLevel) {
5
5
  LogLevel[LogLevel["noLog"] = 0] = "noLog";
@@ -1,10 +1,10 @@
1
- import { Spector } from "./spector-types.js";
1
+ import type { Spector } from "./spector-types.js";
2
2
  /** Spector debug initialization options */
3
3
  type SpectorProps = {
4
- /** Whether spector is enabled */
5
- debugWithSpectorJS?: boolean;
4
+ /** Whether spector.js is enabled */
5
+ debugSpectorJS?: boolean;
6
6
  /** URL to load spector script from. Typically a CDN URL */
7
- spectorUrl?: string;
7
+ debugSpectorJSUrl?: string;
8
8
  /** Canvas to monitor */
9
9
  gl?: WebGL2RenderingContext;
10
10
  };
@@ -14,7 +14,7 @@ declare global {
14
14
  export declare const DEFAULT_SPECTOR_PROPS: Required<SpectorProps>;
15
15
  /** Loads spector from CDN if not already installed */
16
16
  export declare function loadSpectorJS(props: {
17
- spectorUrl?: string;
17
+ debugSpectorJSUrl?: string;
18
18
  }): Promise<void>;
19
19
  export declare function initializeSpectorJS(props: SpectorProps): Spector | null;
20
20
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"spector.d.ts","sourceRoot":"","sources":["../../../src/context/debug/spector.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,OAAO,EAAC,2BAAwB;AAExC,2CAA2C;AAC3C,KAAK,YAAY,GAAG;IAClB,iCAAiC;IACjC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wBAAwB;IACxB,EAAE,CAAC,EAAE,sBAAsB,CAAC;CAC7B,CAAC;AAOF,OAAO,CAAC,MAAM,CAAC;IAGb,IAAI,OAAO,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,YAAY,CAOxD,CAAC;AAEF,sDAAsD;AACtD,wBAAsB,aAAa,CAAC,KAAK,EAAE;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAQ/E;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,GAAG,IAAI,CAyDvE"}
1
+ {"version":3,"file":"spector.d.ts","sourceRoot":"","sources":["../../../src/context/debug/spector.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAC,OAAO,EAAC,2BAAwB;AAE7C,2CAA2C;AAC3C,KAAK,YAAY,GAAG;IAClB,oCAAoC;IACpC,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,2DAA2D;IAC3D,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,wBAAwB;IACxB,EAAE,CAAC,EAAE,sBAAsB,CAAC;CAC7B,CAAC;AAOF,OAAO,CAAC,MAAM,CAAC;IAGb,IAAI,OAAO,EAAE,OAAO,CAAC;CACtB;AAED,eAAO,MAAM,qBAAqB,EAAE,QAAQ,CAAC,YAAY,CAOxD,CAAC;AAEF,sDAAsD;AACtD,wBAAsB,aAAa,CAAC,KAAK,EAAE;IAAC,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAQtF;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,GAAG,IAAI,CAyDvE"}
@@ -7,18 +7,18 @@ const LOG_LEVEL = 1;
7
7
  let spector = null;
8
8
  let initialized = false;
9
9
  export const DEFAULT_SPECTOR_PROPS = {
10
- debugWithSpectorJS: log.get('spector') || log.get('spectorjs'),
10
+ debugSpectorJS: log.get('debug-spectorjs'),
11
11
  // https://github.com/BabylonJS/Spector.js#basic-usage
12
12
  // https://forum.babylonjs.com/t/spectorcdn-is-temporarily-off/48241
13
13
  // spectorUrl: 'https://spectorcdn.babylonjs.com/spector.bundle.js';
14
- spectorUrl: 'https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js',
14
+ debugSpectorJSUrl: 'https://cdn.jsdelivr.net/npm/spectorjs@0.9.30/dist/spector.bundle.js',
15
15
  gl: undefined
16
16
  };
17
17
  /** Loads spector from CDN if not already installed */
18
18
  export async function loadSpectorJS(props) {
19
19
  if (!globalThis.SPECTOR) {
20
20
  try {
21
- await loadScript(props.spectorUrl || DEFAULT_SPECTOR_PROPS.spectorUrl);
21
+ await loadScript(props.debugSpectorJSUrl || DEFAULT_SPECTOR_PROPS.debugSpectorJSUrl);
22
22
  }
23
23
  catch (error) {
24
24
  log.warn(String(error));
@@ -27,13 +27,13 @@ export async function loadSpectorJS(props) {
27
27
  }
28
28
  export function initializeSpectorJS(props) {
29
29
  props = { ...DEFAULT_SPECTOR_PROPS, ...props };
30
- if (!props.debugWithSpectorJS) {
30
+ if (!props.debugSpectorJS) {
31
31
  return null;
32
32
  }
33
33
  if (!spector && globalThis.SPECTOR && !globalThis.luma?.spector) {
34
34
  log.probe(LOG_LEVEL, 'SPECTOR found and initialized. Start with `luma.spector.displayUI()`')();
35
- const { Spector } = globalThis.SPECTOR;
36
- spector = new Spector();
35
+ const { Spector: SpectorJS } = globalThis.SPECTOR;
36
+ spector = new SpectorJS();
37
37
  if (globalThis.luma) {
38
38
  globalThis.luma.spector = spector;
39
39
  }
@@ -1,7 +1,5 @@
1
1
  type DebugContextProps = {
2
- debug?: boolean;
3
- throwOnError?: boolean;
4
- break?: string[];
2
+ debugWebGL?: boolean;
5
3
  };
6
4
  declare global {
7
5
  var WebGLDebugUtils: any;
@@ -1 +1 @@
1
- {"version":3,"file":"webgl-developer-tools.d.ts","sourceRoot":"","sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":[],"mappings":"AAYA,KAAK,iBAAiB,GAAG;IACvB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB,CAAC;AAoBF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,eAAe,EAAE,GAAG,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAO7D;AAID,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,KAAK,GAAE,iBAAsB,GAC5B,sBAAsB,CAExB"}
1
+ {"version":3,"file":"webgl-developer-tools.d.ts","sourceRoot":"","sources":["../../../src/context/debug/webgl-developer-tools.ts"],"names":[],"mappings":"AAYA,KAAK,iBAAiB,GAAG;IACvB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAaF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,eAAe,EAAE,GAAG,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAsB,uBAAuB,IAAI,OAAO,CAAC,IAAI,CAAC,CAO7D;AAID,wBAAgB,gBAAgB,CAC9B,EAAE,EAAE,sBAAsB,EAC1B,KAAK,GAAE,iBAAsB,GAC5B,sBAAsB,CAExB"}
@@ -29,7 +29,7 @@ export async function loadWebGLDeveloperTools() {
29
29
  // Returns (a potentially new) context with debug instrumentation turned off or on.
30
30
  // Note that this actually returns a new context
31
31
  export function makeDebugContext(gl, props = {}) {
32
- return props.debug ? getDebugContext(gl, props) : getRealContext(gl);
32
+ return props.debugWebGL ? getDebugContext(gl, props) : getRealContext(gl);
33
33
  }
34
34
  // Returns the real context from either of the real/debug contexts
35
35
  function getRealContext(gl) {
@@ -88,9 +88,7 @@ function onGLError(props, err, functionName, args) {
88
88
  const message = `${errorMessage} in gl.${functionName}(${functionArgs})`;
89
89
  log.error(message)();
90
90
  debugger; // eslint-disable-line
91
- if (props.throwOnError) {
92
- throw new Error(message);
93
- }
91
+ // throw new Error(message);
94
92
  }
95
93
  // Don't generate function string until it is needed
96
94
  function onValidateGLFunc(props, functionName, functionArgs) {
@@ -99,24 +97,11 @@ function onValidateGLFunc(props, functionName, functionArgs) {
99
97
  functionString = getFunctionString(functionName, functionArgs);
100
98
  log.log(1, functionString)();
101
99
  }
102
- // If array of breakpoint strings supplied, check if any of them is contained in current GLEnum function
103
- if (props.break && props.break.length > 0) {
104
- functionString = functionString || getFunctionString(functionName, functionArgs);
105
- const isBreakpoint = props.break.every((breakOn) => functionString.indexOf(breakOn) !== -1);
106
- if (isBreakpoint) {
107
- debugger; // eslint-disable-line
108
- }
109
- }
110
100
  for (const arg of functionArgs) {
111
101
  if (arg === undefined) {
112
102
  functionString = functionString || getFunctionString(functionName, functionArgs);
113
- if (props.throwOnError) {
114
- throw new Error(`Undefined argument: ${functionString}`);
115
- }
116
- else {
117
- log.error(`Undefined argument: ${functionString}`)();
118
- debugger; // eslint-disable-line
119
- }
103
+ debugger; // eslint-disable-line
104
+ // throw new Error(`Undefined argument: ${functionString}`);
120
105
  }
121
106
  }
122
107
  }
@@ -1,35 +1,19 @@
1
1
  /**
2
2
  * ContextProps
3
3
  * @param onContextLost
4
- * @param onContextRestored
5
- *
6
- * BROWSER CONTEXT PARAMETERS
7
- * @param debug Instrument context (at the expense of performance).
8
- * @param alpha Default render target has an alpha buffer.
9
- * @param depth Default render target has a depth buffer of at least 16 bits.
10
- * @param stencil Default render target has a stencil buffer of at least 8 bits.
11
- * @param antialias Boolean that indicates whether or not to perform anti-aliasing.
12
- * @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
13
- * @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
14
- * @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
4
+ * @param onContextRestored *
15
5
  */
16
6
  type ContextProps = {
17
- onContextLost?: (event: Event) => void;
18
- onContextRestored?: (event: Event) => void;
19
- alpha?: boolean;
20
- desynchronized?: boolean;
21
- antialias?: boolean;
22
- depth?: boolean;
23
- failIfMajorPerformanceCaveat?: boolean;
24
- powerPreference?: 'default' | 'high-performance' | 'low-power';
25
- premultipliedAlpha?: boolean;
26
- preserveDrawingBuffer?: boolean;
7
+ /** Called when a context is lost */
8
+ onContextLost: (event: Event) => void;
9
+ /** Called when a context is restored */
10
+ onContextRestored: (event: Event) => void;
27
11
  };
28
12
  /**
29
13
  * Create a WebGL context for a canvas
30
14
  * Note calling this multiple time on the same canvas does return the same context
31
15
  * @param canvas A canvas element or offscreen canvas
32
16
  */
33
- export declare function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGL2RenderingContext;
17
+ export declare function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps, webglContextAttributes: WebGLContextAttributes): WebGL2RenderingContext;
34
18
  export {};
35
19
  //# sourceMappingURL=create-browser-context.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create-browser-context.d.ts","sourceRoot":"","sources":["../../../src/context/helpers/create-browser-context.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;GAcG;AACH,KAAK,YAAY,GAAG;IAClB,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,GAAG,kBAAkB,GAAG,WAAW,CAAC;IAC/D,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAUF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAC3C,KAAK,EAAE,YAAY,GAClB,sBAAsB,CA+CxB"}
1
+ {"version":3,"file":"create-browser-context.d.ts","sourceRoot":"","sources":["../../../src/context/helpers/create-browser-context.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,KAAK,YAAY,GAAG;IAClB,oCAAoC;IACpC,aAAa,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACtC,wCAAwC;IACxC,iBAAiB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAC3C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,iBAAiB,GAAG,eAAe,EAC3C,KAAK,EAAE,YAAY,EACnB,sBAAsB,EAAE,sBAAsB,GAC7C,sBAAsB,CA6CxB"}
@@ -1,49 +1,43 @@
1
1
  // luma.gl
2
2
  // SPDX-License-Identifier: MIT
3
3
  // Copyright (c) vis.gl contributors
4
- const DEFAULT_CONTEXT_PROPS = {
5
- powerPreference: 'high-performance', // After all, most apps are using WebGL for performance reasons
6
- // eslint-disable-next-line no-console
7
- onContextLost: () => console.error('WebGL context lost'),
8
- // eslint-disable-next-line no-console
9
- onContextRestored: () => console.info('WebGL context restored')
10
- };
11
4
  /**
12
5
  * Create a WebGL context for a canvas
13
6
  * Note calling this multiple time on the same canvas does return the same context
14
7
  * @param canvas A canvas element or offscreen canvas
15
8
  */
16
- export function createBrowserContext(canvas, props) {
17
- props = { ...DEFAULT_CONTEXT_PROPS, ...props };
9
+ export function createBrowserContext(canvas, props, webglContextAttributes) {
18
10
  // Try to extract any extra information about why context creation failed
19
- let errorMessage = null;
20
- const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
21
- canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
11
+ const errorMessage = null;
12
+ // const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
13
+ // Avoid multiple listeners?
14
+ // canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);
15
+ // canvas.addEventListener('webglcontextcreationerror', onCreateError, false);
16
+ const webglProps = {
17
+ preserveDrawingBuffer: true,
18
+ // failIfMajorPerformanceCaveat: true,
19
+ ...webglContextAttributes
20
+ };
22
21
  // Create the desired context
23
22
  let gl = null;
24
- // props.failIfMajorPerformanceCaveat = true;
25
- // We require webgl2 context
26
- gl ||= canvas.getContext('webgl2', props);
27
- // Software GPU
28
- // props.failIfMajorPerformanceCaveat = false;
29
- // if (!gl && props.webgl1) {
30
- // gl = canvas.getContext('webgl', props);
31
- // }
32
- // TODO are we removing this listener before giving it a chance to fire?
33
- canvas.removeEventListener('webglcontextcreationerror', onCreateError, false);
23
+ // Create a webgl2 context
24
+ gl ||= canvas.getContext('webgl2', webglProps);
25
+ // Creation failed with failIfMajorPerformanceCaveat - Try a Software GPU
26
+ if (!gl && !webglContextAttributes.failIfMajorPerformanceCaveat) {
27
+ webglProps.failIfMajorPerformanceCaveat = false;
28
+ gl = canvas.getContext('webgl', webglProps);
29
+ // @ts-expect-error
30
+ gl.luma ||= {};
31
+ // @ts-expect-error
32
+ gl.luma.softwareRenderer = true;
33
+ }
34
34
  if (!gl) {
35
35
  throw new Error(`Failed to create WebGL context: ${errorMessage || 'Unknown error'}`);
36
36
  }
37
- if (props.onContextLost) {
38
- // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
39
- const { onContextLost } = props;
40
- canvas.addEventListener('webglcontextlost', (event) => onContextLost(event), false);
41
- }
42
- if (props.onContextRestored) {
43
- // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
44
- const { onContextRestored } = props;
45
- canvas.addEventListener('webglcontextrestored', (event) => onContextRestored(event), false);
46
- }
37
+ // Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
38
+ const { onContextLost, onContextRestored } = props;
39
+ canvas.addEventListener('webglcontextlost', (event) => onContextLost(event), false);
40
+ canvas.addEventListener('webglcontextrestored', (event) => onContextRestored(event), false);
47
41
  return gl;
48
42
  }
49
43
  /* TODO - can we call this asynchronously to catch the error events?