Esempio n. 1
0
 private void AddDevices(GraphicsAdapter adapter, DeviceType deviceType, DisplayMode mode,
                         GraphicsDeviceInformation baseDeviceInfo, List <GraphicsDeviceInformation> foundDevices)
 {
     for (int i = 0; i < ValidBackBufferFormats.Length; i++)
     {
         SurfaceFormat backBufferFormat = ValidBackBufferFormats[i];
         if (adapter.CheckDeviceType(deviceType, mode.Format, backBufferFormat, IsFullScreen))
         {
             GraphicsDeviceInformation item = baseDeviceInfo.Clone();
             if (IsFullScreen)
             {
                 item.PresentationParameters.BackBufferWidth           = mode.Width;
                 item.PresentationParameters.BackBufferHeight          = mode.Height;
                 item.PresentationParameters.FullScreenRefreshRateInHz = mode.RefreshRate;
             }
             else if (useResizedBackBuffer)
             {
                 item.PresentationParameters.BackBufferWidth  = resizedBackBufferWidth;
                 item.PresentationParameters.BackBufferHeight = resizedBackBufferHeight;
             }
             else
             {
                 item.PresentationParameters.BackBufferWidth  = PreferredBackBufferWidth;
                 item.PresentationParameters.BackBufferHeight = PreferredBackBufferHeight;
             }
             item.PresentationParameters.BackBufferFormat       = backBufferFormat;
             item.PresentationParameters.AutoDepthStencilFormat = PreferredDepthStencilFormat;
             if (PreferMultiSampling)
             {
                 for (int j = 0; j < multiSampleTypes.Length; j++)
                 {
                     int             qualityLevels = 0;
                     MultiSampleType sampleType    = multiSampleTypes[j];
                     if (
                         adapter.CheckDeviceMultiSampleType(deviceType, backBufferFormat, IsFullScreen,
                                                            sampleType, out qualityLevels))
                     {
                         GraphicsDeviceInformation information2 = item.Clone();
                         information2.PresentationParameters.MultiSampleType = sampleType;
                         if (!foundDevices.Contains(information2))
                         {
                             foundDevices.Add(information2);
                         }
                         break;
                     }
                 }
             }
             else if (!foundDevices.Contains(item))
             {
                 foundDevices.Add(item);
             }
         }
     }
 }
Esempio n. 2
0
 private void AddDevices(GraphicsAdapter adapter, DeviceType deviceType, DisplayMode mode, GraphicsDeviceInformation baseDeviceInfo, List<GraphicsDeviceInformation> foundDevices)
 {
     for (int i = 0; i < ValidBackBufferFormats.Length; i++)
     {
         SurfaceFormat backBufferFormat = ValidBackBufferFormats[i];
         if (adapter.CheckDeviceType(deviceType, mode.Format, backBufferFormat, this.IsFullScreen))
         {
             GraphicsDeviceInformation item = baseDeviceInfo.Clone();
             if (this.IsFullScreen)
             {
                 item.PresentationParameters.BackBufferWidth = mode.Width;
                 item.PresentationParameters.BackBufferHeight = mode.Height;
                 item.PresentationParameters.FullScreenRefreshRateInHz = mode.RefreshRate;
             }
             else if (this.useResizedBackBuffer)
             {
                 item.PresentationParameters.BackBufferWidth = this.resizedBackBufferWidth;
                 item.PresentationParameters.BackBufferHeight = this.resizedBackBufferHeight;
             }
             else
             {
                 item.PresentationParameters.BackBufferWidth = this.PreferredBackBufferWidth;
                 item.PresentationParameters.BackBufferHeight = this.PreferredBackBufferHeight;
             }
             item.PresentationParameters.BackBufferFormat = backBufferFormat;
             item.PresentationParameters.AutoDepthStencilFormat = this.ChooseDepthStencilFormat(adapter, deviceType, mode.Format);
             if (this.PreferMultiSampling)
             {
                 for (int j = 0; j < multiSampleTypes.Length; j++)
                 {
                     int qualityLevels = 0;
                     MultiSampleType sampleType = multiSampleTypes[j];
                     if (adapter.CheckDeviceMultiSampleType(deviceType, backBufferFormat, this.IsFullScreen, sampleType, out qualityLevels))
                     {
                         GraphicsDeviceInformation information2 = item.Clone();
                         information2.PresentationParameters.MultiSampleType = sampleType;
                         if (!foundDevices.Contains(information2))
                         {
                             foundDevices.Add(information2);
                         }
                         break;
                     }
                 }
             }
             else if (!foundDevices.Contains(item))
             {
                 foundDevices.Add(item);
             }
         }
     }
 }
Esempio n. 3
0
        private void ChangeDevice(bool forceCreate)
        {
            if (game == null)
            {
                throw new InvalidOperationException(Resources.GraphicsComponentNotAttachedToGame);
            }
            CheckForAvailableSupportedHardware();
            inDeviceTransition = true;
            string screenDeviceName = game.Window.ScreenDeviceName;
            int    width            = game.Window.ClientBounds.Width;
            int    height           = game.Window.ClientBounds.Height;
            bool   flag             = false;

            try
            {
                GraphicsDeviceInformation graphicsDeviceInformation = FindBestDevice(forceCreate);
                game.Window.BeginScreenDeviceChange(graphicsDeviceInformation.PresentationParameters.IsFullScreen);
                flag = true;
                bool flag2 = true;
                if (!forceCreate && (device != null))
                {
                    OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation));
                    if (CanResetDevice(graphicsDeviceInformation))
                    {
                        try
                        {
                            GraphicsDeviceInformation information2 = graphicsDeviceInformation.Clone();
                            MassagePresentParameters(graphicsDeviceInformation.PresentationParameters);
                            ValidateGraphicsDeviceInformation(graphicsDeviceInformation);
                            device.Reset(information2.PresentationParameters);
                            flag2 = false;
                        }
                        catch
                        {
                        }
                    }
                }
                if (flag2)
                {
                    CreateDevice(graphicsDeviceInformation);
                }
                PresentationParameters presentationParameters = device.PresentationParameters;
                screenDeviceName   = device.CreationParameters.Adapter.DeviceName;
                isReallyFullScreen = presentationParameters.IsFullScreen;
                if (presentationParameters.BackBufferWidth != 0)
                {
                    width = presentationParameters.BackBufferWidth;
                }
                if (presentationParameters.BackBufferHeight != 0)
                {
                    height = presentationParameters.BackBufferHeight;
                }
                isDeviceDirty = false;
            }
            finally
            {
                if (flag)
                {
                    game.Window.EndScreenDeviceChange(screenDeviceName, width, height);
                }
                inDeviceTransition = false;
            }
        }