Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[g-webgl] 需要正确处理 WebGL Context Lost #1362

Closed
xiaoiver opened this issue Jun 7, 2023 · 1 comment
Closed

[g-webgl] 需要正确处理 WebGL Context Lost #1362

xiaoiver opened this issue Jun 7, 2023 · 1 comment
Assignees
Labels

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Jun 7, 2023

https://www.khronos.org/webgl/wiki/HandlingContextLost

当 WebGL 上下文丢失时,应该尝试恢复:

canvas.addEventListener("webglcontextlost", setupWebGLStateAndResources, false);

同理,WebGPU 错误处理可以参考:https://github.com/gpuweb/gpuweb/blob/main/design/ErrorHandling.md#fatal-errors-requestadapter-requestdevice-and-devicelost

const device = await adapter.requestDevice(descriptor);
device.lost.then(recoverFromDeviceLoss);
@xiaoiver
Copy link
Contributor Author

xiaoiver commented Jun 14, 2023

g-webglg-webgpu 中增加如下初始化配置项:

interface WebGLRendererConfig extends RendererConfig {
  targets: ('webgl1' | 'webgl2')[];
  onContextLost: (e: Event) => void;
  onContextRestored: (e: Event) => void;
  onContextCreationError: (e: Event) => void;
}

interface WebGPURendererConfig extends RendererConfig {
  shaderCompilerPath: string;
  onContextLost: () => void;
}

使用方法如下:

import { Renderer } from 'g-webgl';

new Renderer({
  onContextLost: () => {}
});

xiaoiver added a commit that referenced this issue Jun 14, 2023
* fix: WebGPU HAL & handle lost context #863 & #1362

* fix: wait for context lost promise

* fix: create renderer3d component in picking plugin #1094

* feat: add onContextLost callback to constructor options of WebGL & WebGPU renderer #1362

* fix: copy glsl_wgsl_compiler_bg.wasm to dist dir of g-webgpu #1369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant