Search code examples
c#directx-11sharpdxdirect3d11depth-testing

How do I create a depth stencil view?


I am in the making of a SharpDX game and I can't figure out how to make a depth stencil view. To be fair, I also don't really know what it is. I've looked everywhere I could find online and everything I do ends up with a black screen.

Can someone tell me how to make a depth stencil view, or point me to a way that doesn't give me a black screen?

Edit: I rewrote the code and I don't know what I did but it works now.


Solution

  • A DepthStencilView is effectively a pointer to a buffer/image that stores depth/stencil.

    You are missing concepts here.

    First, create a 2D image (texture) with D3D11_BIND_DEPTH_STENCIL BindFlags and a depth/stencil image format (typically DXGI_FORMAT_D24_UNORM_S8_UINT is used).

    Once you have a D3D11 2D Texture that can be bound as a DepthStencil output, you can create a view of the resource and then bind that to the Output Merger (ID3D11DeviceContext::OMSetRenderTargets (...)).