2

我想绘制单面而不是 xna 模型,因为它太慢了。

但我不知道有什么区别

  • 绘制图元
  • 绘制用户基元
  • DrawIndexedPrimitives
  • DrawUserIndexedPrimitives

哪种方法最快?这些指数有什么用?

4

2 回答 2

5

The simple answer to your question is that the "User" versions are a fair bit slower on the CPU because they have to transfer vertex data to the GPU (via the driver and the bus) each time they are called.

The non-User versions use vertex and index buffers that already exist on the GPU (you put them there at load time). They have considerably less data to transfer, so they are faster.

The "User" and "Indexed" versions will also each have a performance impact on the GPU. This impact is relatively tiny. Generally speaking you don't need to worry about it.

The User versions exist because they are faster when your data changes each frame. There is also DynamicVertexBuffer which can be used with the non-User version of the draw functions. I believe it is slightly faster than the User methods in cases where you can pre-allocate the buffer at the desired size.

The Indexed versions allow you to select vertices out of your vertex buffer using an index buffer (so triangles that you draw can choose vertices at any position in the vertex buffer). The alternative is that your vertex buffer is simply interpreted as as sequential list of triangle vertices (based on PrimitiveType). The main reason for the existence of index buffers is to remove the need for duplicate vertices in your vertex buffer (which would require additional memory and processing on the GPU).

BUT...

XNA's Model class internally uses DrawIndexedPrimitives. Not only that, but it uses it correctly (ie: it doesn't draw single faces - but as many as it can at once - for the best performance). So if you are finding that it is slow, then your problem lies elsewhere.

I suggest trying to diagnose the reason why your game is performing poorly, before trying to select a "solution". Maybe ask for help doing that in a question here (or on https://gamedev.stackexchange.com/).

于 2012-06-24T14:19:48.957 回答
0

如果可以的话,全部一次,实例化绘制总是会更好,但这需要您一次性提供所有纹理!例如,在我的例子中,我喜欢用 1 个纹理绘制实例化的对象...所有的树、所有的地面、所有的建筑物等...

于 2020-05-03T20:53:22.437 回答