SlimDX DirectX10多重采样不工作



我正在DirectX10中设置SlimDX项目,但不知何故,我无法进行多重采样。这是我的设备初始化:

    // Create swap chain description
    DXGI.SwapChainDescription swapChainDesc = new DXGI.SwapChainDescription()
    {
        BufferCount = 1,
        Usage = DXGI.Usage.RenderTargetOutput,
        OutputHandle = Window.Handle,
        IsWindowed = true,
        ModeDescription = new DXGI.ModeDescription(0, 0, new Rational(60, 1), DXGI.Format.R8G8B8A8_UNorm),
        SampleDescription = new DXGI.SampleDescription(2, 0),
        Flags = DXGI.SwapChainFlags.AllowModeSwitch,
        SwapEffect = DXGI.SwapEffect.Discard
    };
    // Get device
    DX10.Device.CreateWithSwapChain(null, DX10.DriverType.Hardware, DX10.DeviceCreationFlags.None, swapChainDesc, out Device, out SwapChain);
    // Get back buffer
    using (DX10.Texture2D texture = DX10.Resource.FromSwapChain<DX10.Texture2D>(SwapChain, 0))
        BackBuffer = new DX10.RenderTargetView(Device, texture);
    // Set viewport
    var viewport = new DX10.Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
    Device.OutputMerger.SetTargets(BackBuffer);
    Device.Rasterizer.SetViewports(viewport);
    // Disable alt+enter
    using (var factory = SwapChain.GetParent<DXGI.Factory>())
        factory.SetWindowAssociation(Window.Handle, DXGI.WindowAssociationFlags.IgnoreAll);
    // Create depth buffer description
    DX10.Texture2DDescription depthDesc = new DX10.Texture2DDescription
    {
        Width = Window.ClientSize.Width,
        Height = Window.ClientSize.Height,
        MipLevels = 1,
        ArraySize = 1,
        Format = DXGI.Format.D24_UNorm_S8_UInt,
        SampleDescription = new DXGI.SampleDescription(1, 0),
        Usage = DX10.ResourceUsage.Default,
        BindFlags = DX10.BindFlags.DepthStencil,
        CpuAccessFlags = DX10.CpuAccessFlags.None,
        OptionFlags = DX10.ResourceOptionFlags.None
    };
    // Get depth buffer
    DX10.Texture2D depthStencilBuffer = new DX10.Texture2D(Device, depthDesc);
    DX10.DepthStencilView depthStencilView = new DX10.DepthStencilView(Device, depthStencilBuffer);
    depthStencilBuffer.Dispose();

我正在绘制一个简单的方框。我还检查了

Device.CheckMultisampleQualityLevels(DXGI.Format.R8G8B8A8_UNorm, 4)

具有1、2、4、8和16个样本。每次函数返回1。然而,当我将1放入SwapChainDescription SampleDescription Quality时,设备创建会抛出一个错误:

E_INVALIDARG:向返回函数传递了一个无效参数(-2147028409)

我基本上只能把0作为质量计数。然而,在我的笔记本电脑上,我可以选择不同的质量级别,但多重采样也不起作用,而且PC和笔记本电脑显卡都支持多重采样。

我做错什么了吗?

好吧,现在似乎是个小问题。。。我只是忘记初始化光栅:

SlimDX.Direct3D10.RasterizerStateDescription rasteriserDesc = new SlimDX.Direct3D10.RasterizerStateDescription()
{
    CullMode = SlimDX.Direct3D10.CullMode.Back,
    DepthBias = 0,
    DepthBiasClamp = 0,
    FillMode = SlimDX.Direct3D10.FillMode.Solid,
    IsAntialiasedLineEnabled = true,
    IsDepthClipEnabled = true,
    IsFrontCounterclockwise = false,
    IsMultisampleEnabled = true,
    IsScissorEnabled = false,
    SlopeScaledDepthBias = 0
};
Device.Rasterizer.State = SlimDX.Direct3D10.RasterizerState.FromDescription(device, rasteriserDesc);

现在,多重采样正在正常工作。

最新更新