Graphics Reference
In-Depth Information
2.
Within your class descending from D3DApplicationBase
(or D3DApplicationDesktop and so on), be sure to call the base
implementation, and then initialize the resources as required. The following
code snippet shows how initializing a Direct3D shader resource might look like.
public class D3DApp: Common.D3DApplicationDesktop
{
Texture2D myShaderResource;
protected override void
CreateDeviceDependentResources(
DeviceManager deviceManager)
{
// Call base implementation
base.CreateDeviceDependentResources(deviceManager);
// Release existing resources
RemoveAndDispose(ref myShaderResource);
// Retrieve device reference
var device = deviceManager.Direct3DDevice;
// Create a shader resource view
myShaderResource = ToDispose (
ShaderResourceView.FromFile(device, "Texture.png"));
...
}
...
How it works…
By handling the device manager's OnInitialize event our Direct3D applications
descendent class is able to create its Direct3D device resources when the device is
ready, or whenever the device instance is recreated.
The D3DApplicationBase base class provides the minimal code necessary to
ensure that any existing swap chain is released and then recreated by triggering the
D3DApplicationBase.OnSizeChanged event. Unless completely overriding the
base implementation, it is important that our overrides call this base implementation.
After calling the base implementation, our own code needs to release any resources that
may have been created previously by using the SharpDX.Component.RemoveAndDispose
method. Then we retrieve the currently active Direct3D device from the device manager and
continue to create any necessary resources.
 
Search WWH ::




Custom Search