我应该如何优化绘制大量动态数量的顶点集合?

发布于 2024-12-05 06:36:04 字数 586 浏览 0 评论 0原文

……或者我是疯了才去尝试的吗?

作为使用裸顶点进行 3D 图形的新手,我以前从未使用过顶点缓冲区等。我猜我应该使用动态缓冲区,因为我的游戏涉及操作、添加和删除基元。但我该怎么做呢?

到目前为止,我已将索引存储在 Triangle.cs 类中。三角形存储在四边形中(四边形包含与其索引相对应的顶点),四边形存储在块中。在我的绘制方法中,我迭代每个块、每个块中的每个四边形,最后是每个三角形,将适当的纹理应用于我的效果,然后调用 DrawUserIndexedPrimitives 来绘制存储在三角形中的顶点。

我想使用顶点缓冲区,因为此方法无法支持我想要的规模。我假设它是动态的。但是,由于我的顶点和索引存储在单独的类的集合中,我仍然可以有效地使用缓冲区吗?为每个四元组使用单独的缓冲区是否愚蠢(我猜是这样)?对我来说,在第一次绘制四边形时将顶点转储到缓冲区中,然后存储这些顶点的位置,以便我可以将该偏移量应用于该三角形的索引以进行连续绘制,这是否可行且有效?在这种情况下,是否有一种可行的方法来处理从缓冲区中删除顶点(可能是基于事件的三角形中索引偏移量的移位)?

我很抱歉这些问题可能太新手或太令人困惑/模糊。我很乐意提供澄清。但正如我所说,我对此很陌生,我什至可能不知道我在说什么......

...or am I insane to even try?

As a novice to using bare vertices for 3d graphics, I haven't ever worked with vertex buffers and the like before. I am guessing that I should use a dynamic buffer because my game deals with manipulating, adding and deleting primitives. But how would I go about doing that?

So far I have stored my indices in a Triangle.cs class. Triangles are stored in Quads (which contain the vertices that correspond to their indices), quads are stored in blocks. In my draw method, I iterate through each block, each quad in each block, and finally each triangle, apply the appropriate texture to my effect, then call DrawUserIndexedPrimitives to draw the vertices stored in the triangle.

I'd like to use a vertex buffer because this method cannot support the scale I am going for. I am assuming it to be dynamic. Since my vertices and indices are stored in a collection of separate classes, though, can I still effectively use a buffer? Is using separate buffers for each quad silly (I'm guessing it is)? Is it feasible and effective for me to dump vertices into the buffer the first time a quad is drawn and then store where those vertices were so that I can apply that offset to that triangle's indices for successive draws? Is there a feasible way to handle removing vertices from the buffer in this scenario (perhaps event-based shifting of index offsets in triangles)?

I apologize that these questions may be either far too novicely or too confusing/vague. I'd be happy to provide clarification. But as I've said, I'm new to this and I may not even know what I'm talking about...

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

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

发布评论

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

评论(1

_失温 2024-12-12 06:36:04

我无法确切说明您要做什么,但是每个四边形使用单独的缓冲区非常愚蠢。

图形编程中的黄金法则是批处理,批处理,批处理。这意味着将尽可能多的东西包装到一个吸引人的呼叫中,您的图形卡会喜欢您。

就您而言,将所有的verticies放在一个顶点缓冲区和索引缓冲区中(您可能需要使用更多,我不知道我们正在谈论多少个verticies)。每当用户更改一个原始素数时,都会再生整个缓冲区。如果您确实有很多素源,请将它们分成多个缓冲区,并且仅在用户更改某些东西时需要再生所需的缓冲区。

最重要的是要最大程度地减少“ DravuserIndexedPrimitimitives”呼叫的数量,这些东西具有 lot ,您可以轻松地以20倍的速度进行游戏。
图形卡是管道,他们喜欢得到大量数据供他们吃掉。一次给它一个三角形来做的事情就像强迫大规模的汽车工厂一次只制造一辆汽车。他们无法在最后一辆汽车完成之前开始建造下一辆车。

无论如何,祝您好运,并随时提出任何问题。

I can't exactly tell what you're trying to do, but using a seperate buffer for every quad is very silly.

The golden rule in graphics programming is batch, batch, batch. This means to pack as much stuff into a single DrawUserIndexedPrimitives call as possible, your graphics card will love you for it.

In your case, put all of your verticies and indicies into one vertex buffer and index buffer (you might need to use more, I have no idea how many verticies we're talking about). Whenever the user changes one of the primatives, regenerate the entire buffer. If you really have a lot of primatives, split them up into multiple buffers and on only regenerate the ones you need when the user changes something.

The most important thing is to minimize the amount of 'DrawUserIndexedPrimitives' calls, those things have a lot of overhead, you could easily make your game on the order of 20x faster.
Graphics cards are pipelines, they like being given a big chunk of data for them to eat away at. What you're doing by giving it one triangle at a time is like forcing a large-scale car factory to only make one car at a time. Where they can't start on building the next car before the last one is finished.

Anyway good luck, and feel free to ask any questions.

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