سؤال

this code appears in the preparation of a Direct3DBase class created by the default windows phone 8 direct3d project:

// Create a depth stencil view.
CD3D11_TEXTURE2D_DESC depthStencilDesc(
    DXGI_FORMAT_D24_UNORM_S8_UINT,
    static_cast<UINT>(m_renderTargetSize.Width),
    static_cast<UINT>(m_renderTargetSize.Height),
    1,
    1,
    D3D11_BIND_DEPTH_STENCIL
    );

ComPtr<ID3D11Texture2D> depthStencil;
DX::ThrowIfFailed(
    m_d3dDevice->CreateTexture2D(
        &depthStencilDesc,
        nullptr,
        &depthStencil
        )
    );

CD3D11_DEPTH_STENCIL_VIEW_DESC depthStencilViewDesc(D3D11_DSV_DIMENSION_TEXTURE2D);
DX::ThrowIfFailed(
    m_d3dDevice->CreateDepthStencilView(
        depthStencil.Get(),
        &depthStencilViewDesc,
        &m_depthStencilView
        )
    );

What is a depth stencil view?

هل كانت مفيدة؟

المحلول

D3D11 separates the concepts of resources (essentially just blocks of memory) and views (ways to 'view' or access those blocks of memory from different parts of the graphics pipeline). In this example the resource is a 2D texture of the desired width, height and format and the view is a depth stencil view onto that texture.

When you want to render something, you bind a render target view and a depth stencil view to the pipeline with a call to ID3D11DeviceContext::OMSetRenderTargets() and thus bind the backing resources for the specified views as your render target and depth/stencil buffer.

The advantage of this decoupling only really becomes apparent when you want to do more sophisticated things like bind slices of a texture array as render targets or depth stencil buffers, reinterpret the same resource memory in different ways at different stages in your frame, etc. It also makes the fairly common case of using a render target or depth stencil buffer as a texture a bit simpler and less of a special case than it was in D3D9 however.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top