internal static ShaderModel FromFeatureLevel(FeatureLevel featureLevel) { string featureLevelValue = featureLevel.ToString(); string shaderModelValue = "SM" + featureLevelValue.Substring(2, featureLevelValue.Length - 2); return((ShaderModel)Enum.Parse(typeof(ShaderModel), shaderModelValue)); }
public bool Initialize(out string errorMsg) { try { errorMsg = null; List <ModeDescription> adapterModes = new List <ModeDescription>(); _dx11factory = new Factory1(); using (Adapter1 adapter = _dx11factory.GetAdapter1(0)) { using (Output output = adapter.Outputs[0]) { IsB8G8R8A8_UNormSupport = false; foreach (var mode in output.GetDisplayModeList(Format.B8G8R8A8_UNorm, DisplayModeEnumerationFlags.Interlaced)) { IsB8G8R8A8_UNormSupport = true; adapterModes.Add(mode); } MainAdapter = adapter.Description.Description; logger.Info("GPU found : {0}", MainAdapter); //GetResource Level FeatureLevel maxSupportLevel = Device.GetSupportedFeatureLevel(adapter); logger.Info("Maximum supported DirectX11 level = {0}", maxSupportLevel.ToString()); if (maxSupportLevel == FeatureLevel.Level_9_1 || maxSupportLevel == FeatureLevel.Level_9_2 || maxSupportLevel == FeatureLevel.Level_9_3) { errorMsg = "Your graphical card doesn't support at minimum DirectX 10 feature, current feature : " + maxSupportLevel.ToString(); return(false); } int DedicatedGPU = adapter.Description.DedicatedVideoMemory / (1024 * 1024); if (DedicatedGPU < 0) { DedicatedGPU = 0; } int DedicatedSystem = adapter.Description.DedicatedSystemMemory / (1024 * 1024); if (DedicatedSystem < 0) { DedicatedSystem = 0; } int SharedSystem = adapter.Description.SharedSystemMemory / (1024 * 1024); if (SharedSystem < 0) { SharedSystem = 0; } logger.Info("GPU Memory : Dedicated from GPU : {0}MB, Shared : {1}MB, Dedicated from System : {2}MB. Total : {3}MB", DedicatedGPU, DedicatedSystem, SharedSystem, DedicatedGPU + DedicatedSystem + SharedSystem); logger.Info("B8G8R8A8_UNormSupport compatibility = {0}", IsB8G8R8A8_UNormSupport); #if DEBUG foreach (var mode in adapterModes) { logger.Trace("[{1}:{2}], format : {0}, RefreshRate : {3}hz, Scaling : {4}, ScanlineMode : {5}", mode.Format, mode.Width, mode.Height, (float)mode.RefreshRate.Numerator / mode.RefreshRate.Denominator, mode.Scaling, mode.ScanlineOrdering); } #endif } } RefreshResources(); GetMSAAQualities(Format.B8G8R8A8_UNorm); //Remove the some built-in fonctionnality of DXGI _dx11factory.MakeWindowAssociation(_renderForm.Handle, WindowAssociationFlags.IgnoreAll | WindowAssociationFlags.IgnoreAltEnter); _renderForm.ResizeBegin += _renderForm_ResizeBegin; _renderForm.ResizeEnd += _renderForm_ResizeEnd; _renderForm.Resize += _renderForm_Resize; _renderForm.LostFocus += GameWindow_LostFocus; _renderForm.GotFocus += GameWindow_GotFocus; _renderForm.Show(); _renderForm.Focus(); _renderForm.TopMost = true; HasFocus = true; _renderForm.TopMost = false; return(true); } catch (Exception e) { errorMsg = e.Message; return(false); } }