开发者

How to properly update vertex buffers in DirectX 10

For a开发者_开发技巧 little background: I am working on a project in C++ in which I am trying to draw 3D representations of objects based on real time profile data. The profiling data is gathered from external profiling hardware. The system travels along an object and at a rate of 300 times per second provides my software with a profile slice. Each slice consists of a list of ~8000 X-Y points. The movement of the profiler is recorded by an encoder. The encoder information provides the 3rd dimension of the scan.

Another important thing to note is that the profiler may move back and forth over the object. As this happens, I want to replace previously read/drawn slices with new ones (based on encoder position). As of now, I am achieving this with a circular buffer of slices that I store by the encoder count. This also means that I will want to throw out slices as the buffer fills and begins overwriting old slices. In order to show the proper amount of the subject piece on the screen - I need to draw 1000 slices of profile data at a time. For now I am rendering the object as a point cloud. In the future we may attempt to attach adjacent slices and render as a triangle list.

I am new to DirectX, but using books and online examples I've gotten to the point where I am drawing the object in 3D, but I am convinced that I am not efficiently/properly using Vertex Buffers. Most examples I've found work with very static models. Therefore, they tend to create a single Vertex Buffer with their list of points, and then are just manipulated by matrix transformations. I, on the other hand, will be updating the scene very quickly as I retrieve profile data from our hardware.

Currently I am creating a new Vertex Buffer for each slice I read in. When I draw the scene I loop through my list of up to 1000 buffers and call Draw() for each one. I noticed that if I cut in half the number of Vertex Buffers drawn at a time, my FPS increased significantly, whereas there was little improvement when halving the number of Vertex Points per buffer - so I take that as an indication that the multiple Vertex Buffers is not the proper way to approach this.

So to the guts of my question... I'm wondering if I can put all these vertices in a single Vertex Buffer when the Vertices change so frequently. Can I update the points within an existing Vertex Buffer? Or should I just recreate a single brand new Buffer each time I update the scene? One last thing to keep in mind is that the number of points per slice from the hardware will vary - so when it comes to over-writing previous slices, the new slice may have more or fewer points than the slice being replaced.

Thanks for your time. Any advice will be much appreciated!


You can always update the points within a vertex buffer as long as you make the buffer dynamic (specify D3D10_USAGE_DYNAMIC and use ID3D10Device::CopySubresourceRegion to update only parts of the buffer efficiently). That should be more efficient than re-creating buffers too frequently.

Having different sizes for each slice is bad, however. You could either implement some kind of memory manager to keep the overall fragmentation of your vertex buffers low or this is the point where using multiple vb's is unavoidable. One way would be to round all slices sizes up to a reasonable limit and have one vb for each size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