Quick Q about vertex buffers

Started by
4 comments, last by Damocles 14 years, 8 months ago
Is it possible to point a vertex buffer to a region of memory? I know the normal method is to lock the buffer, then copy all the data in, then unlock. Is there a way to lock it, tell it the data starts at memory address X, then unlock it?
------------------------------------------[New Delta Games] | [Sliders]
Advertisement
Not as far as I know in DirectX <= 9.0. Try DrawPrimitiveUP() it can be pointed to a memory region but isn't required to fit the DX9 VB structure.
Be aware that DPUP can not be actually *pointed* to a memory region (like you could do on some platforms where CPU and GPU share the same memory -- xbox360, wii, etc)
Actually, DPUP will copy the specified region to an area accessible by the GPU. This is usually inefficient.
Yeah, I figured that was the case. Thanks guys. I can't use draw*UP because I'm looking to use geometry instancing, so I was hoping to use the features of std::vector to manage the data directly in the instancing vertex buffer. I guess I'll have to write my own std::vector-esque functions to manage the vb manually.
------------------------------------------[New Delta Games] | [Sliders]
Quote:Original post by Damocles
Yeah, I figured that was the case. Thanks guys. I can't use draw*UP because I'm looking to use geometry instancing, so I was hoping to use the features of std::vector to manage the data directly in the instancing vertex buffer. I guess I'll have to write my own std::vector-esque functions to manage the vb manually.

Don't. There's a reason why the usual method is to lock the buffer, copy everything in, and unlock it again. It's because it's the most efficient method (unless your vertex generation is so trivial you can lock the buffer and generate your vertices directly into it).

To manipulate a VB like a vector, you would either have to:
1) constantly lock/unlock the buffer every time you want to modify the collection
2) keep the buffer constantly locked, and unlock only when you want to render.

Both these options are terrible performance-wise. Locking is not free. And you want to keep your lock for as short of a time as possible.

Generate/modify your vertices in your vector. Then copy them over when you want to render.
NextWar: The Quest for Earth available now for Windows Phone 7.
ok, thanks for the warning sc4, I'll stick with the standard method then.
------------------------------------------[New Delta Games] | [Sliders]

This topic is closed to new replies.

Advertisement