예제 #1
0
        protected void TryFindSupportedFeatureLevel(GameGraphicsParameters prefferedParameters,
                                                    GraphicsAdapter graphicsAdapter,
                                                    List <GraphicsDeviceInformation> graphicsDeviceInfos,
                                                    AddDeviceToListDelegate addDelegate)
        {
            // Check if the adapter has an output with the preffered index
            if (prefferedParameters.IsFullScreen && graphicsAdapter.OutputsCount <= prefferedParameters.PreferredFullScreenOutputIndex)
            {
                return;
            }

            // Iterate on each preferred graphics profile
            foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile)
            {
                // Check if this profile is supported.
                if (graphicsAdapter.IsProfileSupported(featureLevel))
                {
                    var deviceInfo = CreateGraphicsDeviceInformation(prefferedParameters, graphicsAdapter, featureLevel);

                    addDelegate(prefferedParameters, graphicsAdapter, deviceInfo, graphicsDeviceInfos);

                    // If the profile is supported, we are just using the first best one
                    break;
                }
            }
        }
예제 #2
0
        public override List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml;

            if (gameWindowBackgroundXaml != null)
            {
                // Make sure that we have the single graphics device created by the BackgroundXaml
                gameWindowBackgroundXaml.RequestDepthFormat = prefferedParameters.PreferredDepthStencilFormat;
                var graphicsDevice = gameWindowBackgroundXaml.EnsureDevice();

                // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
                // So we return a single element
                var deviceInfo = new GraphicsDeviceInformation
                {
                    Adapter                = graphicsDevice.Adapter,
                    GraphicsProfile        = graphicsDevice.Features.Level,
                    PresentationParameters = graphicsDevice.Presenter.Description
                };

                return(new List <GraphicsDeviceInformation>()
                {
                    deviceInfo
                });
            }

            return(base.FindBestDevices(prefferedParameters));
        }
        /// <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]);
        }
예제 #4
0
        public virtual List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = new List <GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapter.Adapters)
            {
                TryFindSupportedFeatureLevel(prefferedParameters, graphicsAdapter, graphicsDeviceInfos, TryAddDeviceWithDisplayMode);
            }

            return(graphicsDeviceInfos);
        }
예제 #5
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
            // So we return a single element
            var deviceInfo = new GraphicsDeviceInformation
                {
                    Adapter = gameWindowWP8.GraphicsDevice.Adapter,
                    GraphicsProfile = gameWindowWP8.GraphicsDevice.Features.Level,
                    PresentationParameters = gameWindowWP8.GraphicsDevice.Presenter.Description
                };

            return new List<GraphicsDeviceInformation>() { deviceInfo };
        }
        /// <summary>
        /// Gets the list of <see cref="GraphicsDeviceInformation"/> that correspond to the provided <see cref="GameGraphicsParameters"/>.
        /// </summary>
        /// <param name="prefferedParameters">The preferred parameters for devices to support.</param>
        /// <returns>The list of supported <see cref="GraphicsDeviceInformation"/> that match provided <see cref="GameGraphicsParameters"/>.</returns>
        /// <remarks>If <see cref="GamePlatform.FindBestDevices"/> doesn't return any devices - adds the first available <see cref="GraphicsAdapter"/>.</remarks>
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(prefferedParameters);

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

                TryFindSupportedFeatureLevel(prefferedParameters, graphicsAdapter, graphicsDeviceInfos, AddDeviceWithDefaultDisplayMode);
            }

            return graphicsDeviceInfos;
        }
예제 #7
0
        public override List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(prefferedParameters);

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

                TryFindSupportedFeatureLevel(prefferedParameters, graphicsAdapter, graphicsDeviceInfos, AddDeviceWithDefaultDisplayMode);
            }

            return(graphicsDeviceInfos);
        }
예제 #8
0
        public virtual List <GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = new List <GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapter.Adapters)
            {
                // Iterate on each preferred graphics profile
                foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter                = graphicsAdapter,
                            GraphicsProfile        = featureLevel,
                            PresentationParameters = new PresentParameters()
                            {
                                MultiSampleQuality   = 0,
                                Windowed             = !prefferedParameters.IsFullScreen,
                                PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                DeviceWindowHandle   = MainWindow.NativeWindow.Handle,
                            }
                        };

                        if (graphicsAdapter.CurrentDisplayMode.Format != Format.Unknown)
                        {
                            AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                        }

                        if (prefferedParameters.IsFullScreen)
                        {
                            // Get display mode for the particular width, height, pixelformat
                            foreach (var displayMode in graphicsAdapter.SupportedDisplayModes)
                            {
                                AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                            }
                        }

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

            return(graphicsDeviceInfos);
        }
