Skip to content

Commit

Permalink
chore: Upgrade typescript and WebGPU typings (#1768)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Jul 23, 2023
1 parent f0b8361 commit c758bb9
Show file tree
Hide file tree
Showing 35 changed files with 81 additions and 71 deletions.
4 changes: 2 additions & 2 deletions docs/tutorials/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Open the file `package.json` (created when we initialized npm), and add the foll
"@luma.gl/webgl": "^9.0.0",
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^2.6.4"
}
}
Expand All @@ -69,7 +69,7 @@ The full contents of the `package.json` should be the following (dependency vers
"@luma.gl/webgl": "^9.0.0",
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^2.6.4"
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples-wip/api-v8/program-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/api-v8/stress-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@probe.gl/stats-widget": "^4.0.0"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/dof/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/geospatial/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"mapbox-gl": "^1.2.1"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/gltf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/instanced-transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/transform-feedback/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@luma.gl/webgl-legacy": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/notready/wandering/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@probe.gl/log": "^4.0.0"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/webgl/external-webgl-context/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@luma.gl/webgl": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/webgl/hello-instancing-webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@luma.gl/webgl": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples-wip/webgl/shader-modules-webgl/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@luma.gl/webgl": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/api/animation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/api/cubemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/api/texture-3d/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/hello-cube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/hello-instancing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@luma.gl/webgl": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/hello-triangle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@luma.gl/webgl-legacy": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/lighting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/shader-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@luma.gl/webgl": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/getting-started/shader-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@luma.gl/webgl-legacy": "9.0.0-alpha.21"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/showcase/instancing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/showcase/persistence/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/webgpu/computeboids/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4",
"vite-plugin-string": "^1.1.1"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/webgpu/hello-triangle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/webgpu/instanced-cubes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/webgpu/rotating-cube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/webgpu/textured-cube/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
2 changes: 1 addition & 1 deletion examples/webgpu/two-cubes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@math.gl/core": "4.0.0-alpha.4"
},
"devDependencies": {
"typescript": "^4.3.2",
"typescript": "^5.1.6",
"vite": "^3.2.4"
}
}
67 changes: 37 additions & 30 deletions modules/webgl/src/context/context/create-browser-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

