关于 glDrawRangeElements() 的问题

发布于 2024-12-06 14:12:19 字数 563 浏览 0 评论 0原文

我正在尝试使用 glDrawRangeElements() 命令渲染一些旧级别的数据。我的顶点设置正确,索引设置正确,但我似乎无法渲染它。我终于在网上检查并发现了这里找到的示例: http://www.songho.ca/opengl /gl_vertexarray.html

从示例中,我认为我做得不正确。显然,开始是一个索引值,结束是一个索引值,而不是索引数组中的索引。我假设,例如,如果你想渲染 10 个三角形,起始位置为 0,结束位置为 29,计数为 30。但我显然错了?

仅当 0 和 29 处的索引值实际上是 0 和 29 时,这才是正确的。因此,如果索引以 400 开头并以 452 结束,则对同一数组的调用将改为:

glDrawRangeElements(GL_TRIANGLES, 400, 452, 29, GL_UNSIGNED_BYTE, indices);

这是正确的吗?还有人认为这有点违反直觉吗?关于顶点数组还有其他建议吗?

I am trying to render some old level data using the glDrawRangeElements() command. My vertices are set up correctly, my indices are set up correctly, but I can't seem to get it to render. I finally checked online and came across the example found here: http://www.songho.ca/opengl/gl_vertexarray.html

From the example, I think I have been doing it incorrectly. Apparently the start is an index value and the ending is an index value, rather than an index into the indices array. I assumed that for example if you wanted to render 10 triangles, the start would be 0 and the ending would be 29 and the count would be 30. But I am apparently wrong?

That would only be correct if the index value at 0, and 29 were in fact 0 and 29. So if the indices started with 400 and ended with 452, the call to that same array would instead be

glDrawRangeElements(GL_TRIANGLES, 400, 452, 29, GL_UNSIGNED_BYTE, indices);

Is that correct? Does anyone else think this is a little counter intuitive? Any other advice about vertex arrays?

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

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

发布评论

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

评论(1

扭转时空 2024-12-13 14:12:19

首先我们来说一下glDrawElements,因为Range版本只是一个修改的。 count 是从源索引数组中提取以进行渲染的索引数。每个索引将映射拉到一个顶点。因此,如果您的 count 为“29”,那么您将尝试渲染 29 个顶点。如果您使用 GL_TRIANGLES,这只会渲染 27 个顶点,因为每个三角形需要三个顶点。 OpenGL 将丢弃额外的内容。

因此,如果您想渲染 30 个索引,则输入 30 作为计数。

现在我们知道了如何使用glDrawElements,我们来谈谈glDrawRangeElements< /a>.通常使用 glDrawElements 时,您可以指定源索引数组中要从中提取的位置。 indicescount 参数告诉 OpenGL 在哪里可以找到索引。但从此数组中提取的实际索引可能位于源顶点数组索引边界内的任何位置。

glDrawRangeElements 允许您为 OpenGL 指定一个顶点索引值的范围(包含在内,因为这是有意义的)。你的意思是,它在这次绘制调用期间获得的索引不会超过该范围。这可以允许驱动程序执行有用的优化。 start 值应该是从索引数组中获取的最低索引值,end 应该是最高的。它不应该只是第一个和最后一个顶点的索引。

First, let's talk about glDrawElements, because the Range version is just a modification of that. The count is the number of indices to pull from the source index array to render. Each index pulled maps to a vertex. So if your count is "29", then you are trying to render 29 vertices. This will only render 27 vertices if you use GL_TRIANGLES, since each triangle requires three vertices. OpenGL will discard the extras.

So if you want to render 30 indices, you put 30 in as the count.

Now that we know how to use glDrawElements, let's talk about glDrawRangeElements. When normally using glDrawElements, you specify a location in the source index array to pull from. The indices and count parameters tell OpenGL where to find the indices. But the actual indices pulled from this array could be anywhere within the boundaries of the source vertex array indices.

glDrawRangeElements allows you to give OpenGL a range (inclusive, because that makes sense) of vertex index values. What you are saying is that the indices it gets during this draw call will not exceed that range. This could allow the driver to perform useful optimizations. The start value should be the lowest index value that will be gotten from the index array, and the end should be the highest. It should not simply be the index of the first and last vertices.

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