/// <summary> /// Finds the best device that is compatible with the preferences defined in this instance. /// </summary> /// <param name="anySuitableDevice">if set to <c>true</c> a device can be selected from any existing adapters, otherwise, it will select only from default adapter.</param> /// <returns>The graphics device information.</returns> protected virtual GraphicsDeviceInformation FindBestDevice(bool anySuitableDevice) { // Setup preferred parameters before passing them to the factory var preferredParameters = new GameGraphicsParameters { PreferredVideoAdapter = PreferredVideoAdapter, PreferredBackBufferWidth = PreferredBackBufferWidth, PreferredBackBufferHeight = PreferredBackBufferHeight, PreferredBackBufferFormat = PreferredBackBufferFormat, PreferredDepthStencilFormat = PreferredDepthStencilFormat, IsFullScreen = IsFullScreen, PreferMultiSampling = PreferMultiSampling, SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace, PreferredGraphicsProfile = (FeatureLevel[])PreferredGraphicsProfile.Clone(), }; // Setup resized value if there is a resize pending if (!IsFullScreen && isBackBufferToResize) { preferredParameters.PreferredBackBufferWidth = resizedBackBufferWidth; preferredParameters.PreferredBackBufferHeight = resizedBackBufferHeight; } var devices = game.GamePlatform.FindBestDevices(preferredParameters); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found"); } return(devices[0]); }
/// <summary> /// Finds the best device that is compatible with the preferences defined in this instance. /// </summary> /// <param name="anySuitableDevice">if set to <c>true</c> a device can be selected from any existing adapters, otherwise, it will select only from default adapter.</param> /// <returns>The graphics device information.</returns> protected virtual GraphicsDeviceInformation FindBestDevice(bool anySuitableDevice) { // Setup preferred parameters before passing them to the factory var preferredParameters = new GameGraphicsParameters { PreferredBackBufferWidth = PreferredBackBufferWidth, PreferredBackBufferHeight = PreferredBackBufferHeight, PreferredBackBufferFormat = PreferredBackBufferFormat, PreferredDepthStencilFormat = PreferredDepthStencilFormat, PreferredRefreshRate = PreferredRefreshRate, PreferredFullScreenOutputIndex = PreferredFullScreenOutputIndex, IsFullScreen = IsFullScreen, PreferMultiSampling = PreferMultiSampling, SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace, PreferredGraphicsProfile = (GraphicsProfile[])PreferredGraphicsProfile.Clone(), }; // Setup resized value if there is a resize pending if (!IsFullScreen && isBackBufferToResize) { preferredParameters.PreferredBackBufferWidth = resizedBackBufferWidth; preferredParameters.PreferredBackBufferHeight = resizedBackBufferHeight; } GraphicsProfile availableGraphicsProfile; if (!IsPreferredProfileAvailable(preferredParameters.PreferredGraphicsProfile, out availableGraphicsProfile)) { throw new InvalidOperationException(string.Format("Graphics profiles [{0}] are not supported by the device. The highest available profile is [{1}].", string.Join(", ", preferredParameters.PreferredGraphicsProfile), availableGraphicsProfile)); } var devices = graphicsDeviceFactory.FindBestDevices(preferredParameters); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found"); } RankDevices(devices); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found after ranking"); } return(devices[0]); }
/// <summary> /// Finds the best device that is compatible with the preferences defined in this instance. /// </summary> /// <param name="anySuitableDevice">if set to <c>true</c> a device can be selected from any existing adapters, otherwise, it will select only from default adapter.</param> /// <returns>The graphics device information.</returns> protected virtual DeviceInformation FindBestDevice(bool anySuitableDevice) { // Setup preferred parameters before passing them to the factory var preferredParameters = new ApplicationGraphicsParameters { PreferredBackBufferWidth = PreferredBackBufferWidth, PreferredBackBufferHeight = PreferredBackBufferHeight, PreferredBackBufferFormat = PreferredBackBufferFormat, PreferredDepthStencilFormat = PreferredDepthStencilFormat, IsFullScreen = IsFullScreen, IsStereo = IsStereo, PreferredFullScreenOutputIndex = PreferredFullScreenOutputIndex, DepthBufferShaderResource = DepthBufferShaderResource, PreferMultiSampling = PreferMultiSampling, SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace, PreferredGraphicsProfile = (FeatureLevel[])PreferredGraphicsProfile.Clone(), PreferredMultiSampleCount = PreferMultiSampling ? PreferredMultiSampleCount : 1, }; // Setup resized value if there is a resize pending if (!IsFullScreen && isBackBufferToResize) { preferredParameters.PreferredBackBufferWidth = resizedBackBufferWidth; preferredParameters.PreferredBackBufferHeight = resizedBackBufferHeight; } var devices = deviceFactory.FindBestDevices(preferredParameters); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found"); } RankDevices(devices); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found after ranking"); } return(devices[0]); }
/// <summary> /// Finds the best device that is compatible with the preferences defined in this instance. /// </summary> /// <param name="anySuitableDevice">if set to <c>true</c> a device can be selected from any existing adapters, otherwise, it will select only from default adapter.</param> /// <returns>The graphics device information.</returns> protected virtual GraphicsDeviceInformation FindBestDevice(bool anySuitableDevice) { // Setup preferred parameters before passing them to the factory var preferredParameters = new GameGraphicsParameters { PreferredBackBufferWidth = PreferredBackBufferWidth, PreferredBackBufferHeight = PreferredBackBufferHeight, PreferredBackBufferFormat = PreferredBackBufferFormat, PreferredDepthStencilFormat = PreferredDepthStencilFormat, PreferredRefreshRate = PreferredRefreshRate, PreferredFullScreenOutputIndex = PreferredFullScreenOutputIndex, IsFullScreen = IsFullScreen, PreferredMultiSampleLevel = PreferredMultiSampleLevel, SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace, PreferredGraphicsProfile = (GraphicsProfile[])PreferredGraphicsProfile.Clone(), ColorSpace = PreferredColorSpace, RequiredAdapterUid = RequiredAdapterUid }; // Remap to Srgb backbuffer if necessary if (PreferredColorSpace == ColorSpace.Linear) { // If the device support SRgb and ColorSpace is linear, we use automatically a SRgb backbuffer if (preferredParameters.PreferredBackBufferFormat == PixelFormat.R8G8B8A8_UNorm) { preferredParameters.PreferredBackBufferFormat = PixelFormat.R8G8B8A8_UNorm_SRgb; } else if (preferredParameters.PreferredBackBufferFormat == PixelFormat.B8G8R8A8_UNorm) { preferredParameters.PreferredBackBufferFormat = PixelFormat.B8G8R8A8_UNorm_SRgb; } } else { // If we are looking for gamma and the backbuffer format is SRgb, switch back to non srgb if (preferredParameters.PreferredBackBufferFormat == PixelFormat.R8G8B8A8_UNorm_SRgb) { preferredParameters.PreferredBackBufferFormat = PixelFormat.R8G8B8A8_UNorm; } else if (preferredParameters.PreferredBackBufferFormat == PixelFormat.B8G8R8A8_UNorm_SRgb) { preferredParameters.PreferredBackBufferFormat = PixelFormat.B8G8R8A8_UNorm; } } // Setup resized value if there is a resize pending if (!IsFullScreen && isBackBufferToResize) { preferredParameters.PreferredBackBufferWidth = resizedBackBufferWidth; preferredParameters.PreferredBackBufferHeight = resizedBackBufferHeight; } GraphicsProfile availableGraphicsProfile; if (!IsPreferredProfileAvailable(preferredParameters.PreferredGraphicsProfile, out availableGraphicsProfile)) { throw new InvalidOperationException($"Graphics profiles [{string.Join(", ", preferredParameters.PreferredGraphicsProfile)}] are not supported by the device. The highest available profile is [{availableGraphicsProfile}]."); } var devices = graphicsDeviceFactory.FindBestDevices(preferredParameters); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found"); } RankDevices(devices); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found after ranking"); } return(devices[0]); }
/// <summary> /// Finds the best device that is compatible with the preferences defined in this instance. /// </summary> /// <param name="anySuitableDevice">if set to <c>true</c> a device can be selected from any existing adapters, otherwise, it will select only from default adapter.</param> /// <returns>The graphics device information.</returns> protected virtual GraphicsDeviceInformation FindBestDevice(bool anySuitableDevice) { // Setup preferred parameters before passing them to the factory var preferredParameters = new GameGraphicsParameters { PreferredBackBufferWidth = PreferredBackBufferWidth, PreferredBackBufferHeight = PreferredBackBufferHeight, PreferredBackBufferFormat = PreferredBackBufferFormat, PreferredDepthStencilFormat = PreferredDepthStencilFormat, PreferredRefreshRate = PreferredRefreshRate, PreferredFullScreenOutputIndex = PreferredFullScreenOutputIndex, IsFullScreen = IsFullScreen, PreferredMultisampleCount = PreferredMultisampleCount, SynchronizeWithVerticalRetrace = SynchronizeWithVerticalRetrace, PreferredGraphicsProfile = (GraphicsProfile[])PreferredGraphicsProfile.Clone(), ColorSpace = PreferredColorSpace, RequiredAdapterUid = RequiredAdapterUid, }; // Remap to Srgb backbuffer if necessary if (PreferredColorSpace == ColorSpace.Linear) { // If the device support SRgb and ColorSpace is linear, we use automatically a SRgb backbuffer preferredParameters.PreferredBackBufferFormat = preferredParameters.PreferredBackBufferFormat.ToSRgb(); } else { // If we are looking for gamma and the backbuffer format is SRgb, switch back to non srgb preferredParameters.PreferredBackBufferFormat = preferredParameters.PreferredBackBufferFormat.ToNonSRgb(); } // Setup resized value if there is a resize pending if (!IsFullScreen && isBackBufferToResize) { preferredParameters.PreferredBackBufferWidth = resizedBackBufferWidth; preferredParameters.PreferredBackBufferHeight = resizedBackBufferHeight; } var devices = graphicsDeviceFactory.FindBestDevices(preferredParameters); if (devices.Count == 0) { // Nothing was found; first, let's check if graphics profile was actually supported // Note: we don't do this preemptively because in some cases it seems to take lot of time (happened on a test machine, several seconds freeze on ID3D11Device.Release()) GraphicsProfile availableGraphicsProfile; if (!IsPreferredProfileAvailable(preferredParameters.PreferredGraphicsProfile, out availableGraphicsProfile)) { throw new InvalidOperationException($"Graphics profiles [{string.Join(", ", preferredParameters.PreferredGraphicsProfile)}] are not supported by the device. The highest available profile is [{availableGraphicsProfile}]."); } // Otherwise, there was just no screen mode throw new InvalidOperationException("No screen modes found"); } RankDevices(devices); if (devices.Count == 0) { throw new InvalidOperationException("No screen modes found after ranking"); } return(devices[0]); }