SlimDX DirectX10多重采样无法正常工作

时间:2012-09-05 00:27:30

标签: slimdx directx-10 multisampling

我正在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: An invalid parameter was passed to the returning function (-2147024809)

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

我有什么问题吗?

1 个答案:

答案 0 :(得分:1)

好的,现在好像正在讨厌一个菜鸟问题...... 我只是忘了初始化光栅器:

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);

现在多重采样工作正常。

相关问题