@luma.gl/webgl
Advanced tools
Comparing version 9.1.0-beta.11 to 9.1.0-beta.12
@@ -13,3 +13,4 @@ import { Adapter, Device, DeviceProps } from '@luma.gl/core'; | ||
* Get a device instance from a GL context | ||
* Creates and instruments the device if not already created | ||
* Creates a WebGLCanvasContext against the contexts canvas | ||
* @note autoResize will be disabled, assuming that whoever created the external context will be handling resizes. | ||
* @param gl | ||
@@ -16,0 +17,0 @@ * @returns |
@@ -30,3 +30,4 @@ // luma.gl | ||
* Get a device instance from a GL context | ||
* Creates and instruments the device if not already created | ||
* Creates a WebGLCanvasContext against the contexts canvas | ||
* @note autoResize will be disabled, assuming that whoever created the external context will be handling resizes. | ||
* @param gl | ||
@@ -47,3 +48,8 @@ * @returns | ||
} | ||
return new WebGLDevice({ _handle: gl }); | ||
// We create a new device using the provided WebGL context and its canvas | ||
// Assume that whoever created the external context will be handling resizes. | ||
return new WebGLDevice({ | ||
_handle: gl, | ||
createCanvasContext: { canvas: gl.canvas, autoResize: false } | ||
}); | ||
} | ||
@@ -50,0 +56,0 @@ async create(props = {}) { |
@@ -84,10 +84,13 @@ // luma.gl | ||
} | ||
const gl = createBrowserContext(this.canvasContext.canvas, { | ||
onContextLost: (event) => this._resolveContextLost?.({ | ||
reason: 'destroyed', | ||
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.' | ||
}), | ||
// eslint-disable-next-line no-console | ||
onContextRestored: (event) => console.log('WebGL context restored') | ||
}, webglContextAttributes); | ||
// Check if we should attach to an externally created context or create a new context | ||
const externalGLContext = this.props._handle; | ||
const gl = externalGLContext || | ||
createBrowserContext(this.canvasContext.canvas, { | ||
onContextLost: (event) => this._resolveContextLost?.({ | ||
reason: 'destroyed', | ||
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.' | ||
}), | ||
// eslint-disable-next-line no-console | ||
onContextRestored: (event) => console.log('WebGL context restored') | ||
}, webglContextAttributes); | ||
if (!gl) { | ||
@@ -117,3 +120,5 @@ throw new Error('WebGL context creation failed'); | ||
} | ||
this.canvasContext.resize(); | ||
if (canvasContextProps.autoResize !== false) { | ||
this.canvasContext.resize(); | ||
} | ||
// Install context state tracking | ||
@@ -120,0 +125,0 @@ const glState = new WebGLStateTracker(this.gl, { |
{ | ||
"name": "@luma.gl/webgl", | ||
"version": "9.1.0-beta.11", | ||
"version": "9.1.0-beta.12", | ||
"description": "WebGL2 adapter for the luma.gl core API", | ||
@@ -46,7 +46,7 @@ "type": "module", | ||
"dependencies": { | ||
"@luma.gl/constants": "9.1.0-beta.11", | ||
"@luma.gl/constants": "9.1.0-beta.12", | ||
"@math.gl/types": "^4.1.0", | ||
"@probe.gl/env": "^4.0.8" | ||
}, | ||
"gitHead": "aab3748ab83360e6ee611f9b4a2d805e5f17fb01" | ||
"gitHead": "7559423456495eeac8828002f48ddbe3d8ceeff0" | ||
} |
@@ -39,3 +39,4 @@ // luma.gl | ||
* Get a device instance from a GL context | ||
* Creates and instruments the device if not already created | ||
* Creates a WebGLCanvasContext against the contexts canvas | ||
* @note autoResize will be disabled, assuming that whoever created the external context will be handling resizes. | ||
* @param gl | ||
@@ -56,3 +57,9 @@ * @returns | ||
} | ||
return new WebGLDevice({_handle: gl as WebGL2RenderingContext}); | ||
// We create a new device using the provided WebGL context and its canvas | ||
// Assume that whoever created the external context will be handling resizes. | ||
return new WebGLDevice({ | ||
_handle: gl, | ||
createCanvasContext: {canvas: gl.canvas, autoResize: false} | ||
}); | ||
} | ||
@@ -99,3 +106,3 @@ | ||
/** Check if supplied parameter is a WebGL2RenderingContext */ | ||
function isWebGL(gl: any): boolean { | ||
function isWebGL(gl: any): gl is WebGL2RenderingContext { | ||
if (typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext) { | ||
@@ -102,0 +109,0 @@ return true; |
@@ -143,16 +143,21 @@ // luma.gl | ||
const gl = createBrowserContext( | ||
this.canvasContext.canvas, | ||
{ | ||
onContextLost: (event: Event) => | ||
this._resolveContextLost?.({ | ||
reason: 'destroyed', | ||
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.' | ||
}), | ||
// eslint-disable-next-line no-console | ||
onContextRestored: (event: Event) => console.log('WebGL context restored') | ||
}, | ||
webglContextAttributes | ||
); | ||
// Check if we should attach to an externally created context or create a new context | ||
const externalGLContext = this.props._handle as WebGL2RenderingContext | null; | ||
const gl = | ||
externalGLContext || | ||
createBrowserContext( | ||
this.canvasContext.canvas, | ||
{ | ||
onContextLost: (event: Event) => | ||
this._resolveContextLost?.({ | ||
reason: 'destroyed', | ||
message: 'Entered sleep mode, or too many apps or browser tabs are using the GPU.' | ||
}), | ||
// eslint-disable-next-line no-console | ||
onContextRestored: (event: Event) => console.log('WebGL context restored') | ||
}, | ||
webglContextAttributes | ||
); | ||
if (!gl) { | ||
@@ -192,3 +197,5 @@ throw new Error('WebGL context creation failed'); | ||
this.canvasContext.resize(); | ||
if (canvasContextProps.autoResize !== false) { | ||
this.canvasContext.resize(); | ||
} | ||
@@ -195,0 +202,0 @@ // Install context state tracking |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2048343
31671
221358
238
2
4
0
+ Added@luma.gl/constants@9.1.0-beta.12(transitive)
- Removed@luma.gl/constants@9.1.0-beta.11(transitive)