@luma.gl/webgl 9.1.0-beta.11 → 9.1.0-beta.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luma.gl/webgl",
3
- "version": "9.1.0-beta.11",
3
+ "version": "9.1.0-beta.15",
4
4
  "description": "WebGL2 adapter for the luma.gl core API",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -43,9 +43,9 @@
43
43
  "@luma.gl/core": "^9.1.0-alpha.1"
44
44
  },
45
45
  "dependencies": {
46
- "@luma.gl/constants": "9.1.0-beta.11",
46
+ "@luma.gl/constants": "9.1.0-beta.15",
47
47
  "@math.gl/types": "^4.1.0",
48
48
  "@probe.gl/env": "^4.0.8"
49
49
  },
50
- "gitHead": "aab3748ab83360e6ee611f9b4a2d805e5f17fb01"
50
+ "gitHead": "8befd5eecce277fedbe2562f05a06fae3fc04c6e"
51
51
  }
@@ -36,7 +36,8 @@ export class WebGLAdapter extends Adapter {
36
36
 
37
37
  /**
38
38
  * Get a device instance from a GL context
39
- * Creates and instruments the device if not already created
39
+ * Creates a WebGLCanvasContext against the contexts canvas
40
+ * @note autoResize will be disabled, assuming that whoever created the external context will be handling resizes.
40
41
  * @param gl
41
42
  * @returns
42
43
  */
@@ -52,7 +53,13 @@ export class WebGLAdapter extends Adapter {
52
53
  if (!isWebGL(gl)) {
53
54
  throw new Error('Invalid WebGL2RenderingContext');
54
55
  }
55
- return new WebGLDevice({_handle: gl as WebGL2RenderingContext});
56
+
57
+ // We create a new device using the provided WebGL context and its canvas
58
+ // Assume that whoever created the external context will be handling resizes.
59
+ return new WebGLDevice({
60
+ _handle: gl,
61
+ createCanvasContext: {canvas: gl.canvas, autoResize: false}
62
+ });
56
63
  }
57
64
 
58
65
  async create(props: DeviceProps = {}): Promise<WebGLDevice> {
@@ -94,7 +101,7 @@ ${device.info.vendor}, ${device.info.renderer} for canvas: ${device.canvasContex
94
101
  }
95
102
 
96
103
  /** Check if supplied parameter is a WebGL2RenderingContext */
97
- function isWebGL(gl: any): boolean {
104
+ function isWebGL(gl: any): gl is WebGL2RenderingContext {
98
105
  if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) {
99
106
  return true;
100
107
  }
@@ -140,19 +140,24 @@ export class WebGLDevice extends Device {
140
140
  webglContextAttributes.powerPreference = props.powerPreference;
141
141
  }
142
142
 
143
- const gl = createBrowserContext(
144
- this.canvasContext.canvas,
145
- {
146
- onContextLost: (event: Event) =>
147
- this._resolveContextLost?.({
148
- reason: 'destroyed',
149
- message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
150
- }),
151
- // eslint-disable-next-line no-console
152
- onContextRestored: (event: Event) => console.log('WebGL context restored')
153
- },
154
- webglContextAttributes
155
- );
143
+ // Check if we should attach to an externally created context or create a new context
144
+ const externalGLContext = this.props._handle as WebGL2RenderingContext | null;
145
+
146
+ const gl =
147
+ externalGLContext ||
148
+ createBrowserContext(
149
+ this.canvasContext.canvas,
150
+ {
151
+ onContextLost: (event: Event) =>
152
+ this._resolveContextLost?.({
153
+ reason: 'destroyed',
154
+ message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.'
155
+ }),
156
+ // eslint-disable-next-line no-console
157
+ onContextRestored: (event: Event) => console.log('WebGL context restored')
158
+ },
159
+ webglContextAttributes
160
+ );
156
161
 
157
162
  if (!gl) {
158
163
  throw new Error('WebGL context creation failed');
@@ -188,7 +193,9 @@ export class WebGLDevice extends Device {
188
193
  this.features.initializeFeatures();
189
194
  }
190
195
 
191
- this.canvasContext.resize();
196
+ if (canvasContextProps.autoResize !== false) {
197
+ this.canvasContext.resize();
198
+ }
192
199
 
193
200
  // Install context state tracking
194
201
  const glState = new WebGLStateTracker(this.gl, {