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

WebGL 提供判断是否支持 OES_texture_float 的方法 #26

Open
xiaoiver opened this issue Jun 18, 2020 · 2 comments
Open

WebGL 提供判断是否支持 OES_texture_float 的方法 #26

xiaoiver opened this issue Jun 18, 2020 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@xiaoiver
Copy link
Contributor

xiaoiver commented Jun 18, 2020

问题背景

我们在 WebGL 的实现中使用了 OES_texture_float 扩展进行浮点数纹理的读写。
https://www.khronos.org/registry/webgl/extensions/OES_texture_float/

但是该扩展存在一定兼容性问题,尤其是在移动端 和 Safari 中:
http://webglstats.com/webgl/extension/OES_texture_float

经测试:

  • Safari 13.1 (15609.1.20.111.8) 支持
  • Safari 12.1.1 不支持

因此我们需要提供判断方法,或者采用其他兼容方案。

解决方案

提供一个 isFloatSupported 方法,开发者调用后可以自行决定,例如切换到 CPU 算法:
regl-project/regl#487
regl-project/regl@6afda7c

另外也可以尝试兼容方案:
https://github.com/mikolalysenko/glsl-read-float
在 Shader 中通过 pack 把一个浮点数压缩成 ivec4 渲染到纹理,从纹理中读取数据时进行 unpack

@xiaoiver xiaoiver added the bug Something isn't working label Jun 18, 2020
@xiaoiver xiaoiver self-assigned this Jun 18, 2020
@xiaoiver
Copy link
Contributor Author

这个判断应该和具体渲染引擎有关,而且由于 WebGL 具体实现中需要尝试读取浮点纹理,通过是否报错判断,因此需要在引擎初始化完成后。最终决定加在 onInit 回调内:

const world = new World(canvas, {
  engineOptions: {
    supportCompute: true,
  },
  onInit: (engine) => {
    console.log(engine.isFloatSupported());
  },
});

@xiaoiver
Copy link
Contributor Author

xiaoiver commented Jun 18, 2020

tfjs 遇到不支持的浏览器例如低版本的 Safari:

  1. 抛出 WebGL: INVALID_ENUM: readPixels: invalid type
  2. 自动切换成 CPU 版本:

tensorflow/tfjs#287 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant