public void RestoreLostDevice()
{
// Release all non-managed resources
// Set all texture units to nothing
DisableTextureUnitsFrom( 0 );
// Unbind any vertex streams
for ( var i = 0; i < _lastVertexSourceCount; ++i )
{
ActiveD3D9Device.SetStreamSource( i, null, 0, 0 );
}
_lastVertexSourceCount = 0;
// Release all automatic temporary buffers and free unused
// temporary buffers, so we doesn't need to recreate them,
// and they will reallocate on demand. This saves a lot of
// release/recreate of non-managed vertex buffers which
// wasn't need at all.
_hardwareBufferManager.ReleaseBufferCopies( true );
// We have to deal with non-managed textures and vertex buffers
// GPU programs don't have to be restored
( (D3DTextureManager)textureManager ).ReleaseDefaultPoolResources();
( _hardwareBufferManager ).ReleaseDefaultPoolResources();
// Reset the device, using the primary window presentation params
try
{
var result = ActiveD3D9Device.Reset(_deviceManager.ActiveDevice.PrimaryWindow.PresentationParameters);
if ( result.Code == ResultCode.DeviceLost.Code )
return;
}
catch ( SlimDXException dlx )
{
LogManager.Instance.Write( "[Error] Received error while trying to restore the device." );
LogManager.Instance.Write( LogManager.BuildExceptionString( dlx ) );
return;
}
catch ( Exception ex )
{
throw new AxiomException( "Cannot reset device!", ex );
}
// will have lost basic states
vertexProgramBound = false;
fragmentProgramBound = false;
// Recreate all non-managed resources
( (D3DTextureManager)textureManager ).RecreateDefaultPoolResources();
( _hardwareBufferManager ).RecreateDefaultPoolResources();
LogManager.Instance.Write( "!!! Direct3D Device successfully restored." );
//device.SetRenderState( D3D.RenderState.Clipping, true );
//TODO fireEvent("DeviceRestored");
}