protected bool InitDirect3D() { var creationFlags = DeviceCreationFlags.None; #if DEBUG creationFlags |= DeviceCreationFlags.Debug; #endif try { Device = new Device(DriverType, creationFlags); } catch (Exception ex) { MessageBox.Show("D3D11Device creation failed\n" + ex.Message + "\n" + ex.StackTrace, "Error"); return(false); } ImmediateContext = Device.ImmediateContext; if (Device.FeatureLevel != FeatureLevel.Level_11_0) { Console.WriteLine("Direct3D Feature Level 11 unsupported\nSupported feature level: " + Enum.GetName(Device.FeatureLevel.GetType(), Device.FeatureLevel)); //return false; } //Debug.Assert((Msaa4XQuality = Device.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, 4)) > 0); try { var format = GammaCorrectedBackBuffer ? Format.R8G8B8A8_UNorm_SRGB : Format.R8G8B8A8_UNorm; var sd = new SwapChainDescription { ModeDescription = new ModeDescription(ClientWidth, ClientHeight, new Rational(60, 1), format) { ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified, Scaling = DisplayModeScaling.Unspecified }, SampleDescription = Enable4XMsaa && Device.FeatureLevel >= FeatureLevel.Level_10_1 ? new SampleDescription(4, Msaa4XQuality - 1) : new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = Window.Handle, IsWindowed = true, SwapEffect = SwapEffect.Discard, Flags = SwapChainFlags.None }; SwapChain = new SwapChain(Device.Factory, Device, sd); } catch (Exception ex) { MessageBox.Show("SwapChain creation failed\n" + ex.Message + "\n" + ex.StackTrace, "Error"); return(false); } OnResize(); Sprite = new SpriteRenderer(Device); FontCache = new FontCache(Sprite); return(true); }
protected bool InitDirect3D() { var creationFlags = DeviceCreationFlags.None; #if DEBUG creationFlags |= DeviceCreationFlags.Debug; #endif try { Device = new Device(DriverType, creationFlags); } catch (Exception ex) { MessageBox.Show("D3D11Device creation failed\n" + ex.Message + "\n" + ex.StackTrace, "Error"); return false; } ImmediateContext = Device.ImmediateContext; if (Device.FeatureLevel != FeatureLevel.Level_11_0) { Console.WriteLine("Direct3D Feature Level 11 unsupported\nSupported feature level: " + Enum.GetName(Device.FeatureLevel.GetType(), Device.FeatureLevel)); //return false; } //Debug.Assert((Msaa4XQuality = Device.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, 4)) > 0); try { var sd = new SwapChainDescription { ModeDescription = new ModeDescription(ClientWidth, ClientHeight, new Rational(60, 1), Format.R8G8B8A8_UNorm) { ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified, Scaling = DisplayModeScaling.Unspecified }, SampleDescription = Enable4XMsaa && Device.FeatureLevel >= FeatureLevel.Level_10_1 ? new SampleDescription(4, Msaa4XQuality - 1) : new SampleDescription(1, 0), Usage = Usage.RenderTargetOutput, BufferCount = 1, OutputHandle = Window.Handle, IsWindowed = true, SwapEffect = SwapEffect.Discard, Flags = SwapChainFlags.None }; SwapChain = new SwapChain(Device.Factory, Device, sd); } catch (Exception ex) { MessageBox.Show("SwapChain creation failed\n" + ex.Message + "\n" + ex.StackTrace, "Error"); return false; } OnResize(); Sprite = new SpriteRenderer(Device); FontCache = new FontCache(Sprite); return true; }