Graphics Reference
In-Depth Information
After the buffer mode description structure, we next specify the options for multisample anti-
aliasing (MSAA). This requires that we select the number of samples and the quality of their sam-
pling pattern. This functionality is discussed in more detail throughout Chapter 2 and Chapter 3,
but for now we will disable it by specifying a single sample per pixel, with a quality of zero.
Next, we indicate the intended usage of the swap chain, which will be used in our
case as a render target output. The BufferCount parameter is used to indicate how many buf-
fers will be used within the swap chain. Having multiple buffers allows DXGI to use one of
the buffers to display the rendered image, while at the same time, Direct3D can be generating
the next frame in a secondary buffer. This allows for smoother animation in the window. It is
common to use two buffers for this purpose, but additional buffers can be used if necessary.
The next two parameters configure the connection to the application window. The
OutputWindow parameter is simply the window handle of the window that will receive the
swap chain's contents. The next parameter, Windowed, indicates what it sounds likeā€”if the
window will appear as a window on the desktop, or if it will occupy the complete screen. This
will vary from application to application, but we will stick with windowed mode for now.
The SwapEffect parameter configures what is done to the buffer contents after they
are presented to the window. This flag is normally set to discard the buffer contents after
presentation, but it can be changed as needed. The final parameter needed to create a swap
chain is a combination of a number of miscellaneous flags that can further configure the
buffer, and how it is used by DXGI. In general, these are special usage flags that can allow
special operations by the application, such as handling monitor rotation, switching between
windowed and full screen modes, and allowing GDI access to the buffers. We won't be us-
ing any of these flags in our example. After all of the parameters are filled in, we also sup-
ply pointers to all of the objects that we expect to receive back. These are the swap chain,
the device, the created device's feature level, and the immediate device context.
It is important to always check the return value from API calls, to ensure that the
function has succeeded. All of the returned items except for the feature level are COM
objects and thus must have their reference counts managed accordingly. After we have the
swap chain interface, we must obtain the texture resource interface from it, for use in the
rendering pipeline. This is done with the IDXGISwapChain: :GetBuffer() method, which
works similarly to the COM query interface method described above. The difference is that
the index of the buffer we are trying to acquire is passed as the first parameter. The acquisi-
tion of the texture interface is shown in Listing 1.6.
ID3DllTexture2D* pSwapChainBuffer = 0;
hr = pSwapChain->GetBuffer( 0,
__uuidof( ID3DllTexture2D ),
(void **)&pSwapChainBuffer );
Listing 1.6. Acquiring the texture interface from a swap chain.
Search WWH ::




Custom Search