예제 #9
0
 private GraphicsDeviceInformation CreateGraphicsDeviceInformation(GameGraphicsParameters prefferedParameters,
                                                                   GraphicsAdapter graphicsAdapter,
                                                                   FeatureLevel featureLevel)
 {
     return(new GraphicsDeviceInformation
     {
         Adapter = graphicsAdapter,
         GraphicsProfile = featureLevel,
         PresentationParameters =
         {
             MultiSampleCount     = MSAALevel.None,
             IsFullScreen         = prefferedParameters.IsFullScreen,
             PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
             DeviceWindowHandle   = MainWindow.NativeWindow,
             RenderTargetUsage    = Usage.BackBuffer | Usage.RenderTargetOutput
         }
     });
 }
예제 #10
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = base.FindBestDevices(prefferedParameters);

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

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

                        // 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(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));
                        AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);

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

            return graphicsDeviceInfos;
        }
예제 #11
0
        private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters,
                                                 GraphicsAdapter graphicsAdapter,
                                                 GraphicsDeviceInformation deviceInfo,
                                                 List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            if (graphicsAdapter.CurrentDisplayMode != null)
            {
                AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }

            if (prefferedParameters.IsFullScreen)
            {
                // Get display mode for the particular width, height, pixelformat
                foreach (var displayMode in graphicsAdapter.SupportedDisplayModes)
                {
                    AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                }
            }
        }
예제 #12
0
        private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters,
                                            GraphicsOutput output,
                                            GraphicsDeviceInformation deviceInfo,
                                            List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            if (output.CurrentDisplayMode != null)
            {
                AddDevice(output.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }

            if (prefferedParameters.IsFullScreen)
            {
                // Get display mode for the particular width, height, pixelformat
                foreach (var displayMode in output.SupportedDisplayModes)
                {
                    AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                }
            }
        }
예제 #13
0
        private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters,
                                            GraphicsOutput output,
                                            GraphicsDeviceInformation deviceInfo,
                                            List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var preferredMode = new DisplayMode(prefferedParameters.PreferredBackBufferFormat,
                                                prefferedParameters.PreferredBackBufferWidth,
                                                prefferedParameters.PreferredBackBufferHeight,
                                                prefferedParameters.PreferredRefreshRate);

            if (prefferedParameters.IsFullScreen)
            {
                var displayMode = output.FindClosestMatchingDisplayMode(prefferedParameters.PreferredGraphicsProfile, preferredMode);
                AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
            else
            {
                AddDevice(preferredMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
        }
예제 #14
0
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var gameWindowBackgroundXaml = gameWindow as GameWindowPhoneBackgroundXaml;
            if (gameWindowBackgroundXaml != null)
            {
                // Make sure that we have the single graphics device created by the BackgroundXaml
                gameWindowBackgroundXaml.RequestDepthFormat = prefferedParameters.PreferredDepthStencilFormat;
                var graphicsDevice = gameWindowBackgroundXaml.EnsureDevice();

                // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
                // So we return a single element
                var deviceInfo = new GraphicsDeviceInformation
                    {
                        Adapter = graphicsDevice.Adapter,
                        GraphicsProfile = graphicsDevice.Features.Level,
                        PresentationParameters = graphicsDevice.Presenter.Description
                    };

                return new List<GraphicsDeviceInformation>() { deviceInfo };
            }

            return base.FindBestDevices(prefferedParameters);
        }
예제 #15
0
 private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters,
                                          GraphicsAdapter graphicsAdapter,
                                          GraphicsDeviceInformation deviceInfo,
                                          List <GraphicsDeviceInformation> graphicsDeviceInfos)
 {
     // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
     if (prefferedParameters.IsFullScreen)
     {
         if (prefferedParameters.PreferredFullScreenOutputIndex < graphicsAdapter.OutputsCount)
         {
             var output = graphicsAdapter.GetOutputAt(prefferedParameters.PreferredFullScreenOutputIndex);
             TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos);
         }
     }
     else
     {
         for (var i = 0; i < graphicsAdapter.OutputsCount; i++)
         {
             var output = graphicsAdapter.GetOutputAt(i);
             TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos);
         }
     }
 }
        public override List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var gameWindowBackgroundXaml = gameWindow as GameWindowWindowsPhoneBackgroundXaml;
            if (gameWindowBackgroundXaml != null)
            {

                // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
                // So we return a single element
                var deviceInfo = new GraphicsDeviceInformation
                    {
                        Adapter = gameWindowBackgroundXaml.GraphicsDevice.Adapter,
                        GraphicsProfile = gameWindowBackgroundXaml.GraphicsDevice.Features.Level,
                        PresentationParameters = gameWindowBackgroundXaml.GraphicsDevice.Presenter.Description
                    };

                return new List<GraphicsDeviceInformation>() {deviceInfo};
            }

            var gameWindowXaml = gameWindow as GameWindowWindowsPhoneXaml;
            if (gameWindowXaml != null)
            {

                // Unlike Desktop and WinRT, the list of best devices are completely fixed in WP8 XAML
                // So we return a single element
                var deviceInfo = new GraphicsDeviceInformation
                                 {
                                     Adapter = gameWindowXaml.GraphicsDevice.Adapter,
                                     GraphicsProfile = gameWindowXaml.GraphicsDevice.Features.Level,
                                     PresentationParameters = gameWindowXaml.GraphicsDevice.Presenter.Description
                                 };

                return new List<GraphicsDeviceInformation>() { deviceInfo };
            }

            return base.FindBestDevices(prefferedParameters);
        }
