javascript - 如何使用 gl.lineWidth()

标签 javascript graphics webgl

其他一切都进展顺利,界限正在绘制中。它似乎只是忽略了 gl.lineWidth() 调用。我还有什么需要做的吗?

    gl.lineWidth(17);
    gl.drawArrays(this.drawMode,0,totalVertices);

我是否有可能过度简化事情?它可能需要知道我正在指定哪一行的宽度吗?

最佳答案

需要注意的是,使用 1.0 以外的任何宽度的 gl.lineWidth 不能保证按照 WebGL 规范工作。 WebGL 基于 OpenGL ES 2.0(WebGL2 基于 OpenGL ES 3.0)。 The OpenGL ES 3.0 spec

第 3.5 节

The maximum line width supported must be at least one.

或者换句话说,不需要支持宽度 > 1.0。 OpenGL ES 2.0/WebGL1 也是如此

要找出线条支持的最小和最大宽度,您应该调用 gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE) ,它返回一个由 2 个数字组成的数组。第一个数字是支持的最小宽度,第二个数字是支持的最大宽度。两者都允许为 1.0

因此,您确实不应该使用 gl.lineWidth,因为您的用户可能无法获得 1.0 以外的任何宽度。

也就是说,有一段时间,一些实现支持线宽 > 1.0。这种情况在 2017 年 1 月 WebGL2 发布时发生了重大变化。 WebGL2 至少在 Mac 和 Linux 上是在 OpenGL 3.3 的核心配置文件之上实现的。来自OpenGL Spec Core Profile spec附录E

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.

浏览器不会根据 OpenGL 规范生成错误,因为 OpenGL ES 规范不需要错误,但限制仍然存在,因为底层驱动程序不支持它们。

如果你想画大于1的线,你需要rasterize the lines yourself .

关于javascript - 如何使用 gl.lineWidth(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47444239/

相关文章:

Java 图形在计时器中不工作

C# 绘图,奇怪的行为

glsl - 在 int gl_VertexID 中导致 three.js 出错

javascript - 无法使用 Ajax 将数据列表从 Controller 返回到 View 中的下拉列表。我收到未定义的未定义错误

javascript - JQuery 测试元素是否可见或隐藏,然后添加删除类

java - 为什么我的动画会剪切消息框?

javascript - WebGL alpha 取决于与原点的距离

javascript - Webgl sylvester.js glUtils.js 权限

javascript - 使用 SoundCloud API 暂停声音

javascript - 如果服务器 http 状态不是 200,则启用 CORS