如何在 C# 中使用 SlimDX 获得显卡的多重采样功能?

How can I get the Multisampling capabilities of a graphics card with SlimDX in C#?

我想让用户在游戏中选择 MSAA 选项。我希望能够检查他们的机器可以提供哪些多重采样选项并仅显示这些选项。我正在使用的应用程序是用 WinForms 构建的;它实际上不是游戏本身,而是该游戏的启动器。

我找到了 SlimDX.Direct3D11.Device.CheckMultisampleQualityLevels() 但我不确定如何在 WinForms 中获得对 Direct3D11 设备的引用。 https://msdn.microsoft.com/en-us/library/windows/desktop/ff476499%28v=vs.85%29.aspx

您需要遍历所有可能的样本计数,并检查是否至少支持一个质量级别(您需要按格式执行此操作):

SlimDX.Direct3D11.Device device; //your created device
SlimDX.DXGI.Format format = SlimDX.DXGI.Format.R8G8B8A8_Unorm; //Replace by the format you want to test, this one is very common still
for (int samplecount = 1; samplecount  < SlimDX.Device.MultisampleCountMaximum ; samplecount *= 2)
{
     int levels = device.CheckMultisampleQualityLevels(format, samplecount );
     if (levels > 0)
     {
         //you can use a sampledescription of
         new SampleDescription(samplecount, /* value between 0 and levels -1 */
     }
     else
     {
         // samplecount is not supported for this format
     }
}