예제 #17
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,
                    IsFullScreen = IsFullScreen,
                    PreferredFullScreenOutputIndex = PreferredFullScreenOutputIndex,
                    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 = 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];
        }
예제 #18
0
        protected void AddDevice(GraphicsAdapter graphicsAdapter, DisplayMode mode,  GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var deviceInfo = deviceBaseInfo.Clone();

            PresentParameters p = new PresentParameters();
            p.InitDefaults();

            p.FullScreenRefreshRateInHz = mode.RefreshRate;

            if (prefferedParameters.IsFullScreen)
            {
                p.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth;
                p.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight;
                p.Windowed = false;
            }
            else
            {
                p.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth;
                p.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight;
                p.Windowed = true;
                p.FullScreenRefreshRateInHz = 0;
            }

            p.DeviceWindowHandle = MainWindow.NativeWindow.Handle;
            p.AutoDepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat;
            p.MultiSampleQuality = 0;
            p.PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate;
            p.SwapEffect = SwapEffect.Discard;
            p.PresentFlags = PresentFlags.Video;            

            deviceInfo.PresentationParameters = p;
            deviceInfo.Adapter = GraphicsAdapter.Adapters[prefferedParameters.PreferredVideoAdapter];

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
예제 #19
0
        protected void AddDeviceWithDefaultDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var displayMode = new DisplayMode(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));

            AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
        }
