2

SlimDX March SDKで問題が発生しています(DXSDK11の場合は2010年6月だと思います)。問題は、デプスビューを出力マージ状態にアタッチするたびに、画面に出力が表示されないことです。コードを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を削除するとすぐに、画面に画像が表示され始めます(もちろん深度テストなし)。それ以外の場合はその逆です。

4

1 に答える 1

0

depthBufferDescで、widthをHeight変数に渡し、heightをWidthに渡していることがわかりました。これは、異なる寸法の2つのレンダリングターゲットを作成し、それを分解していました。

于 2011-09-19T19:42:18.767 に答える