/// <summary>
        /// Find the display mode that most closely matches the requested display mode.
        /// </summary>
        /// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
        /// <param name="mode">The mode.</param>
        /// <returns>Returns the closes display mode.</returns>
        /// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
        /// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order.  ScanlineOrdering Scaling Format Resolution RefreshRate  When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and  other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering,  Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because  the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output.  If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified  display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output.   Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
        public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
        {
            if (targetProfiles == null) throw new ArgumentNullException("targetProfiles");

            ModeDescription closestDescription;
            SharpDX.Direct3D11.Device deviceTemp = null;
            try
            {
                var features = new SharpDX.Direct3D.FeatureLevel[targetProfiles.Length];
                for (int i = 0; i < targetProfiles.Length; i++)
                {
                    features[i] = (FeatureLevel)targetProfiles[i];
                }

                deviceTemp = new SharpDX.Direct3D11.Device(adapter.NativeAdapter, SharpDX.Direct3D11.DeviceCreationFlags.None, features);
            }
            catch (Exception) { }

            var description = new SharpDX.DXGI.ModeDescription()
            {
                Width = mode.Width,
                Height = mode.Height,
                RefreshRate = mode.RefreshRate.ToSharpDX(),
                Format = (SharpDX.DXGI.Format)mode.Format,
                Scaling = DisplayModeScaling.Unspecified,
                ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
            };
            using (var device = deviceTemp)
                output.GetClosestMatchingMode(device, description, out closestDescription);

            return DisplayMode.FromDescription(closestDescription);
        }
Exemplo n.º 2
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(preferredParameters);

            // Special case where the default FindBestDevices is not working
            if (graphicsDeviceInfos.Count == 0)
            {
                var graphicsAdapter = GraphicsAdapterFactory.Adapters[0];

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                                             {
                                                 Adapter = graphicsAdapter,
                                                 GraphicsProfile = featureLevel,
                                                 PresentationParameters =
                                                     {
                                                         MultiSampleCount = MSAALevel.None,
                                                         IsFullScreen = preferredParameters.IsFullScreen,
                                                         PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                                         DeviceWindowHandle =  MainWindow.NativeWindow,
                                                     }
                                             };

                        // Hardcoded format and refresh rate...
                        // This is a workaround to allow this code to work inside the emulator
                        // but this is not really robust
                        // TODO: Check how to handle this case properly
                        var displayMode = new DisplayMode(PixelFormat.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));
                        AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return graphicsDeviceInfos;
        }
        /// <summary>
        /// Find the display mode that most closely matches the requested display mode.
        /// </summary>
        /// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
        /// <param name="mode">The mode.</param>
        /// <returns>Returns the closes display mode.</returns>
        /// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
        /// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order.  ScanlineOrdering Scaling Format Resolution RefreshRate  When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and  other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering,  Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because  the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output.  If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified  display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output.   Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
        public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
        {
            if (targetProfiles == null) throw new ArgumentNullException("targetProfiles");

            // TODO VULKAN

            //ModeDescription closestDescription;
            //SharpDX.Direct3D12.Device deviceTemp = null;
            //for (int i = 0; i < targetProfiles.Length; i++)
            //{
            //    // Create Device D3D12 with feature Level based on profile
            //    try
            //    {
            //        deviceTemp = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, (FeatureLevel)targetProfiles[i]);
            //        break;
            //    }
            //    catch (Exception)
            //    {
            //    }
            //}

            //if (deviceTemp == null)
            //    throw new InvalidOperationException("Could not create D3D12 graphics device");

            //var description = new SharpDX.DXGI.ModeDescription()
            //{
            //    Width = mode.Width,
            //    Height = mode.Height,
            //    RefreshRate = mode.RefreshRate.ToSharpDX(),
            //    Format = (SharpDX.DXGI.Format)mode.Format,
            //    Scaling = DisplayModeScaling.Unspecified,
            //    ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
            //};
            //using (var device = deviceTemp)
            //    output.GetClosestMatchingMode(device, description, out closestDescription);

            //return DisplayMode.FromDescription(closestDescription);
            return mode;
        }
        /// <summary>
        /// Find the display mode that most closely matches the requested display mode.
        /// </summary>
        /// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
        /// <param name="mode">The mode.</param>
        /// <returns>Returns the closes display mode.</returns>
        /// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
        /// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order.  ScanlineOrdering Scaling Format Resolution RefreshRate  When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and  other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering,  Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because  the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output.  If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified  display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output.   Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
        public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
        {
            if (targetProfiles == null) throw new ArgumentNullException("targetProfiles");

            ModeDescription closestDescription;
            SharpDX.Direct3D12.Device deviceTemp = null;
            for (int i = 0; i < targetProfiles.Length; i++)
            {
                // Create Device D3D12 with feature Level based on profile
                try
                {
                    deviceTemp = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, (FeatureLevel)targetProfiles[i]);
                    break;
                }
                catch (Exception)
                {
                }
            }

            if (deviceTemp == null)
                throw new InvalidOperationException("Could not create D3D12 graphics device");

            var description = new SharpDX.DXGI.ModeDescription()
            {
                Width = mode.Width,
                Height = mode.Height,
                RefreshRate = mode.RefreshRate.ToSharpDX(),
                Format = (SharpDX.DXGI.Format)mode.Format,
                Scaling = DisplayModeScaling.Unspecified,
                ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
            };
            using (var device = deviceTemp)
                output.GetClosestMatchingMode(device, description, out closestDescription);

            return DisplayMode.FromDescription(closestDescription);
        }
