Game Development Reference
In-Depth Information
// Create the Depth Stencil View description
DepthStencilViewDescription
DepthStencilViewDesc =new
DepthStencilViewDescription();
DepthStencilViewDesc.Format =
DepthStencilTextureDesc.Format;
DepthStencilViewDesc.Dimension
=DepthStencilViewDimension.Texture2D;
DepthStencilViewDesc.MipSlice = 0;
// Create the depth stencil texture.
m_DepthStencilTexture = new
Texture2D(m_Device,DepthStencilTextureDesc);
// Create the DepthStencilView object.
m_DepthStencilView = new
DepthStencilView(m_Device,m_DepthStencilTexture,DepthStencilViewDesc);
// Make the DepthStencilView active.
m_DeviceContext.OutputMerger.SetTargets(m_DepthStencilView,
m_RenderTargetView);
}
As you can see, the first thing we do is create a
Texture2DDescription
to con-
figure the depth stencil texture. The
width
and
height
properties, of course, are
setting its size to the same size as our rendering area. The
MipLevels
and
Ar-
raySize
parameters are beyond the scope of this text, so we will ignore them.
The
Format
property is, of course, the format our texture is in. The
D24_UNorm_S8_UInt
format means 24 bits for depth and 8 bits for the stencil com-
ponent, but this is getting into the details of how the depth stencil actually works,
which is beyond the scope of this text. The
SampleDescription
property sets
the multisampling parameters for this texture. The
Usage
property specifies how
this resource will be used during rendering. We set the
BindFlags
property to
BindFlags.DepthStencil
to tell Direct3D that this will be used for depth stencil-