Open GL ES/WebGL 中是否有 glPolygonMode 的替代品?

发布于 2024-09-15 09:46:26 字数 123 浏览 5 评论 0原文

我想在线框模式下创建一个游戏,但是如果没有 glPolygoneMode 命令,我不知道该怎么做。我可以用可用的东西自己编写代码吗?我对 opengl 完全陌生。如果有人做到了这一点并且有代码片段,我很乐意看到它。任何帮助表示赞赏。

I would like to create a game in wireframe mode however without the glPolygoneMode command I don't know how I would do it. Is it something I could code myself with what is available? I'm completely new to opengl. If anyone has done this and has the code snippet I would love to see it. Any help is appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

三人与歌 2024-09-22 09:46:26

不幸的是,您可能实际上必须将几何图形完全转换为线图元并使用GL_LINES渲染它们。然而,这当然不是通过在绘制调用中简单地用 GL_LINES 替换 GL_TRIANGLES (或其他)来完成的,您将必须完全重新排序顶点以适应新的原始模式。这要求您至少在 glDrawElements... 调用中使用不同的索引数组,或者对于非索引渲染 (glDrawArrays...),完全使用不同的顶点数组(尽管,如果您真的选择这样做,这可能是切换到索引绘图的正确时机)。

但是,如果您有可用的几何着色器(不过,看来 WebGL 不支持它们,OpenGL ES 从 3.2 开始就应该支持它们,就像 desptop GL 一样,但无论如何它都有很好的旧 glPolygonMode )并且还没有将它们用于其他用途,事情会变得更容易。在这种情况下,您可以在顶点和片段处理之间安装一个相当简单的几何着色器,该着色器采用三角形并为每个三角形输出 3 条线

layout(triangles) in;
layout(line_strip, max_vertices=4) out;

void main()
{
    for(int i=0; i<4; ++i)
    {
        // and whatever other attributes of course
        gl_Position = gl_in[i%3].gl_Position;
        EmitVertex();
    }
}

如果您使用正确的基于块的着色器接口,您应该能够使用现有的顶点和片段着色器来完成其余的工作,只需将几何着色器挂在它们之间,即可对基于三角形的图元进行各种线框渲染。

Unfortunately, you might have to actually completely convert your geometry to line primitives and render them using GL_LINES. However, it is of course not done by simply replacing GL_TRIANGLES (or whatever) with GL_LINES in your draw calls, you will have to entirely reorder your vertices to accomodate for the new primitive mode. This requires you to at least use different index arrays in glDrawElements... calls or, for non-indexed rendering (glDrawArrays...), different vertex arrays altogether (though, in case you really choose to do that, this might be the right moment to switch to indexed drawing instead).

If, however, you have Geometry Shaders available (though, it seems WebGL doesn't support them, OpenGL ES should since 3.2, as does desptop GL but that has good old glPolygonMode anyway) and don't already use them for something else, things get easier. In this case you can just install a rather simple geometry shader between the vertex and fragment processing that takes triangles and outputs 3 lines for each of them:

layout(triangles) in;
layout(line_strip, max_vertices=4) out;

void main()
{
    for(int i=0; i<4; ++i)
    {
        // and whatever other attributes of course
        gl_Position = gl_in[i%3].gl_Position;
        EmitVertex();
    }
}

If you use proper block-based shader interfacing, you should be able to use your existing vertex and fragment shaders for the rest and just hook that geometry shader in between them for the wireframe rendering of all kinds for triangle-based primitives.

流绪微梦 2024-09-22 09:46:26

可以想象,您可以使用 GL_LINES 渲染整个场景

Conceivably you could render the entire scene using GL_LINES

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文