private void CollectAvailableAdapters()
        {
            SystemCapabilities = new SystemCapabilities();

            if (_selectedGraphicsProfile == null)
            {
                // This sets _selectedAdapterCapabilities and _selectedRenderQuality
                SystemCapabilities.SelectRecommendedAdapter(out _selectedAdapterCapabilities, out _selectedRenderQuality);

                _selectedGraphicsProfile = _selectedAdapterCapabilities.GetGraphicsProfileForQuality(_selectedRenderQuality);
            }
            else
            {
                // This sets _selectedAdapterCapabilities and _selectedRenderQuality
                _selectedAdapterCapabilities = SystemCapabilities.CreateAdapterCapabilitiesFromGraphicsProfile(_selectedGraphicsProfile);

                var isCustomRenderQuality = IsCustomRenderQuality();

                if (isCustomRenderQuality)
                {
                    _selectedRenderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Custom;
                }
                else
                {
                    _selectedRenderQuality = AdapterCapabilitiesBase.GetGraphicsProfileQuality(_selectedGraphicsProfile);
                }
            }
        }
        private bool IsCustomRenderQuality()
        {
            var renderQuality   = AdapterCapabilitiesBase.GetGraphicsProfileQuality(_selectedGraphicsProfile);
            var graphicsProfile = _selectedAdapterCapabilities.GetGraphicsProfileForQuality(renderQuality);

            var isCustomRenderQuality = !(graphicsProfile.PreferedMultisampleCount == _selectedGraphicsProfile.PreferedMultisampleCount &&
                                          graphicsProfile.ShaderQuality == _selectedGraphicsProfile.ShaderQuality &&
                                          graphicsProfile.TextureFiltering == _selectedGraphicsProfile.TextureFiltering);

            return(isCustomRenderQuality);
        }
        private void ChangeSelectedAdapter(AdapterCapabilitiesBase newSelectedAdapter)
        {
            _selectedAdapterCapabilities = newSelectedAdapter;

            if (_selectedRenderQuality == AdapterCapabilitiesBase.RenderQualityTypes.Custom)
            {
                _selectedRenderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
            }

            _selectedGraphicsProfile = newSelectedAdapter.GetGraphicsProfileForQuality(_selectedRenderQuality);

            UpdateCustomSettingsComboBoxes();
        }
        private void CollectAvailableAdapters()
        {
            SystemCapabilities = new SystemCapabilities();

            if (_selectedGraphicsProfile == null)
            {
                // This sets _selectedAdapterCapabilities and _selectedRenderQuality
                SystemCapabilities.SelectRecommendedAdapter(out _selectedAdapterCapabilities, out _selectedRenderQuality);
                _selectedGraphicsProfile = _selectedAdapterCapabilities.GetGraphicsProfileForQuality(_selectedRenderQuality);
            }
            else
            {
                // This sets _selectedAdapterCapabilities and _selectedRenderQuality
                _selectedAdapterCapabilities = SystemCapabilities.CreateAdapterCapabilitiesFromGraphicsProfile(_selectedGraphicsProfile);
                _selectedRenderQuality       = GetExistingRenderQuality(_selectedGraphicsProfile);
            }
        }
        private void ChangeSelectedAdapter(AdapterCapabilitiesBase newSelectedAdapter)
        {
            if (_selectedGraphicsProfile.DriverType == GraphicsProfile.DriverTypes.Wpf3D && _selectedRenderQuality == AdapterCapabilitiesBase.RenderQualityTypes.Low)
            {
                _selectedRenderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
            }

            _selectedAdapterCapabilities = newSelectedAdapter;

            if (_selectedRenderQuality == AdapterCapabilitiesBase.RenderQualityTypes.Custom)
            {
                _selectedRenderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
            }

            _selectedGraphicsProfile = newSelectedAdapter.GetGraphicsProfileForQuality(_selectedRenderQuality);

            UpdateCustomSettingsComboBoxes();

            QualityComboBox.SelectedItem = _selectedRenderQuality;
        }
        internal void SelectRecommendedAdapter(out AdapterCapabilitiesBase bestAdapterCapabilities, out AdapterCapabilitiesBase.RenderQualityTypes renderQuality)
        {
            if (AllAdapterCapabilities == null || AllAdapterCapabilities.Count == 0 || !IsSupportedOS)
            {
#if LOGGING
                My.Log.Trace(Logger, "RecommendedAdapter: WPF 3D");
#endif

                bestAdapterCapabilities = WpfAdapterCapabilities;
                renderQuality           = AdapterCapabilitiesBase.RenderQualityTypes.Normal;

                return;
            }

            // First try to get dedicated graphics card from nvidia or ATI that has some dedicated video RAM and support at least 10.0 feature level

            // VendorID from http://gamedev.stackexchange.com/questions/31625/get-video-chipset-manufacturer-in-direct3d
            // Full list of vendors: http://www.pcidatabase.com/vendors.php?sort=id
            bestAdapterCapabilities = AllAdapterCapabilities.OfType <HardwareAdapterCapabilities>()
                                      .Where(a => a.IsSupported &&
                                             (a.AdapterDescription1.VendorId == 0x10DE ||                                            // NVidia
                                              a.AdapterDescription1.VendorId == 0x1002 || a.AdapterDescription1.VendorId == 0x1022)) // AMD
                                      .OrderByDescending(a => (long)a.AdapterDescription1.DedicatedVideoMemory)                      // Sort by DedicatedVideoMemory - we assume that more RAM means better card - so pick the one with most RAM (DedicatedVideoMemory is of type PointerSize - to be able to compare by it we need to convert it to long)

                                      .FirstOrDefault();

            if (bestAdapterCapabilities == null)
            {
                // If no NVidia or ATI graphics card was found than just take the first supported graphics card
                bestAdapterCapabilities = AllAdapterCapabilities.OfType <HardwareAdapterCapabilities>().FirstOrDefault(a => a.IsSupported);
            }

            if (bestAdapterCapabilities != null)
            {
                // Found the best dedicated graphics card
                // If the card is 11.0 feature level and has at least 1 GB RAM use High quality, else use Normal quality
                if ((int)bestAdapterCapabilities.DeviceCapabilities.FeatureLevel >= (int)FeatureLevel.Level_11_0 &&
                    bestAdapterCapabilities.AdapterDescription1.DedicatedVideoMemory >= 1000000000L)
                {
                    renderQuality = AdapterCapabilitiesBase.RenderQualityTypes.High;
                }
                else
                {
                    renderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
                }
            }
            else
            {
                // No hardware graphics card - use software rendering
                bestAdapterCapabilities = SoftwareAdapterCapabilities;

                if (bestAdapterCapabilities != null)
                {
                    // no 10.0 feature level adapter found - we use software rendering
                    // Software rendering is highly optimized for multi-threading so more cores means we can afford better performance
                    if (Environment.ProcessorCount > 2)
                    {
                        renderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
                    }
                    else
                    {
                        renderQuality = AdapterCapabilitiesBase.RenderQualityTypes.Low;
                    }
                }
                else
                {
                    // WPF 3D
                    bestAdapterCapabilities = WpfAdapterCapabilities;
                    renderQuality           = AdapterCapabilitiesBase.RenderQualityTypes.Normal;
                }
            }

#if LOGGING
            My.Log.Trace(Logger, "RecommendedAdapter: {0}; RenderQuality: {1}", bestAdapterCapabilities.DisplayName, renderQuality);
#endif
        }