检测浏览器对 WebGL 粗线的支持

Detecting support for WebGL thick lines in browser

作为 three.js 文档中的 stated

Due to limitations in the ANGLE layer, with the WebGL renderer on Windows platforms linewidth will always be 1 regardless of the set value.

宽线在某些不使用ANGLE的浏览器中也不起作用,例如IE11

this question 讨论了解决方法。

但是如果浏览器支持宽行,有没有办法检测

是的,有一个参数:ALIASED_LINE_WIDTH_RANGE。查询时,它 returns 线宽的可能值范围:

gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE) // returns [1, 1] on my machine, for example

仅供参考:

虽然您可以调用 gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE) 并且它 returns 是一个具有最小和最大线条宽度的数组,但支持的几乎都是 1.0。这不仅仅是因为角度。

OpenGL 本身从 3.1 版本开始不支持大于 1.0 的行。来自规范

E.2.1 Deprecated ... Features

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

请注意,这是在 OpenGL 的核心配置文件中。您可以使用 "compatibility profile" 并且仍然得到宽线和所有其他旧的东西。不幸的是,要使用 "core" 配置文件实现 WebGL2,这意味着几乎所有 WebGL 只支持宽度为 1.0 的行。