Sdílet prostřednictvím


How to: Use the Reference Device

This example demonstrates how to create a custom PreparingDeviceSettings event handler to change the device creation parameters used by a GraphicsDeviceManager prior to the device being created.

For this example, the device type of the graphics device will be changed to a reference device. The reference device accurately emulates every Direct3D feature in software rather than hardware. As a result, the reference device is not very fast. The reference device does make use of special CPU instructions whenever it can, but it is not intended for retail applications.

Warning

Use the reference rasterizer only for feature testing or demonstration purposes. The reference device is not available for the Xbox 360.

To use the reference device

  1. In the constructor for the game, after the GraphicsDeviceManager is created, add an event handler for the PreparingDeviceSettings event to the GraphicsDeviceManager. In this example, the event handler is named graphics_PreparingDeviceSettings.

    graphics = new GraphicsDeviceManager( this );
    graphics.PreparingDeviceSettings +=
        new EventHandler<PreparingDeviceSettingsEventArgs>(
                            graphics_PreparingDeviceSettings );
    
  2. In the graphics_PreparingDeviceSettings method, add the code to change the device creation parameters. In the following example, the event handler is implemented to change the device creation parameters to create a device of type DeviceType.Reference with software vertex processing.

    void graphics_PreparingDeviceSettings( object sender, PreparingDeviceSettingsEventArgs e )
    {
        e.GraphicsDeviceInformation.CreationOptions =
            CreateOptions.SoftwareVertexProcessing;
        e.GraphicsDeviceInformation.DeviceType =
            DeviceType.Reference;
        e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType =
            MultiSampleType.None;
    
    }