Managed wrapper for Direct3D10 - Swap chains
By Ralf "Demirug" Kornmann, May 8 2006
Most of us Direct3D developers may have never dealt with a swap chain directly, as everything we needed was part of the Direct3D 9 device. As we've already mentioned in the last chapter, Direct3D 10 doesn't do this for us anymore. We have to create every swap chain we need, including the primary one, as part of the initialization. To do this we will leave the Direct3D 10 namespace and enter the graphics infrastructure part of DirectX, the DXGI namespace. Together with Direct3D 10 this forms the new graphics API for the next generation hardware. Unlike Direct3D 10, which will replaced for a future chip generation, the graphics infrastructure part will remain unchanged for future versions of Direct3D. It contains everything that is not bound to a special Direct3D version, like the hardware enumeration or the swap chains.
To create the swap chain we need, we'll need to pass some more parameters to the constructor than we needed for the device, as shown in de code listing above. Most of them should look familiar from the Direct3D 9 present parameters though. The first one is always the device that we have created in the first step. The next one will be a display mode description, which controls the size and format of the back buffer and -in case we are going to full screen mode- some additional parameters for the display. As there are still some possible hardware limits, especially in full screen mode, we should check if our mode is valid for our hardware adapter. We will add this later however and until then we'll use a safe window mode setup which is guaranteed to work on D3D10 hardware.
After this we have to pass the settings for the multisampling quality we want for the back buffer. Again we should check the available qualities, but as we prefer a quick start we'll postpone this to later on and do without multisampling for now. This will always work fine and with the slow reference driver we should not use multisampling anyway. Next the swap chain needs to know what we want to do with the back buffer which it will create for us. At least we'll need to use it as a render target for our device, but we can also specify that it can be used as an input for a shader. This would be useful if we want to do some fancy post filter effects. With the number of back buffers, we pass the last parameter for our buffer creation, but we'll need to supply a bit more information for the swap chain.
The first parameter of this second block controls the maximum latency for the frames in the new swap chain. We leave this at the default value and pass in zero. Even with the new graphics API we are still in the world of Windows and have to share the desktop with other programs. This makes it necessary to bind the swap chain to our own Window, which we do by passing in pass the form handle. A Boolean parameter controls if our swap chain will start in windows or full screen mode. After this here are only two parameters left.
As in Direct3D 9 we still can control how the back and front buffer should be swapped. Currently the new API only provides two swap effects instead of the three available in D3D9. Discard and Copy remain, but Flip is gone. The behavior for these two remaining swap effects remains unchanged. As Discard is still the fastest swap effect, we'll use this in our sample. The final parameter tells the swap chain if our back buffer is rotated by some specified angle.
With these 10 parameters we have created our swap chain, but unfortunately we are still not able to render anything, because our device still doesn't have our back buffer attached. The next step is attaching the back buffer from our swap chain to our device.
Back to MDX10 device creation | Continue reading about Back buffer attachment
Files for this article
|MDX10 wrapper & tutorials.zip||135.7 KB|