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); } } } }
private void ChangeDevice(bool forceCreate) { if (this.game == null) { throw new InvalidOperationException("Graphics component not attached to game"); } this.CheckForAvailableSupportedHardware(); this.inDeviceTransition = true; string screenDeviceName = this.game.Window.Title; int width = (int)this.game.Window.ActualWidth; int height = (int)this.game.Window.ActualHeight; bool flag = false; try { GraphicsDeviceInformation graphicsDeviceInformation = this.FindBestDevice(forceCreate); //this.game.Window.BeginScreenDeviceChange(graphicsDeviceInformation.PresentationParameters.IsFullScreen); flag = true; bool flag2 = true; if (!forceCreate && (this.device != null)) { this.OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation)); if (this.CanResetDevice(graphicsDeviceInformation)) { try { GraphicsDeviceInformation information2 = graphicsDeviceInformation.Clone(); this.MassagePresentParameters(graphicsDeviceInformation.PresentationParameters); this.ValidateGraphicsDeviceInformation(graphicsDeviceInformation); this.device.Reset(information2.PresentationParameters, information2.Adapter); flag2 = false; } catch { } } } if (flag2) { this.CreateDevice(graphicsDeviceInformation); } PresentationParameters presentationParameters = this.device.PresentationParameters; screenDeviceName = this.device.CreationParameters.Adapter.DeviceName; this.isReallyFullScreen = presentationParameters.IsFullScreen; if (presentationParameters.BackBufferWidth != 0) { width = presentationParameters.BackBufferWidth; } if (presentationParameters.BackBufferHeight != 0) { height = presentationParameters.BackBufferHeight; } this.isDeviceDirty = false; } finally { if (flag) { //this.game.Window.EndScreenDeviceChange(screenDeviceName, width, height); } this.inDeviceTransition = false; } }
private void ChangeDevice(bool forceCreate) { if (this.m_objGame == null) { throw new InvalidOperationException(Resources.GraphicsComponentNotAttachedToGame); } this.m_bInDeviceTransition = true; string screenDeviceName = string.Empty; int width = 0; int height = 0; if (this.m_objGame.Canvas != null && this.m_objGame.Canvas.Window != null) { screenDeviceName = this.m_objGame.Canvas.Window.Title; width = (int)this.m_objGame.Canvas.Window.ActualWidth; height = (int)this.m_objGame.Canvas.Window.ActualHeight; } bool flag = false; try { GraphicsDeviceInformation graphicsDeviceInformation = this.FindBestDevice(forceCreate); //this.game.Window.BeginScreenDeviceChange(graphicsDeviceInformation.PresentationParameters.IsFullScreen); flag = true; bool flag2 = true; if (!forceCreate && (this.m_objDevice != null)) { this.OnPreparingDeviceSettings(this, new PreparingDeviceSettingsEventArgs(graphicsDeviceInformation)); if (this.CanResetDevice(graphicsDeviceInformation)) { try { GraphicsDeviceInformation information2 = graphicsDeviceInformation.Clone(); MassagePresentParameters(graphicsDeviceInformation.PresentationParameters); ValidateGraphicsDeviceInformation(graphicsDeviceInformation); m_objDevice.Reset(information2.PresentationParameters, information2.Adapter); flag2 = false; } catch { } } } if (flag2) { this.CreateDevice(graphicsDeviceInformation); } PresentationParameters presentationParameters = this.m_objDevice.PresentationParameters; screenDeviceName = this.m_objDevice.Adapter.DeviceName; this.m_bIsReallyFullScreen = presentationParameters.IsFullScreen; if (presentationParameters.BackBufferWidth != 0) { width = presentationParameters.BackBufferWidth; } if (presentationParameters.BackBufferHeight != 0) { height = presentationParameters.BackBufferHeight; } this.m_bIsDeviceDirty = false; } finally { if (flag) { //this.game.Window.EndScreenDeviceChange(screenDeviceName, width, height); } this.m_bInDeviceTransition = false; } }