Exemplo n.º 5
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapterFactory.Adapters)
            {
                // Skip adapeters that don't have graphics output
                if (graphicsAdapter.Outputs.Length == 0)
                {
                    continue;
                }

                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;

                // INTEL workaround: it seems Intel driver doesn't support properly feature level 9.x. Fallback to 10.
                if (graphicsAdapter.VendorId == 0x8086)
                    preferredGraphicsProfiles = preferredGraphicsProfiles.Select(x => x < GraphicsProfile.Level_10_0 ? GraphicsProfile.Level_10_0 : x).ToArray();

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                            {
                                Adapter = graphicsAdapter,
                                GraphicsProfile = featureLevel,
                                PresentationParameters =
                                    {
                                        MultiSampleCount = MSAALevel.None,
                                        IsFullScreen = preferredParameters.IsFullScreen,
                                        PreferredFullScreenOutputIndex = preferredParameters.PreferredFullScreenOutputIndex,
                                        PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                        DeviceWindowHandle = MainWindow.NativeWindow,
                                        ColorSpace = preferredParameters.ColorSpace
                                    }
                            };

                        var preferredMode = new DisplayMode(preferredParameters.PreferredBackBufferFormat,
                            preferredParameters.PreferredBackBufferWidth,
                            preferredParameters.PreferredBackBufferHeight,
                            preferredParameters.PreferredRefreshRate);

                        // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
                        if (preferredParameters.IsFullScreen)
                        {
                            if (preferredParameters.PreferredFullScreenOutputIndex < graphicsAdapter.Outputs.Length)
                            {
                                var output = graphicsAdapter.Outputs[preferredParameters.PreferredFullScreenOutputIndex];
                                var displayMode = output.FindClosestMatchingDisplayMode(preferredGraphicsProfiles, preferredMode);
                                AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                            }
                        }
                        else
                        {
                            AddDevice(preferredMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                        }

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return graphicsDeviceInfos;
        }
Exemplo n.º 6
0
        protected void AddDevice(DisplayMode mode,  GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters preferredParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            // TODO: Temporary woraround
            if (mode == null)
                mode = new DisplayMode(PixelFormat.R8G8B8A8_UNorm, 800, 480, new Rational(60, 1));

            var deviceInfo = deviceBaseInfo.Clone();

            deviceInfo.PresentationParameters.RefreshRate = mode.RefreshRate;

            if (preferredParameters.IsFullScreen)
            {
                deviceInfo.PresentationParameters.BackBufferFormat = mode.Format;
                deviceInfo.PresentationParameters.BackBufferWidth = mode.Width;
                deviceInfo.PresentationParameters.BackBufferHeight = mode.Height;
            }
            else
            {
                deviceInfo.PresentationParameters.BackBufferFormat = preferredParameters.PreferredBackBufferFormat;
                deviceInfo.PresentationParameters.BackBufferWidth = preferredParameters.PreferredBackBufferWidth;
                deviceInfo.PresentationParameters.BackBufferHeight = preferredParameters.PreferredBackBufferHeight;
            }

            // TODO: Handle multisampling 
            deviceInfo.PresentationParameters.DepthStencilFormat = preferredParameters.PreferredDepthStencilFormat;
            deviceInfo.PresentationParameters.MultiSampleCount = MSAALevel.None;

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
Exemplo n.º 7
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapterFactory.Adapters)
            {
                if (!preferredParameters.RequiredAdapterUid.IsNullOrEmpty() && graphicsAdapter.AdapterUid != preferredParameters.RequiredAdapterUid) continue;

                // Skip adapeters that don't have graphics output 
                // but only if no RequiredAdapterUid is provided (OculusVR at init time might be in a device with no outputs)
                if (graphicsAdapter.Outputs.Length == 0 && preferredParameters.RequiredAdapterUid.IsNullOrEmpty())
                {
                    continue;
                }

                var preferredGraphicsProfiles = preferredParameters.PreferredGraphicsProfile;

                // Iterate on each preferred graphics profile
                foreach (var featureLevel in preferredGraphicsProfiles)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter = graphicsAdapter,
                            GraphicsProfile = featureLevel,
                            PresentationParameters =
                            {
                                MultiSampleLevel = preferredParameters.PreferredMultiSampleLevel,
                                IsFullScreen = preferredParameters.IsFullScreen,
                                PreferredFullScreenOutputIndex = preferredParameters.PreferredFullScreenOutputIndex,
                                PresentationInterval = preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                DeviceWindowHandle = MainWindow.NativeWindow,
                                ColorSpace = preferredParameters.ColorSpace
                            }
                        };

                        var preferredMode = new DisplayMode(preferredParameters.PreferredBackBufferFormat,
                            preferredParameters.PreferredBackBufferWidth,
                            preferredParameters.PreferredBackBufferHeight,
                            preferredParameters.PreferredRefreshRate);

                        // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
                        if (preferredParameters.IsFullScreen)
                        {
                            if (preferredParameters.PreferredFullScreenOutputIndex < graphicsAdapter.Outputs.Length)
                            {
                                var output = graphicsAdapter.Outputs[preferredParameters.PreferredFullScreenOutputIndex];
                                var displayMode = output.FindClosestMatchingDisplayMode(preferredGraphicsProfiles, preferredMode);
                                AddDevice(displayMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                            }
                        }
                        else
                        {
                            AddDevice(preferredMode, deviceInfo, preferredParameters, graphicsDeviceInfos);
                        }

                        // If the profile is supported, we are just using the first best one
                        break;
                    }
                }
            }

            return graphicsDeviceInfos;
        }
