GraphicsDeviceManager.PreparingDeviceSettings Event

Raised when the GraphicsDeviceManager is changing the GraphicsDevice settings (during reset or recreation of the GraphicsDevice).

Namespace: Microsoft.Xna.Framework
Assembly: Microsoft.Xna.Framework.Game (in microsoft.xna.framework.game.dll)

public event EventHandler<PreparingDeviceSettingsEventArgs> PreparingDeviceSettings

Handle PreparingDeviceSettings events to set graphics options for your device - such as antialiasing.

public Game1()
{
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
    graphics.PreferMultiSampling = true;
    graphics.PreparingDeviceSettings +=
      new EventHandler<PreparingDeviceSettingsEventArgs>(graphics_PreparingDeviceSettings);
}
        void graphics_PreparingDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
        {
            // Xbox 360 and most PCs support FourSamples/1 (4x) and TwoSamples/1 (2x)
            // antialiasing.
#if XBOX
            e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 1;
            e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType =
                MultiSampleType.FourSamples;
            return;
#endif
            int quality = 0;
            GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
            SurfaceFormat format = adapter.CurrentDisplayMode.Format;
            // Check for 4xAA
            if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format,
                false, MultiSampleType.FourSamples, out quality))
            {
                // even if a greater quality is returned, we only want quality 1
                e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 1;
                e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType =
                    MultiSampleType.FourSamples;
            }
            // Check for 2xAA
            else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format,
                false, MultiSampleType.TwoSamples, out quality))
            {
                // even if a greater quality is returned, we only want quality 1
                e.GraphicsDeviceInformation.PresentationParameters.MultiSampleQuality = 1;
                e.GraphicsDeviceInformation.PresentationParameters.MultiSampleType =
                    MultiSampleType.TwoSamples;
            }
            return;
        }

Xbox 360, Windows XP SP2, Windows Vista

Community Additions

ADD
Show: