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

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

                    addDelegate(preferredParameters, graphicsAdapter, deviceInfo, graphicsDeviceInfos);

                    // If the profile is supported, we are just using the first best one
                    break;
                }
            }
        }
예제 #2
0
        protected void AddDevice(DisplayMode mode, DeviceInformation deviceBaseInfo,
                                 ApplicationGraphicsParameters preferredParameters, List <DeviceInformation> graphicsDeviceInfos)
        {
            var deviceInfo = deviceBaseInfo.Clone();

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

            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 / depthstencil format
            deviceInfo.PresentationParameters.DepthStencilFormat = preferredParameters.PreferredDepthStencilFormat;
            deviceInfo.PresentationParameters.MultiSampleCount   = MSAALevelFromCount(preferredParameters.PreferredMultiSampleCount);

            if (!graphicsDeviceInfos.Contains(deviceInfo))
            {
                graphicsDeviceInfos.Add(deviceInfo);
            }
        }
예제 #3
0
        public virtual List <DeviceInformation> FindBestDevices(ApplicationGraphicsParameters preferredParameters)
        {
            var graphicsDeviceInfos = new List <DeviceInformation>();

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

            return(graphicsDeviceInfos);
        }
예제 #4
0
        private void TryAddDeviceFromOutput(ApplicationGraphicsParameters prefferedParameters,
                                            GraphicsOutput output,
                                            DeviceInformation deviceInfo,
                                            List <DeviceInformation> 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);
                }
            }
        }
예제 #5
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]);
        }
예제 #6
0
 private DeviceInformation CreateDeviceInformation(ApplicationGraphicsParameters preferredParameters,
                                                   GraphicsAdapter graphicsAdapter,
                                                   FeatureLevel featureLevel)
 {
     return(new DeviceInformation
     {
         Adapter = graphicsAdapter,
         GraphicsProfile = featureLevel,
         PresentationParameters =
         {
             MultiSampleCount               = (MSAALevel)preferredParameters.PreferredMultiSampleCount,
             IsFullScreen                   = preferredParameters.IsFullScreen,
             PreferredFullScreenOutputIndex = preferredParameters.PreferredFullScreenOutputIndex,
             DepthBufferShaderResource      = preferredParameters.DepthBufferShaderResource,
             PresentationInterval           =
                 preferredParameters.SynchronizeWithVerticalRetrace ? PresentInterval.One : PresentInterval.Immediate,
             DeviceWindowHandle             = MainWindow.NativeWindow,
             RenderTargetUsage              = Usage.BackBuffer | Usage.RenderTargetOutput
         }
     });
 }
예제 #7
0
 private void TryAddDeviceWithDisplayMode(ApplicationGraphicsParameters prefferedParameters,
                                          GraphicsAdapter graphicsAdapter,
                                          DeviceInformation deviceInfo,
                                          List <DeviceInformation> 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);
         }
     }
 }