Sign in to follow this  

One device / render target?

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm new at direct3d programming so forgive me if this is a stupid question. Are you supposed to have one device for each rendering target (I call it viewport - correct terminology?) the application might use? Say I want to create a scene editor that renders my scene from four different views: top, left, right and free. The top, left and right using ortohgraphic projection and free using perspective. How do you do this in direct3d? I need to know this so I know how to design my renderer.

Share this post


Link to post
Share on other sites
You should definitely have single device. Create multiple render targets if you need but from single device.

The quote below is taken from http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndxgen/html/directx9devfaq.asp

Quote:
Use only a single Direct3D device. If you need to render to multiple targets, use SetRenderTarget. If you are creating a windowed application with multiple 3D windows, use the CreateAdditionalSwapChain API. The runtime is optimized for a single device and there is a considerable speed penalty for using multiple devices.

GL! :)

Share this post


Link to post
Share on other sites
Lots of ways to do things depending on what you want...

To draw to a section of a render target texture or section of the back buffer you can use SetViewport.

You can copy the backbuffer to a window using Present(). You can use it to draw to different windows. Present will scale the backbuffer to fit the window... like a StretchBlit. This can mean you draw many times the resolution of the window, wasting fill time, and GPU memory, then causing a slow (well actually it's fairly fast) stretch blit.

To get truly independant windows with independant back buffers, you should use CreateAdditionalSwapChain(). Using this method you can create as many backbuffers as you want to draw to as many windows as you want. Swap chains also reset quickly on a resize as you don't have to free and recreate all your POOL_DEFAULT objects and state blocks.

If you have windows on multiple monitors, for best performance you'll need a device per monitor. Creating a second device will invalidate the first, requiring you to immediately reset the first device. Once you have a second device, you can then use the backbuffer and/or create Viewports and/or SwapChains as needed for each window on that monitor. Each device will have it's own textures, shaders, vertex buffers, etc. Managing multiple devices can be a royal pain. If you intend to draw the same geometry on multiple devices, you'll have to wrap each D3D object in your own object that will affect the correct object for each card. For instance, when modifying geometry, you'll want to update vertex buffers on each card. When redrawing you'll want your rendering calls to SetStreamSource() with the correct vertex buffer for the card you're currently drawing to.

For windows straddling a monitor boundry, you can either accept the horribly slow drawing that will occur (Windows needs to lock the backbuffer and copy the data to the other card... really, really, slow. Expect 1FPS), or disable drawing while the window is in this state. You could try to get really tricky and draw the correct parts of the window using the correct device. I'm not sure that works or not. Generally it's easier to force the user to move their window unless there is a really good reason to try and support this.

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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