Graphics Reference
In-Depth Information
Within the
Direct3D Initialization
region and after the window is created, we have
changed the declaration of the
device
and
swapChain
variables to be of type
Device1
and
SwapChain1
. We then create
Device
with the same parameters as before except
using a constructor rather than the previous
Device.CreateWithSwapChain
method.
This is done within a
using
statement so that the reference to the first device is automatically
disposed. Within the using block we query the device for a reference to the
Device1
class.
If the implementation of
Device1
was unavailable in the Direct3D API, the return value from
device11.QueryInterfaceOrNull<Device1>
would be
null
while using the regular
QueryInterface<T>
method would result in a
SharpDX.SharpDXException
being thrown.
All SharpDX classes that wrap a native COM object support a
number of variations of the
QueryInterface
method to query
the underlying
IUnknown
interface.
To create the swap chain, we need to first get a reference to a
SharpDX.DXGI.Factory2
instance. Rather than creating a new factory, we will use the one that was initialized internally
to create our device. All device instances also implement the interface for
SharpDX.DXGI.
Device
, which gives us access to the
Adapter
property. As this is provided by the DXGI API
we can work our way back from the device to a
SharpDX.DXGI.Factory2
instance via the
GetParent
method.
The equivalent unmanaged example of this section would look something like:
// pd3dDevice creation omitted
IDXGIDevice2* pDXGIDevice;
hr = pd3dDevice->QueryInterface(__uuidof(IDXGIDevice2),
&pDXGIDevice);
IDXGIAdapter* pDXGIAdapter;
hr = pDXGIDevice->GetParent(__uuidof(IDXGIAdapter),
&pDXGIAdapter);
IDXGIFactory2* pDXGIFactory;
pDXGIAdapter->GetParent(__uuidof(IDXGIFactory2), &pDXGIFactory);
Describing the swap chain for Direct3D 11.1 is slightly different as it separates the
description into two structures. The first structure,
SwapChainDescription1
, describes
the buffer size, format, size, usage, and so on like the original but introduces a
Stereo
and
Scaling
option and excludes the fullscreen properties. The second structure,
SwapChainFullScreenDescription
, describes the fullscreen behavior of the swap
chain also with a
Scaling
option.