微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SlimDX 11深度缓冲区问题

如何解决SlimDX 11深度缓冲区问题

| 我在SlimDX march SDK中遇到问题(我相信对于Dxsdk11 June 2010)。问题在于,每当我将深度视图附加到输出合并状态时,屏幕上都不会得到任何输出。我已经将我的代码与DX11示例进行了比较,这似乎是正确的。我已经尝试了用于深度测试的各种标志和格式(包括始终通过等),但是似乎没有任何效果。如果有人发现错误,我将不胜感激。这是代码。步骤如下: 初始化后台缓冲区:
        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);
然后初始化深度缓冲区:
        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,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);
设置渲染目标:
    DeviceContext.OutputMerger.Depthstencilstate = DepthState;
    DeviceContext.OutputMerger.SetTargets(DepthView,RenderView);
    DeviceContext.Rasterizer.SetViewports(new Viewport(0,ContextSettings.Width,ContextSettings.Height,0.0f,1.0f));

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

解决方法

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。