Sign in to follow this  
Zipster

[.net] [MDX] :: Avoiding Buffer Duplication

Recommended Posts

I'm writing a MDX application in C# that is going to be rendering some terrain, among other things. The terrain is rendered in two forms, one which provides the user a nice 3D perspective environment to move around in, and another which is a 2D top-down orthographic view where the user can easily select and manipulate vertices. The terrain object itself uses vertex and index buffers to store the terrain data. Ideally I would like each form to use the same instance of the terrain object, to save on memory and guarantee coherency between the views. However, each form uses its own Direct3D device, since one form renders into the whole client area while another form renders into a PictureBox. Since the vertex and index buffers are device-specific, it appears that I need two copies of the buffers. This is the way I currently have it implemented, and it's quite slow because there are approximately a half-million vertices that need to be copied every time the user displays the edit window. And that's just the vertex buffer - the index buffer is obviously larger! My question is if there's any way for me to use the same vertex and index buffer across multiple devices. If I were to try and trick Direct3D by setting the stream source of one device to a vertex buffer created with another device (same with the index buffer), would there be a chance it works or will MDX just throw an exception? Alternatively, is there an easy way I could get both forms to use the same device? That would solve the problem as well.

Share this post


Link to post
Share on other sites
not across multiple devices, but instead you should only use one device and create multiple swap chains, one for each render target.this way you can still render to multiple windows and share vertex buffers, textures, etc. between them.

basically, you create a PresentParameters for each control you want to render to come and pass that to the SwapChain constructor. Then before you call Device.BeginScene, set the device's render target to the appropriate swap chain's back buffer. Then call Present on the swap chaininstead of the device.

Share this post


Link to post
Share on other sites
Ah, swap chains. I remember those from the good 'ol days of DX7, nice to see they're still around and as useful as ever [smile]

EDIT: Implemented and working, Rating++!

[Edited by - Zipster on September 30, 2006 9:13:44 PM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this