Exemplo n.º 8
0
 public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
 {
     return mode;
 }
Exemplo n.º 9
0
        /// <summary>
        /// Find the display mode that most closely matches the requested display mode.
        /// </summary>
        /// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
        /// <param name="mode">The mode.</param>
        /// <returns>Returns the closes display mode.</returns>
        /// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
        /// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order.  ScanlineOrdering Scaling Format Resolution RefreshRate  When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and  other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering,  Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because  the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output.  If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified  display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output.   Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
        public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
        {
            if (targetProfiles == null)
            {
                throw new ArgumentNullException("targetProfiles");
            }

            ModeDescription closestDescription;

            SharpDX.Direct3D12.Device deviceTemp = null;
            for (int i = 0; i < targetProfiles.Length; i++)
            {
                // Create Device D3D12 with feature Level based on profile
                try
                {
                    deviceTemp = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, (FeatureLevel)targetProfiles[i]);
                    break;
                }
                catch (Exception)
                {
                }
            }

            if (deviceTemp == null)
            {
                throw new InvalidOperationException("Could not create D3D12 graphics device");
            }

            var description = new SharpDX.DXGI.ModeDescription()
            {
                Width            = mode.Width,
                Height           = mode.Height,
                RefreshRate      = mode.RefreshRate.ToSharpDX(),
                Format           = (SharpDX.DXGI.Format)mode.Format,
                Scaling          = DisplayModeScaling.Unspecified,
                ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
            };

            using (var device = deviceTemp)
                output.GetClosestMatchingMode(device, description, out closestDescription);

            return(DisplayMode.FromDescription(closestDescription));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Find the display mode that most closely matches the requested display mode.
        /// </summary>
        /// <param name="targetProfiles">The target profile, as available formats are different depending on the feature level..</param>
        /// <param name="mode">The mode.</param>
        /// <returns>Returns the closes display mode.</returns>
        /// <unmanaged>HRESULT IDXGIOutput::FindClosestMatchingMode([In] const DXGI_MODE_DESC* pModeToMatch,[Out] DXGI_MODE_DESC* pClosestMatch,[In, Optional] IUnknown* pConcernedDevice)</unmanaged>
        /// <remarks>Direct3D devices require UNORM formats. This method finds the closest matching available display mode to the mode specified in pModeToMatch. Similarly ranked fields (i.e. all specified, or all unspecified, etc) are resolved in the following order.  ScanlineOrdering Scaling Format Resolution RefreshRate  When determining the closest value for a particular field, previously matched fields are used to filter the display mode list choices, and  other fields are ignored. For example, when matching Resolution, the display mode list will have already been filtered by a certain ScanlineOrdering,  Scaling, and Format, while RefreshRate is ignored. This ordering doesn't define the absolute ordering for every usage scenario of FindClosestMatchingMode, because  the application can choose some values initially, effectively changing the order that fields are chosen. Fields of the display mode are matched one at a time, generally in a specified order. If a field is unspecified, FindClosestMatchingMode gravitates toward the values for the desktop related to this output.  If this output is not part of the desktop, then the default desktop output is used to find values. If an application uses a fully unspecified  display mode, FindClosestMatchingMode will typically return a display mode that matches the desktop settings for this output.   Unspecified fields are lower priority than specified fields and will be resolved later than specified fields.</remarks>
        public DisplayMode FindClosestMatchingDisplayMode(GraphicsProfile[] targetProfiles, DisplayMode mode)
        {
            if (targetProfiles == null)
            {
                throw new ArgumentNullException("targetProfiles");
            }

            // TODO VULKAN

            //ModeDescription closestDescription;
            //SharpDX.Direct3D12.Device deviceTemp = null;
            //for (int i = 0; i < targetProfiles.Length; i++)
            //{
            //    // Create Device D3D12 with feature Level based on profile
            //    try
            //    {
            //        deviceTemp = new SharpDX.Direct3D12.Device(Adapter.NativeAdapter, (FeatureLevel)targetProfiles[i]);
            //        break;
            //    }
            //    catch (Exception)
            //    {
            //    }
            //}

            //if (deviceTemp == null)
            //    throw new InvalidOperationException("Could not create D3D12 graphics device");

            //var description = new SharpDX.DXGI.ModeDescription()
            //{
            //    Width = mode.Width,
            //    Height = mode.Height,
            //    RefreshRate = mode.RefreshRate.ToSharpDX(),
            //    Format = (SharpDX.DXGI.Format)mode.Format,
            //    Scaling = DisplayModeScaling.Unspecified,
            //    ScanlineOrdering = DisplayModeScanlineOrder.Unspecified
            //};
            //using (var device = deviceTemp)
            //    output.GetClosestMatchingMode(device, description, out closestDescription);

            //return DisplayMode.FromDescription(closestDescription);
            return(mode);
        }