一个顶点缓冲区中有多个网格?
我是否需要为每个网格使用一个顶点缓冲区,或者我可以在一个顶点缓冲区中存储多个网格吗?如果是这样,我应该这样做吗?我该怎么做?
Do I need to use one vertex buffer per mesh, or can I store multiple meshes in one vertex buffer? If so, should I do it, and how would I do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在一个顶点缓冲区中存储多个网格。您可以通过将几个小网格放入一个缓冲区中来获得一些性能。对于非常大的网格,您应该使用单独的缓冲区。
SetStreamSource
允许您指定当前网格的顶点缓冲区偏移量。You can store multiple meshes in one vertex buffer. You may gain some performance by putting several small meshes in in one buffer. For really large meshes you should use seperate buffers.
SetStreamSource
lets you specify the vertex buffer offset for your current mesh.TBH 通常将它们全部放入一个大缓冲区的原因是为了节省绘制调用。切换顶点缓冲区的成本相当小。如果您可以将它们全部合并到 1 个顶点缓冲区中并在 1 个绘制调用中渲染 10 个对象,那么您就获得了巨大的胜利。
通常,要合并它们,您只需创建 1 个大顶点缓冲区,其中包含所有顶点数据,这些顶点数据已经在其中一个接一个地进行了世界变换。然后,您设置一个索引缓冲区来依次渲染它们。然后,您可以通过最少的绘制调用来绘制所有内容。当然,如果您移动一件需要更新顶点缓冲区的一部分的东西,这就是为什么它是静态几何体的理想情况。
如果所有对象都相同,那么您将只使用 1 个顶点缓冲区(其中有 1 个对象定义)和 1 个索引缓冲区,对吗?矩阵移动对象或为对象设置动画...
如果所有对象都不同并且移动/设置动画,那么我会坚持使用单独的 VB。我怀疑您将它们合并在一起是否会注意到任何差异。
TBH generally the reason for putting them all in one big buffer is to save on draw calls. The cost of switching a vertex buffer is fairly minimal. If you can merge them all into 1 vertex buffer and render 10 objects in 1 draw call then you are on to a big win.
Usually to merge them you just create 1 big vertex buffer with all the vertex data, already world transformed in it, one after another. You then set up an index buffer that renders them one after another. You then have everything drawing in minimal draw calls. Of course if you move one thing that requires updating a portion of the vertex buffer which is why its an ideal situation for static geometry.
If all the objects are the same you'll only be using 1 vertex buffer (with 1 object definition in it) and 1 index buffer anyway right? Matrices move or animate the object ...
If all the objects are different and moving/animating then i'd just stick with individual VBs. I doubt you'd notice any difference by merging them all together.
嗯,我的经验是,只要你的缓冲区不是很小或很大,它就没有太大区别。我怀疑切换缓冲区的任何低效都会通过为驱动程序提供更多操作性来通过更小的缓冲区管理其内存来提高效率。
Well my experience is that it doesn't make that much difference as long as your buffers aren't really tiny or really huge. I suspect that any inefficency in switching buffers would be matched by an increase in efficiency by giving the driver more operatunities to manage it's memory with more smaller buffers.
使用 OpenGL,您可以使用
glVertexPointer()
从 VBO 内的某个偏移量开始绘制。不确定D3D。With OpenGL you can use
glVertexPointer()
to start drawing from a certain offset inside the VBO. not sure about D3D.