Graphics Reference
In-Depth Information
// Retrieve the underlying DXGI Device from the D3D Device.
// Access the adapter used for that device and then create
// the swap chain
using (var dxgiDevice2 = device.QueryInterface<SharpDX.DXGI.
Device2>())
using (var dxgiAdapter = dxgiDevice2.Adapter)
using (var dxgiFactory2 = dxgiAdapter.GetParent<SharpDX.DXGI.
Factory2>())
using (var output = dxgiAdapter.Outputs.First())
{
// The CreateSwapChain method allows us to override the
// method of swap chain creation.
_swapChain = ToDispose( CreateSwapChain(dxgiFactory2, device,
desc));
// Retrieve the list of supported display modes
DisplayModeList = output.GetDisplayModeList(desc.Format,
DisplayModeEnumerationFlags.Scaling
}
5.
With the swap chain resized or initialized, we retrieve the back buffer and create a
render target view (RTV) for it.
// Obtain the backbuffer for this window
BackBuffer = ToDispose (
Texture2D.FromSwapChain<Texture2D>(_swapChain, 0));
// Create an RTV for the rendertarget.
RenderTargetView = ToDispose (new RenderTargetView(device,
BackBuffer));
6.
Next, we create the viewport. This is used by the rasterizer stage to map vertices from
3D clip space to 2D render target positions. We assign the viewport to the rasterizer
stage using the SetViewport method.
// Create a viewport descriptor of the render size.
var viewport = new SharpDX.ViewportF(
(float)RenderTargetBounds.X,
(float)RenderTargetBounds.Y,
(float)RenderTargetBounds.Width,
(float)RenderTargetBounds.Height,
0.0f, // min depth
1.0f); // max depth
// Set the current viewport for the rasterizer stage.
context.Rasterizer.SetViewport(viewport);
 
Search WWH ::




Custom Search