예제 #20
0
        private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters,
                                            GraphicsOutput output,
                                            GraphicsDeviceInformation deviceInfo,
                                            List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var preferredMode = new DisplayMode(prefferedParameters.PreferredBackBufferFormat,
                prefferedParameters.PreferredBackBufferWidth,
                prefferedParameters.PreferredBackBufferHeight,
                prefferedParameters.PreferredRefreshRate);

            if (prefferedParameters.IsFullScreen)
            {
                var displayMode = output.FindClosestMatchingDisplayMode(prefferedParameters.PreferredGraphicsProfile, preferredMode);
                AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
            else
            {
                AddDevice(preferredMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
        }
예제 #21
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapter.Adapters)
            {
                // Iterate on each preferred graphics profile
                foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                        {
                            Adapter = graphicsAdapter,
                            GraphicsProfile = featureLevel,
                            PresentationParameters = new PresentParameters()
                            {
                                MultiSampleQuality = 0,
                                Windowed = !prefferedParameters.IsFullScreen,
                                PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                DeviceWindowHandle = MainWindow.NativeWindow.Handle,
                            }
                        };

                        if (graphicsAdapter.CurrentDisplayMode.Format != Format.Unknown)
                        {
                            AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                        }

                        if (prefferedParameters.IsFullScreen)
                        {
                            // Get display mode for the particular width, height, pixelformat
                            foreach (var displayMode in graphicsAdapter.SupportedDisplayModes)
                            {
                                AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                            }
                        }

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

            return graphicsDeviceInfos;
        }
예제 #22
0
        protected void AddDevice(DisplayMode mode, GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var deviceInfo = deviceBaseInfo.Clone();

            deviceInfo.PresentationParameters.RefreshRate = mode.RefreshRate;
            deviceInfo.PresentationParameters.PreferredFullScreenOutputIndex = prefferedParameters.PreferredFullScreenOutputIndex;
            deviceBaseInfo.PresentationParameters.DepthBufferShaderResource  = prefferedParameters.DepthBufferShaderResource;

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

            // TODO: Handle multisampling / depthstencil format
            deviceInfo.PresentationParameters.DepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat;
            deviceInfo.PresentationParameters.MultiSampleCount   = MSAALevel.None;

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
예제 #23
0
        protected void AddDevice(GraphicsAdapter graphicsAdapter, DisplayMode mode, GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List <GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var deviceInfo = deviceBaseInfo.Clone();

            PresentParameters p = new PresentParameters();

            p.InitDefaults();

            p.FullScreenRefreshRateInHz = mode.RefreshRate;

            if (prefferedParameters.IsFullScreen)
            {
                p.BackBufferWidth  = prefferedParameters.PreferredBackBufferWidth;
                p.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight;
                p.Windowed         = false;
            }
            else
            {
                p.BackBufferWidth           = prefferedParameters.PreferredBackBufferWidth;
                p.BackBufferHeight          = prefferedParameters.PreferredBackBufferHeight;
                p.Windowed                  = true;
                p.FullScreenRefreshRateInHz = 0;
            }

            p.DeviceWindowHandle     = MainWindow.NativeWindow.Handle;
            p.AutoDepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat;
            p.MultiSampleQuality     = 0;
            p.PresentationInterval   = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate;
            p.SwapEffect             = SwapEffect.Discard;
            p.PresentFlags           = PresentFlags.Video;

            deviceInfo.PresentationParameters = p;
            deviceInfo.Adapter = GraphicsAdapter.Adapters[prefferedParameters.PreferredVideoAdapter];

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
예제 #24
0
        protected void AddDevice(GraphicsAdapter graphicsAdapter, DisplayMode mode,  GraphicsDeviceInformation deviceBaseInfo, GameGraphicsParameters prefferedParameters, List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            var deviceInfo = deviceBaseInfo.Clone();

            deviceInfo.PresentationParameters.RefreshRate = mode.RefreshRate;

            if (prefferedParameters.IsFullScreen)
            {
                deviceInfo.PresentationParameters.BackBufferWidth = mode.Width;
                deviceInfo.PresentationParameters.BackBufferHeight = mode.Height;
            }
            else
            {
                deviceInfo.PresentationParameters.BackBufferWidth = prefferedParameters.PreferredBackBufferWidth;
                deviceInfo.PresentationParameters.BackBufferHeight = prefferedParameters.PreferredBackBufferHeight;
            }

            // TODO: Handle BackBufferFormat / multisampling / depthstencil format
            deviceInfo.PresentationParameters.BackBufferFormat = prefferedParameters.PreferredBackBufferFormat;
            deviceInfo.PresentationParameters.DepthStencilFormat = prefferedParameters.PreferredDepthStencilFormat;
            deviceInfo.PresentationParameters.MultiSampleCount = MSAALevel.None;

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
예제 #25
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapter.Adapters)
            {
                // Iterate on each preferred graphics profile
                foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile)
                {
                    // Check if this profile is supported.
                    if (graphicsAdapter.IsProfileSupported(featureLevel))
                    {
                        var deviceInfo = new GraphicsDeviceInformation
                            {
                                Adapter = graphicsAdapter,
                                GraphicsProfile = featureLevel,
                                PresentationParameters =
                                    {
                                        MultiSampleCount = MSAALevel.None,
                                        IsFullScreen = prefferedParameters.IsFullScreen,
                                        PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                                        DeviceWindowHandle = Window.NativeWindow,
                                        RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput
                                    }
                            };

                        if (graphicsAdapter.CurrentDisplayMode != null)
                        {
                            AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                        }

                        if (prefferedParameters.IsFullScreen)
                        {
                            // Get display mode for the particular width, height, pixelformat
                            foreach (var displayMode in graphicsAdapter.SupportedDisplayModes)
                            {
                                AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
                            }
                        }

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

            return graphicsDeviceInfos;
        }
예제 #26
0
        protected void TryFindSupportedFeatureLevel(GameGraphicsParameters prefferedParameters,
                                                    GraphicsAdapter graphicsAdapter,
                                                    List<GraphicsDeviceInformation> graphicsDeviceInfos,
                                                    AddDeviceToListDelegate addDelegate)
        {
            // Check if the adapter has an output with the preffered index
            if (prefferedParameters.IsFullScreen && graphicsAdapter.OutputsCount <= prefferedParameters.PreferredFullScreenOutputIndex)
                return;

            // Iterate on each preferred graphics profile
            foreach (var featureLevel in prefferedParameters.PreferredGraphicsProfile)
            {
                // Check if this profile is supported.
                if (graphicsAdapter.IsProfileSupported(featureLevel))
                {
                    var deviceInfo = CreateGraphicsDeviceInformation(prefferedParameters, graphicsAdapter, featureLevel);

                    addDelegate(prefferedParameters, graphicsAdapter, deviceInfo, graphicsDeviceInfos);

                    // If the profile is supported, we are just using the first best one
                    break;
                }
            }
        }
예제 #27
0
        public virtual List<GraphicsDeviceInformation> FindBestDevices(GameGraphicsParameters prefferedParameters)
        {
            var graphicsDeviceInfos = new List<GraphicsDeviceInformation>();

            // Iterate on each adapter
            foreach (var graphicsAdapter in GraphicsAdapter.Adapters)
            {
                TryFindSupportedFeatureLevel(prefferedParameters, graphicsAdapter, graphicsDeviceInfos, TryAddDeviceWithDisplayMode);
            }

            return graphicsDeviceInfos;
        }
예제 #28
0
 private GraphicsDeviceInformation CreateGraphicsDeviceInformation(GameGraphicsParameters prefferedParameters,
                                                                   GraphicsAdapter graphicsAdapter,
                                                                   FeatureLevel featureLevel)
 {
     return new GraphicsDeviceInformation
            {
                Adapter = graphicsAdapter,
                GraphicsProfile = featureLevel,
                PresentationParameters =
                {
                    MultiSampleCount = MSAALevel.None,
                    IsFullScreen = prefferedParameters.IsFullScreen,
                    PreferredFullScreenOutputIndex = prefferedParameters.PreferredFullScreenOutputIndex,
                    DepthBufferShaderResource = prefferedParameters.DepthBufferShaderResource,
                    PresentationInterval = prefferedParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
                    DeviceWindowHandle = MainWindow.NativeWindow,
                    RenderTargetUsage = Usage.BackBuffer | Usage.RenderTargetOutput
                }
            };
 }
예제 #29
0
        private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters,
                                                 GraphicsAdapter graphicsAdapter,
                                                 GraphicsDeviceInformation deviceInfo,
                                                 List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            // if we want to switch to fullscreen, try to find only needed output, otherwise check them all
            if (prefferedParameters.IsFullScreen)
            {
                if (prefferedParameters.PreferredFullScreenOutputIndex < graphicsAdapter.OutputsCount)
                {
                    var output = graphicsAdapter.GetOutputAt(prefferedParameters.PreferredFullScreenOutputIndex);
                    TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos);
                }
            }
            else
            {
                for (var i = 0; i < graphicsAdapter.OutputsCount; i++)
                {
                    var output = graphicsAdapter.GetOutputAt(i);
                    TryAddDeviceFromOutput(prefferedParameters, output, deviceInfo, graphicsDeviceInfos);
                }
            }


        }
예제 #30
0
        private void TryAddDeviceFromOutput(GameGraphicsParameters prefferedParameters,
                                            GraphicsOutput output,
                                            GraphicsDeviceInformation deviceInfo,
                                            List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            if (output.CurrentDisplayMode != null)
                AddDevice(output.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);

            if (prefferedParameters.IsFullScreen)
            {
                // Get display mode for the particular width, height, pixelformat
                foreach (var displayMode in output.SupportedDisplayModes)
                    AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
        }
예제 #31
0
 protected void AddDeviceWithDefaultDisplayMode(GameGraphicsParameters prefferedParameters, GraphicsAdapter graphicsAdapter, GraphicsDeviceInformation deviceInfo, List<GraphicsDeviceInformation> graphicsDeviceInfos)
 {
     var displayMode = new DisplayMode(DXGI.Format.B8G8R8A8_UNorm, gameWindow.ClientBounds.Width, gameWindow.ClientBounds.Height, new Rational(60, 1));
     AddDevice(displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
 }
예제 #32
0
        private void TryAddDeviceWithDisplayMode(GameGraphicsParameters prefferedParameters,
                                                 GraphicsAdapter graphicsAdapter,
                                                 GraphicsDeviceInformation deviceInfo,
                                                 List<GraphicsDeviceInformation> graphicsDeviceInfos)
        {
            if (graphicsAdapter.CurrentDisplayMode != null)
                AddDevice(graphicsAdapter, graphicsAdapter.CurrentDisplayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);

            if (prefferedParameters.IsFullScreen)
            {
                // Get display mode for the particular width, height, pixelformat
                foreach (var displayMode in graphicsAdapter.SupportedDisplayModes)
                    AddDevice(graphicsAdapter, displayMode, deviceInfo, prefferedParameters, graphicsDeviceInfos);
            }
        }