Beispiel #1
0
        public static Direct3D9Settings BuildOptimalSettings(DeviceSettings settings)
        {
            DisplayMode       desktopMode = GraphicsDeviceManager.Direct3D9Object.GetAdapterDisplayMode(0);
            Direct3D9Settings optimal     = new Direct3D9Settings();
            var pp = optimal.PresentParameters;

            optimal.AdapterOrdinal       = settings.AdapterOrdinal;
            optimal.DeviceType           = settings.DeviceType;
            pp.Windowed                  = settings.Windowed;
            pp.BackBufferCount           = settings.BackBufferCount;
            pp.MultiSampleType           = settings.MultisampleType;
            pp.MultiSampleQuality        = settings.MultisampleQuality;
            pp.FullScreenRefreshRateInHz = settings.RefreshRate;

            if (settings.Multithreaded)
            {
                optimal.CreationFlags |= CreateFlags.Multithreaded;
            }

            if (optimal.PresentParameters.Windowed || ConversionMethods.GetColorBits(desktopMode.Format) >= 8)
            {
                optimal.AdapterFormat = desktopMode.Format;
            }
            else
            {
                optimal.AdapterFormat = Format.X8R8G8B8;
            }

            if (settings.BackBufferWidth == 0 || settings.BackBufferHeight == 0)
            {
                if (optimal.PresentParameters.Windowed)
                {
                    pp.BackBufferWidth  = 640;
                    pp.BackBufferHeight = 480;
                }
                else
                {
                    pp.BackBufferWidth  = desktopMode.Width;
                    pp.BackBufferHeight = desktopMode.Height;
                }
            }
            else
            {
                pp.BackBufferWidth  = settings.BackBufferWidth;
                pp.BackBufferHeight = settings.BackBufferHeight;
            }

            if (settings.BackBufferFormat == Format.Unknown)
            {
                pp.BackBufferFormat = optimal.AdapterFormat;
            }
            else
            {
                pp.BackBufferFormat = settings.BackBufferFormat;
            }

            if (settings.DepthStencilFormat == Format.Unknown)
            {
                if (ConversionMethods.GetColorBits(optimal.PresentParameters.BackBufferFormat) >= 8)
                {
                    pp.AutoDepthStencilFormat = Format.D32;
                }
                else
                {
                    pp.AutoDepthStencilFormat = Format.D16;
                }
            }
            else
            {
                pp.AutoDepthStencilFormat = settings.DepthStencilFormat;
            }

            if (!settings.EnableVSync)
            {
                pp.PresentationInterval = PresentInterval.Immediate;
            }

            optimal.PresentParameters = pp;
            return(optimal);
        }
Beispiel #2
0
        public static float RankSettingsCombo(SettingsCombo9 combo, Direct3D9Settings optimal, DisplayMode desktopMode)
        {
            float ranking = 0.0f;

            if (combo.AdapterOrdinal == optimal.AdapterOrdinal)
            {
                ranking += 1000.0f;
            }

            if (combo.DeviceType == optimal.DeviceType)
            {
                ranking += 100.0f;
            }

            if (combo.DeviceType == DeviceType.Hardware)
            {
                ranking += 0.1f;
            }

            if (combo.Windowed == optimal.PresentParameters.Windowed)
            {
                ranking += 10.0f;
            }

            if (combo.AdapterFormat == optimal.AdapterFormat)
            {
                ranking += 1.0f;
            }
            else
            {
                int bitDepthDelta = Math.Abs(ConversionMethods.GetColorBits(combo.AdapterFormat) -
                                             ConversionMethods.GetColorBits(optimal.AdapterFormat));
                float scale = Math.Max(0.9f - bitDepthDelta * 0.2f, 0.0f);
                ranking += scale;
            }

            if (!combo.Windowed)
            {
                bool match;
                if (ConversionMethods.GetColorBits(desktopMode.Format) >= 8)
                {
                    match = (combo.AdapterFormat == desktopMode.Format);
                }
                else
                {
                    match = (combo.AdapterFormat == Format.X8R8G8B8);
                }

                if (match)
                {
                    ranking += 0.1f;
                }
            }

            if ((optimal.CreationFlags & CreateFlags.HardwareVertexProcessing) != 0 &&
                (optimal.CreationFlags & CreateFlags.MixedVertexProcessing) != 0)
            {
                if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0)
                {
                    ranking += 1.0f;
                }
            }

            if ((combo.DeviceInfo.Capabilities.DeviceCaps & DeviceCaps.HWTransformAndLight) != 0)
            {
                ranking += 0.1f;
            }

            foreach (DisplayMode displayMode in combo.AdapterInfo.DisplayModes)
            {
                if (displayMode.Format == combo.AdapterFormat &&
                    displayMode.Width == optimal.PresentParameters.BackBufferWidth &&
                    displayMode.Height == optimal.PresentParameters.BackBufferHeight)
                {
                    ranking += 1.0f;
                    break;
                }
            }

            if (combo.BackBufferFormat == optimal.PresentParameters.BackBufferFormat)
            {
                ranking += 1.0f;
            }
            else
            {
                int bitDepthDelta = Math.Abs(ConversionMethods.GetColorBits(combo.BackBufferFormat) -
                                             ConversionMethods.GetColorBits(optimal.PresentParameters.BackBufferFormat));
                float scale = Math.Max(0.9f - bitDepthDelta * 0.2f, 0.0f);
                ranking += scale;
            }

            if (combo.BackBufferFormat == combo.AdapterFormat)
            {
                ranking += 0.1f;
            }

            for (int i = 0; i < combo.MultisampleTypes.Count; i++)
            {
                MultisampleType type    = combo.MultisampleTypes[i];
                int             quality = combo.MultisampleQualities[i];

                if (type == optimal.PresentParameters.MultiSampleType && quality == optimal.PresentParameters.MultiSampleQuality)
                {
                    ranking += 1.0f;
                    break;
                }
            }

            if (combo.DepthStencilFormats.Contains(optimal.PresentParameters.AutoDepthStencilFormat))
            {
                ranking += 1.0f;
            }

            foreach (DisplayMode displayMode in combo.AdapterInfo.DisplayModes)
            {
                if (displayMode.Format == combo.AdapterFormat &&
                    displayMode.RefreshRate == optimal.PresentParameters.FullScreenRefreshRateInHz)
                {
                    ranking += 1.0f;
                    break;
                }
            }

            if (combo.PresentIntervals.Contains(optimal.PresentParameters.PresentationInterval))
            {
                ranking += 1.0f;
            }

            return(ranking);
        }