关于glDrawRangeElements()的问题 [英] Questions about glDrawRangeElements()

查看:710
本文介绍了关于glDrawRangeElements()的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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?

那将是正确的,如果索引值在0和29实际上是0和29.所以如果索引以400开始,以452结束,调用同一数组将改为

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?

推荐答案

首先,让我们谈谈 glDrawElements ,因为Range版本只是一个修改。 count 是从源索引数组中提取的要渲染的索引数。每个索引都映射到一个顶点。所以如果你的计数是29,那么你正试图渲染29个顶点。如果使用 GL_TRIANGLES ,这将只渲染27个顶点,因为每个三角形需要三个顶点。

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.

所以,如果你想渲染30个索引,你把30作为计数。

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

现在我们知道如何使用 glDrawElements ,让我们来谈谈 glDrawRangeElements 。当通常使用 glDrawElements 时,您在源索引数组中指定要从中拉出的位置。 indices count 参数告诉OpenGL在哪里可以找到索引。但是,从这个数组中拉出的实际索引可以在源顶点数组索引的边界内

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 允许您给予OpenGL一个范围(包括,因为这是有意义的)顶点索引值。你所说的是,它在此绘制调用期间获得的指数不会超过该范围。这可以允许驱动程序执行有用的优化。 start 值应该是从索引数组获取的最低索引值, end 应该是最高。它不应该只是第一个和最后一个顶点的索引。

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.

这篇关于关于glDrawRangeElements()的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