/**
* ContextProps
* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
* @param onContextLost
* @param onContextRestored
*
* BROWSER CONTEXT PARAMETERS
* @param debug Instrument context (at the expense of performance).
* @param alpha Default render target has an alpha buffer.
* @param depth Default render target has a depth buffer of at least 16 bits.
* @param stencil Default render target has a stencil buffer of at least 8 bits.
* @param antialias Boolean that indicates whether or not to perform anti-aliasing.
* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
*/
* @param webgl2 Set to false to not create a WebGL2 context (force webgl1)
* @param webgl1 set to false to not create a WebGL1 context (fail if webgl2 not available)
* @param onContextLost
* @param onContextRestored
*
* BROWSER CONTEXT PARAMETERS
* @param debug Instrument context (at the expense of performance).
* @param alpha Default render target has an alpha buffer.
* @param depth Default render target has a depth buffer of at least 16 bits.
* @param stencil Default render target has a stencil buffer of at least 8 bits.
* @param antialias Boolean that indicates whether or not to perform anti-aliasing.
* @param premultipliedAlpha Boolean that indicates that the page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
* @param preserveDrawingBuffer Default render target buffers will not be automatically cleared and will preserve their values until cleared or overwritten
* @param failIfMajorPerformanceCaveat Do not create if the system performance is low.
*/
type ContextProps = {
type?: 'webgl' | 'webgl1' | 'webgl2' | string;
webgl1?: boolean;
Expand All @@ -27,10 +27,10 @@ type ContextProps = {
desynchronized?: boolean; // hints the user agent to reduce the latency by desynchronizing the canvas paint cycle from the event loop
antialias?: boolean; // indicates whether or not to perform anti-aliasing.
depth?: boolean; // indicates that the drawing buffer has a depth buffer of at least 16 bits.
failIfMajorPerformanceCaveat?: boolean, // indicates if a context will be created if the system performance is low or if no hardware GPU is available.
powerPreference?: 'default' | 'high-performance' | 'low-power',
premultipliedAlpha?: boolean, // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
preserveDrawingBuffer?: boolean // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.
failIfMajorPerformanceCaveat?: boolean; // indicates if a context will be created if the system performance is low or if no hardware GPU is available.
powerPreference?: 'default' | 'high-performance' | 'low-power';
premultipliedAlpha?: boolean; // page compositor will assume the drawing buffer contains colors with pre-multiplied alpha.
preserveDrawingBuffer?: boolean; // buffers will not be cleared and will preserve their values until cleared or overwritten by the author.
};

const DEFAULT_CONTEXT_PROPS: ContextProps = {
Expand All @@ -40,24 +40,27 @@ const DEFAULT_CONTEXT_PROPS: ContextProps = {
// eslint-disable-next-line no-console
onContextLost: () => console.error('WebGL context lost'),
// eslint-disable-next-line no-console
onContextRestored: () => console.info('WebGL context restored'),
onContextRestored: () => console.info('WebGL context restored')
};

/**
* Create a WebGL context for a canvas
* Note calling this multiple time on the same canvas does return the same context
* @param canvas A canvas element or offscreen canvas
* @param canvas A canvas element or offscreen canvas
*/
export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas, props: ContextProps): WebGLRenderingContext {
export function createBrowserContext(
canvas: HTMLCanvasElement | OffscreenCanvas,
props: ContextProps
): WebGLRenderingContext {
props = {...DEFAULT_CONTEXT_PROPS, ...props};

// Try to extract any extra information about why context creation failed
let errorMessage = null;
const onCreateError = (error) => (errorMessage = error.statusMessage || errorMessage);
const onCreateError = error => (errorMessage = error.statusMessage || errorMessage);
canvas.addEventListener('webglcontextcreationerror', onCreateError, false);

// Create the desired context
let gl: WebGLRenderingContext | null = null;
let gl: WebGLRenderingContext | WebGL2RenderingContext | null = null;

if (props.type === 'webgl2') {
props = {...props, webgl1: false};
Expand All @@ -67,11 +70,11 @@ export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas
}

// Prefer webgl2 over webgl1 if both are acceptable
if (props.webgl2) {
gl = gl || canvas.getContext('webgl2', props) ;
if (!gl && props.webgl2) {
gl = canvas.getContext('webgl2', props) as WebGL2RenderingContext;
}
if (props.webgl1) {
gl = gl || canvas.getContext('webgl', props) ;
if (!gl && props.webgl1) {
gl = canvas.getContext('webgl', props) as WebGLRenderingContext;
}

// TODO are we removing this listener before giving it a chance to fire?
Expand All @@ -88,12 +91,16 @@ export function createBrowserContext(canvas: HTMLCanvasElement | OffscreenCanvas
if (props.onContextLost) {
// Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
const {onContextLost} = props;
canvas.addEventListener('webglcontextlost',(event: Event) => onContextLost(event), false);
canvas.addEventListener('webglcontextlost', (event: Event) => onContextLost(event), false);
}
if (props.onContextRestored) {
// Carefully extract and wrap callbacks to prevent addEventListener from rebinding them.
const {onContextRestored} = props;
canvas.addEventListener('webglcontextrestored', (event: Event) => onContextRestored(event), false);
canvas.addEventListener(
'webglcontextrestored',
(event: Event) => onContextRestored(event),
false
);
}

return gl;
Expand Down
2 changes: 1 addition & 1 deletion modules/webgpu/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"@babel/runtime": "^7.0.0",
"@luma.gl/api": "9.0.0-alpha.23",
"@probe.gl/env": "^4.0.2",
"@webgpu/types": "^0.1.31"
"@webgpu/types": "^0.1.34"
},
"gitHead": "c636c34b8f1581eed163e94543a8eb1f4382ba8e"
}
Loading

0 comments on commit c758bb9

Please sign in to comment.