Chrome 如何在 macOS 上支持 webgl?

How does Chrome support webgl on macOS?

我在 Chrome.app 中找到了 libGLESv2.dylib libswiftshader_libGLESv2.dylib libvk_swiftshader.dylib。在 https://webglreport.com/?v=2 中它说:

Vendor: WebKit
Renderer:   WebKit WebGL
Unmasked Vendor:    ATI Technologies Inc.
Unmasked Renderer:  AMD Radeon Pro 560X OpenGL Engine
Antialiasing:   Available
ANGLE:  No

听说 chrome 在 windows 上使用了角度。在 macOS 上不使用这里的角度。那么chrome 运行 webgl如何呢?

无法检测角度。 WebGLReport 的猜测和它的猜测都是错误的。这是他们的代码

function getAngle(gl) {
  var lineWidthRange = describeRange(gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE));

  // Heuristic: ANGLE is only on Windows, not in IE, and not in Edge, and does not implement line width greater than one.
  var angle = ((navigator.platform === 'Win32') || (navigator.platform === 'Win64')) &&
    (gl.getParameter(gl.RENDERER) !== 'Internet Explorer') &&
    (gl.getParameter(gl.RENDERER) !== 'Microsoft Edge') &&
    (lineWidthRange === describeRange([1, 1]));

  if (angle) {
    // Heuristic: D3D11 backend does not appear to reserve uniforms like the D3D9 backend, e.g.,
    // D3D11 may have 1024 uniforms per stage, but D3D9 has 254 and 221.
    //
    // We could also test for WEBGL_draw_buffers, but many systems do not have it yet
    // due to driver bugs, etc.
    if (isPowerOfTwo(gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS)) && isPowerOfTwo(gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS))) {
      return 'Yes, D3D11';
    } else {
      return 'Yes, D3D9';
    }
  }

  return 'No';
}

这是错误的,已经过时了。

第一个猜测是查看 lineWidthRange,即使他们写的也只是猜测。规范说只有宽度为 1 的线是有效的。回到 WebGL 发布时,ANGLE 只支持大小为 1 的线而 OpenGL 支持其他线是很常见的。但是,当 WebGL2 发布时,情况发生了变化,因为当 运行 在桌面 OpenGL 之上运行时,WebGL2 需要使用“核心”配置文件,而“核心”配置文件不允许除大小 1 句点以外的行。

来自the spec

E.2.1 Deprecated But Still Supported Features

The following features are deprecated, but still present in the core profile. They may be removed from a future version of OpenGL, and are removed in a forwardcompatible context implementing the core profile.

  • Wide lines - LineWidth values greater than 1.0 will generate an INVALID_VALUE error

他们的第二个猜测是查看浏览器。这显然不再有效。 Edge 现在基于 Chromium 并进一步 Safari now uses ANGLE as well.

最后一个是对使用 ANGLE 的另一种猜测,因为它假设 ANGLE 运行ning 在 D3D 之上,因此某些限制是特殊的,但 ANGLE 现在在所有平台上都使用并且可以 运行 在桌面 OpenGL、D3D、OpenGL ES、Metal 和 Vulkan 之上。根据截至 2021 年 1 月 the angle project 的图表

通过支持渲染器的 OpenGL ES 支持级别

Direct3D 9 Direct3D 11 Desktop GL GL ES Vulkan Metal
OpenGL ES 2.0 complete complete complete complete complete complete
OpenGL ES 3.0 complete complete complete complete in progress
OpenGL ES 3.1 incomplete complete complete complete
OpenGL ES 3.2 in progress in progress in progress

这里是 ANGLE 当前支持的平台列表

通过支持渲染器的平台支持

Direct3D 9 Direct3D 11 Desktop GL GL ES Vulkan Metal
Windows complete complete complete complete complete
Linux complete complete
Mac OS X complete in progress
iOS planned
Chrome OS complete planned
Android complete complete
GGP (Stadia) complete
Fuchsia in progress

所以,你不应该相信WebGLReport。也许你应该去提交一个错误。

Chrome 能够在 MacOS 上使用桌面 OpenGL 到 运行 WebGL,但 AFAIK ANGLE 目前在所有 Chrome 平台上使用,包括 MacOS。 ANGLE was even added to Safari 最近启用了 Safari 的 WebGL2 支持并修复了一些关于 WebGL1 支持的错误