Graphics Reference
In-Depth Information
Loading and compiling resources
asynchronously
Within Windows Store apps, it is desirable to keep your application as responsive as possible
at all times. Instead of showing a static splash screen for the duration of compiling shaders
and loading resources, in this recipe we will initialize our renderers and resources using the
async / await keywords.
Getting ready
For this recipe, we will continue from where we left off in the previous recipe Rendering to an
XAML SwapChainPanel .
How to do it…
We will first make changes to the SwapChainPanel C# class file and then update the
CreateDeviceDependentResources implementation to support asynchronous resource
creation. Lastly, we will take a look at some of the additional changes necessary within the
code for loading meshes and textures.
1.
Let's begin by opening the D3DPanel.xaml.cs file and registering an event handler
for the Loaded event within the constructor.
public D3DPanel()
{
this.InitializeComponent();
this.Loaded += swapChainPanel_Loaded;
CompositionTarget.Rendering +=
CompositionTarget_Rendering;
}
private void swapChainPanel_Loaded(object sender,
RoutedEventArgs e)
{
...
}
2.
We will move the initialization of the D3DApp descendent of
D3DAppSwapChainPanelTarget from the default constructor into the Loaded
event handler.
// Only use Direct3D if outside of the designer
if (!Windows.ApplicationModel.DesignMode.DesignModeEnabled)
{
 
Search WWH ::




Custom Search