protected virtual SampleDescription GetMSAASampleDescription() { var sampleCount = 1; var sampleQuality = 0; #if MSAA if (MSAA != MSAALevel.Disable) { do { var newSampleCount = sampleCount * 2; var newSampleQuality = Device.CheckMultisampleQualityLevels(Format.B8G8R8A8_UNorm, newSampleCount) - 1; if (newSampleQuality < 0) { break; } sampleCount = newSampleCount; sampleQuality = newSampleQuality; if (sampleCount == (int)MSAA) { break; } } while (sampleCount < 32); } #endif return(new SampleDescription(sampleCount, sampleQuality)); }
public override void Init(IntPtr display, IntPtr window, uint samples, bool vsync, bool sRGB) { _display = display; _window = window; _vsync = vsync; FeatureLevel[] features = { FeatureLevel.Level_11_1, FeatureLevel.Level_11_0 }; SharpDX.Direct3D11.Device dev11 = new SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.None, features); _dev = dev11.QueryInterfaceOrNull <SharpDX.Direct3D11.Device1>(); SampleDescription sampleDesc = new SampleDescription(); do { if (_dev.CheckMultisampleQualityLevels(Format.R8G8B8A8_UNorm, (int)samples) > 0) { sampleDesc.Count = (int)samples; sampleDesc.Quality = 0; break; } else { samples >>= 1; } } while (samples > 0); SwapChainDescription1 desc = new SwapChainDescription1(); desc.Width = 0; desc.Height = 0; desc.Format = sRGB ? Format.R8G8B8A8_UNorm_SRgb : Format.R8G8B8A8_UNorm; desc.Scaling = Scaling.None; desc.SampleDescription = sampleDesc; desc.Usage = Usage.RenderTargetOutput; desc.BufferCount = 2; desc.SwapEffect = SwapEffect.FlipSequential; desc.Flags = SwapChainFlags.None; SharpDX.DXGI.Device2 dev = _dev.QueryInterface <SharpDX.DXGI.Device2>(); Adapter adapter = dev.Adapter; Factory2 factory = adapter.GetParent <Factory2>(); if (display == IntPtr.Zero) { GCHandle handle = (GCHandle)window; SharpDX.ComObject coreWindow = new SharpDX.ComObject(handle.Target as object); _swapChain = new SwapChain1(factory, _dev, coreWindow, ref desc); } else { _swapChain = new SwapChain1(factory, _dev, window, ref desc); } _device = new RenderDeviceD3D11(_dev.ImmediateContext.NativePointer, sRGB); }