gpt4 book ai didi

c# - SlimDX 11 深度缓冲问题

转载 作者:太空宇宙 更新时间:2023-11-03 16:44:33 26 4
gpt4 key购买 nike

我遇到了 SlimDX March SDK 的问题(我相信是 DXSDK11 June 2010)。问题是,每当我将附加深度 View 转为输出合并状态时,我都不会在屏幕上看到任何输出。我将我的代码与 DX11 示例进行了比较,它似乎是正确的。我已经为深度测试尝试了各种标志和格式(包括始终通过等),但似乎没有任何效果。如果有人能发现错误,我将不胜感激。这是代码。以下是步骤:

  1. 初始化后台缓冲区:

            D3DDevice device;
    SwapChain swapChain;

    /// Create the swap chain
    SwapChainDescription desc = new SwapChainDescription()
    {
    BufferCount = 1,
    ModeDescription = new ModeDescription
    {
    Width = ContextSettings.Width,
    Height = ContextSettings.Height,
    RefreshRate = new SlimDX.Rational(ContextSettings.RefreshRate, 1),
    Format = ContextSettings.BufferFormat,
    },
    IsWindowed = !ContextSettings.FullScreen,
    OutputHandle = WindowHandle,
    SampleDescription = new SampleDescription(1, 0),
    SwapEffect = SwapEffect.Discard,
    Usage = Usage.RenderTargetOutput,
    };

    FeatureLevel[] featureLevels = new FeatureLevel[] { FeatureLevel.Level_11_0, FeatureLevel.Level_10_1 };
    DriverType driverType = DriverType.Hardware;

    D3DDevice.CreateWithSwapChain(driverType, DeviceCreationFlags.Debug, featureLevels, desc, out device, out swapChain);

    Device = device;
    SwapChain = swapChain;

    /// Setup window association
    Factory factory = swapChain.GetParent<Factory>();
    factory.SetWindowAssociation(WindowHandle, WindowAssociationFlags.IgnoreAll);

    /// Setup back buffers and render target views
    RenderBuffer = DXTexture2D.FromSwapChain<DXTexture2D>(swapChain, 0);
    RenderView = new RenderTargetView(Device, RenderBuffer);
  2. 然后初始化深度缓冲区:

            Format depthFormat = Format.D32_Float;
    Texture2DDescription depthBufferDesc = new Texture2DDescription
    {
    ArraySize = 1,
    BindFlags = BindFlags.DepthStencil,
    CpuAccessFlags = CpuAccessFlags.None,
    Format = depthFormat,
    Height = width,
    Width = height,
    MipLevels = 1,
    OptionFlags = ResourceOptionFlags.None,
    SampleDescription = new SampleDescription( 1, 0 ),
    Usage = ResourceUsage.Default
    };

    DepthBuffer = new DXTexture2D(Device, depthBufferDesc);

    DepthStencilViewDescription dsViewDesc = new DepthStencilViewDescription
    {
    ArraySize = 0,
    Format = depthFormat,
    Dimension = DepthStencilViewDimension.Texture2D,
    MipSlice = 0,
    Flags = 0,
    FirstArraySlice = 0
    };

    DepthView = new DepthStencilView(Device, DepthBuffer, dsViewDesc);

    DepthStencilStateDescription dsStateDesc = new DepthStencilStateDescription()
    {
    IsDepthEnabled = true,
    IsStencilEnabled = false,
    DepthWriteMask = DepthWriteMask.All,
    DepthComparison = Comparison.Less,
    };

    DepthState = DepthStencilState.FromDescription(Device, dsStateDesc);
  3. 设置渲染目标:

        DeviceContext.OutputMerger.DepthStencilState = DepthState;
    DeviceContext.OutputMerger.SetTargets(DepthView, RenderView);
    DeviceContext.Rasterizer.SetViewports(new Viewport(0, 0, ContextSettings.Width, ContextSettings.Height, 0.0f, 1.0f));

    Clear();

一旦我从 OutputMerger.SetTargets 中删除 DepthView,我就开始在屏幕上看到图像(当然没有深度测试),反之亦然。

最佳答案

事实证明,在 depthBufferDesc 中,我将宽度传递给 Height 变量,将高度传递给 Width。这是在创建两个具有不同尺寸的渲染目标,并将其分解。

关于c# - SlimDX 11 深度缓冲问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6460416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com