Swap chains(DX9)

Started by
3 comments, last by L. Spiro 11 years, 6 months ago
So I have taken a pretty long break from working on my home grown engine, and I am now getting back into it. Before I quit for the time, I had converted my rendering pipeline from a FFP to a PP(deferred rendering ect...). Before I had converted, I was using swap chains to present to multiple window handles, but I am now implementing that into my new deferred pipeline. My current implementation is simply overriding the window handle parameter on device->Present() . So my question is, why even use swap chains ever? I thought there only functionality was to present to multiple windows, but you can do that by simply overriding the parameter in Present(). Its been a while since I last used swap chains, so I kind of have forgotten their main purpose.
Advertisement
If you are drawing to windows with different resolutions, you need multiple swap chains.

If you are drawing to windows with different resolutions, you need multiple swap chains.


Could you explain a little bit? I am currently drawing to my main screen(1024 x 768) and to a mini window(300 x 200) and I have not encountered any issues. Far as I can remember, the d3d device will automatically take care of presenting between different resolutions
If you use the same swap chain for both windows, then both images are drawn at exactly the same resolution. When you present, if the window is smaller than the swap chain, the frame is shrunk (and distorted) to fit. If the window is larger, the frame is stretched to fit.

If both windows have nearly the same aspect ratio, this won't be too noticable visually as long as your swap chain is larger than the largest window, but you're still drawing at a higher resolution than necessary and wasting time. If your windows have very different resolutions, (like a main editing window and a long narrow toolbar that has 3d models rendered to it) then you will notice the stretching.

Edit: here's two comparisons. The first is a 1024x768 and 1024x200 window rendering the exact same thing with one swap chain, only the resolutions of the windows are different. As you can see the 768 pixel tall back buffer is getting distorted to fit into a 200 pixel tall window. The second image is the same thing but using 2 swap chains of the appropriate size.

http://img542.imageshack.us/img542/2174/singlee.jpg

http://img13.imageshack.us/img13/1403/multiplep.jpg
You have to create your device with your main window normally, because you have to have a window to create a device.
Afterwards you have to call CreateAdditionalSwapChain() for each following window you want to add to your system. You must also create depth/stencil buffers for them manually.

Finally, when rendering to a window, put the correct back buffer as render target 0, clear/render, and call Present() on the correct swap chain.

Then of course you need to resize them each when their respective windows change size, with special-case handling of the main window since you should resize it through the device rather than directly (to allow the depth/buffers for the main window to be resized).


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement