Game Development Reference
In-Depth Information
m_Viewport = new
Viewport(0.0f,0.0f,m_Form.Width,m_Form.Height,0.0f,1.0f);
m_DeviceContext.Rasterizer.SetViewports(m_Viewport);
m_DeviceContext.OutputMerger.SetTargets(m_RenderTargetView);
// Prevent DXGI handling of Alt+Enter since
it does not work properly with Winforms
using (var factory =
m_SwapChain.GetParent<Factory>())
{
factory.SetWindowAssociation(m_Form.Handle,
WindowAssociationFlags.IgnoreAltEnter);
}
}
As you can see, the first thing we do in this method is create
SwapChainDescrip-
tion
to configure the swap chain we will create in a moment. We are using the
initializer syntax here, which is a handy way for us to set the values of the struct's
properties when it is created. You can use the initializer syntax for structs, arrays,
and lists by opening a brace block after the line that creates the new object, and then
setting the values of its properties inside the brace block.
The
BufferCount
property specifies how many buffers we want to have in our
swap chain, in addition to the front buffer. You should not use more than four buffers
as you will get a performance decrease with too many. In the windowed mode, the
desktop is used as the front buffer, but in the fullscreen mode, a dedicated front buf-
fer is required in the swap chain. The
Usage
property specifies how we intend to
use our swap chain surfaces. The term
surface
refers to a buffer that we will draw
on, so the surfaces of our swap chain are just the buffers that are in it. For the
Out-
putHandle
property, we set this to the handle of our game window to tell it what
window we will be displaying our graphics in. The
IsWindowed
property determines