Game Development Reference
In-Depth Information
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
);
Here we're asking for a texture that has a pixel format of 24 bits for the depth, in an
unsigned normalized integer, and 8 bits for the stencil in an unsigned integer. The
Stencil part of this buffer is an advanced feature that lets you assign a value to pixels
in the texture. This is most often used for creating a mask, and support is provided
for only rendering to regions with a specific stencil value.
After this, we will set the width and height to match the swap chain, and fill in the
Array Size and Mip Levels so that we can reach the parameter that lets us describe
the usage of the texture. The Array Size refers to the number of textures to create. If
you want an array of textures combined as a single resource, you can use this para-
meter to specify the count, but we only want one texture, so we will set this to 1 .
Mip Levels are increasingly smaller textures that match the main texture. This is
used to allow for performance optimizations when rendering the texture at a distance
where the original resolution is overkilled. For example, say you have a screen res-
olution of 800 by 600. If you want three Mip levels, you will receive an 800 x 600
texture, a 400 x 300 texture, and a 200 x 150 texture. The graphics card has hard-
ware to filter and must use the correct texture, thus reducing the amount of wastage
involved in rendering. Our depth buffer here will never be rendered at a distance, so
we don't need to use up extra memory providing different Mip Levels; we will just set
this to 1 to say that we only want the original resolution texture.
Finally, we will tell the structure that we want this texture to be bound as a depth
stencil. This lets the driver make optimizations to ensure that this special texture can
be quickly accessed where needed. We round this out by creating the texture using
the following description structure:
Search WWH ::




Custom Search