Example #1
0
        public void ApplyChanges()
        {
            // Calling ApplyChanges() before CreateDevice() should have no effect.
            if (graphicsDevice == null)
            {
                return;
            }

            // Recreate device information before resetting
            GraphicsDeviceInformation gdi = new GraphicsDeviceInformation();

            gdi.Adapter                = GraphicsDevice.Adapter;
            gdi.GraphicsProfile        = GraphicsDevice.GraphicsProfile;
            gdi.PresentationParameters = GraphicsDevice.PresentationParameters.Clone();

            /* Apply the GraphicsDevice changes to the new Parameters.
             * Note that PreparingDeviceSettings can override any of these!
             * -flibit
             */
            gdi.PresentationParameters.BackBufferFormat =
                PreferredBackBufferFormat;
            if (useResizedBackBuffer)
            {
                gdi.PresentationParameters.BackBufferWidth =
                    resizedBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    resizedBackBufferHeight;
                useResizedBackBuffer = false;
            }
            else
            {
                gdi.PresentationParameters.BackBufferWidth =
                    PreferredBackBufferWidth;
                gdi.PresentationParameters.BackBufferHeight =
                    PreferredBackBufferHeight;
            }
            gdi.PresentationParameters.DepthStencilFormat =
                PreferredDepthStencilFormat;
            gdi.PresentationParameters.IsFullScreen =
                IsFullScreen;
            if (!PreferMultiSampling)
            {
                gdi.PresentationParameters.MultiSampleCount = 0;
            }
            else if (gdi.PresentationParameters.MultiSampleCount == 0)
            {
                /* XNA4 seems to have an upper limit of 8, but I'm willing to
                 * limit this only in GraphicsDeviceManager's default setting.
                 * If you want even higher values, Reset() with a custom value.
                 * -flibit
                 */
                gdi.PresentationParameters.MultiSampleCount = Math.Min(
                    GraphicsDevice.GLDevice.MaxMultiSampleCount,
                    8
                    );
            }

            // Give the user a chance to override the above settings.
            OnPreparingDeviceSettings(
                this,
                new PreparingDeviceSettingsEventArgs(gdi)
                );

            // Reset!
            game.Window.BeginScreenDeviceChange(
                gdi.PresentationParameters.IsFullScreen
                );
            game.Window.EndScreenDeviceChange(
                gdi.Adapter.DeviceName,
                gdi.PresentationParameters.BackBufferWidth,
                gdi.PresentationParameters.BackBufferHeight
                );
            // FIXME: This should be before EndScreenDeviceChange! -flibit
            GraphicsDevice.Reset(
                gdi.PresentationParameters,
                gdi.Adapter
                );

            // Apply the PresentInterval.
            FNAPlatform.SetPresentationInterval(
                SynchronizeWithVerticalRetrace ?
                gdi.PresentationParameters.PresentationInterval :
                PresentInterval.Immediate
                );
        }