我应该如何优化绘制大量动态数量的顶点集合?
……或者我是疯了才去尝试的吗?
作为使用裸顶点进行 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我无法确切说明您要做什么,但是每个四边形使用单独的缓冲区非常愚蠢。
图形编程中的黄金法则是批处理,批处理,批处理。这意味着将尽可能多的东西包装到一个吸引人的呼叫中,您的图形卡会喜欢您。
就您而言,将所有的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.