2012-09-05 64 views
2

我在DirectX10中設置了我的SlimDX項目,但我無法讓多重採樣工作。這裏是我的設備初始化:SlimDX DirectX10多重採樣不起作用

// 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個樣本。每次thefunction返回。然而,當我把1到SwapChainDescription SampleDescription質量,設備創建拋出一個錯誤:

E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809)

我基本上可以只對質量計數置0。然而,在我的筆記本電腦上,我可以選擇不同的質量等級,但多重採樣也不適用,PC和筆記本電腦顯卡都支持多重採樣。

有什麼我做錯了嗎?

回答

1

好吧,似乎魔神一個noob問題現在... 我只是忘了初始化光柵:

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

現在多重採樣工作,因爲它應該。