使用 WebGL 索引缓冲区绘制网格
3 个索引缓冲区提出了一个更困难的问题,但我觉得他们的主要问题归结为我的:是有没有办法在 WebGL 中使用索引缓冲区多次访问同一顶点而不是复制顶点? 我所能找到的就是使用索引缓冲区将纹理、法线等与模型中的顶点相关联。我无法找到一种方法来使用索引缓冲区来告诉 drawArrays 访问位置数组中顶点的顺序。
3 index buffers asks a more difficult question, but I feel like their main problem boils down to mine: is there a way to use index buffers to visit the same vertex multiple times in WebGL rather than duplicating the vertices?
All I was able to find is using index buffers to associate textures, normals, etc. to vertices in a model. I wasn't able to find a way to use an index buffer to tell drawArrays the order in which to visit the vertices in a position array.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,使用 gl.drawElements 并将带有顶点索引的缓冲区上传到 gl.ELEMENT_ARRAY_BUFFER。
请参阅 https://developer.mozilla.org/en/WebGL/Creating_3D_objects_using_WebGL 了解完整信息例子。
Yes, use gl.drawElements and upload the buffer with your vertex indices to gl.ELEMENT_ARRAY_BUFFER.
See https://developer.mozilla.org/en/WebGL/Creating_3D_objects_using_WebGL for a full example.
当您使用索引时,只需将索引加倍即可。然而,这对我来说没有意义,因为使用相同的全局状态多次处理相同的顶点数据,每次重复的结果都是相同的。
我怀疑您真正想做的是对具有不同制服的相同顶点数据进行多次绘制调用。
..只要您不更改顶点数据,就只有少量上传到 GPU(需要低带宽)。
When you use indices, you can just double the indexes. However, this makes no sense to me as processing the same vertex data multiple times with the same global state, results would be the same for each duplicate.
What I suspect you really want to do is to make multiple Draw calls on the same vertex data with different uniforms.
As long as you don't change vertex data, there is just minor uploads to the gpu (needing low bandwidth).