Graphics Reference
In-Depth Information
Although the panel allows any number of immediate child controls as would a regular grid,
the Microsoft guidelines indicate that no more than eight immediate child controls should be
used. Another best practice is to avoid placing a control over the entire swap chain panel in
order to prevent overdraws. Each child control of the swap chain panel can then contain any
number of subsequent child controls depending on the element type; for example, the UI in
the top right of each of the previous screenshots is contained within a
StackPanel
instance
that is an immediate child of our
SwapChainPanel
implementation.
By retrieving the
ISwapChainPanelNative
interface from the
SwapChainPanel
instance, we have connected our new swap chain to the panel through the
ISwapChainPanelNative.SwapChain
property (natively this is done through the
ISwapChainPanelNative.SetSwapChain
method). The panel then takes care of
associating the swap chain with the appropriate area on the screen.
The
Windows.UI.Xaml.Media.CompositionTarget
class is a static class that
represents the display surface on which our application is being drawn. The
Rendering
event is fired for each frame, allowing us to integrate our Direct3D rendering with the XAML
scene. For applications that require more control over the frame rate, a separate rendering
loop thread can be implemented, provided there is appropriate synchronization in place to
prevent threading issues when resizing/rescaling during the render loop.
As with the previous recipe, we must set the Output Merger render targets in each frame of
our
D3DApp
class's
Render
method.
There's more…
When changing the size of a composition swap chain, it is possible to set the
SwapChain2.
SourceSize
property provided, the new size is less than or equal to the original swap chain
size. This identifies a portion of the swap chain to be used when presenting its contents to the
display and is more efficient than using the
SwapChain.ResizeBuffers
function which
forces the swap chain buffers to be physically resized.
There are a couple of other approaches to rendering Direct3D surfaces to XAML controls using
brushes. We can use the
Windows.UI.Xaml.Media.Imaging.SurfaceImageSource
and
Windows.UI.Xaml.Media.Imaging.VirtualSurfaceImageSource
classes and
their corresponding DXGI interfaces,
SharpDX.DXGI.ISurfaceImageSourceNative
and
SharpDX.DXGI.IVirtualSurfaceImageSourceNative
respectively. However, these
are not suitable for real-time rendering—instead they can be useful for effects or rendering
content that requires less frequent updates.
See also
F
For more information on XAML and DirectX interoperation within Windows Store
apps using
SurfaceImageSource
, see
http://msdn.microsoft.com/en-us/
library/hh825871.aspx