Graphics Reference
In-Depth Information
When creating a new swap chain instance, the swap chain description is retrieved by a call to
the protected virtual function CreateSwapChainDescription , and the actual creation of
the swap chain is moved into the protected abstract function CreateSwapChain . This allows
the descending classes to override the default swap chain behavior. Then, it creates the swap
chain from an Hwnd handle for the desktop applications or with the Windows.UI.Core.
CoreWindow or SwapChainPanel object for the Windows Store apps.
The DSV allows the OM to determine which fragments (all the information necessary to create
a single pixel) will become actual pixels in the render target. The depth buffer (also known
as the Z-buffer) is represented by a Texture2D instance. It stores one or two components,
the depth and, optionally, the stencil. We use the 64-bit D32_Float_S8X24_UInt format
that provides 32 bits for the depth and 8 bits for the stencil, while the remaining 24-bits are
unused. The BindFlags instance indicates that this texture will be bound as a DSV.
All render targets (including the depth buffer) bound to the OM must be of the same
size and dimension; therefore when creating the depth buffer, it is important to use the
same SampleDescription structure that was used to create the back buffer (that is,
the one returned from CreateSwapChainDescription ). If multisampling is enabled
then we must use DepthStencilViewDimension.Texture2DMultisampled as the
Dimension value in the DepthStencilViewDescription structure; otherwise, we pass
DepthStencilViewDimension.Texture2D .
Finally, our descendent class's overridden method shows how to call the base implementation
to prepare the swap chain, default render target, and depth/stencil buffer. Then it changes
the viewport settings to render to the center of the render target with a 200 x 200 pixel
reduction in size.
There's moreā€¦
The way the depth buffer works is better explained with a simple example. Imagine that
a scene to be rendered includes a wall, and a cube is located behind this wall (from the
viewer's perspective). If the wall is drawn first, then when the OM is determining whether the
fragments for the cube should be rendered to pixels, it will check the depth buffer. If it sees
that the depth of the wall is closer, then the cube fragments will not be drawn. If the cube was
drawn first and then the wall, the pixels for the cube in the render target will be discarded.
Then the fragments of the wall will be rendered as pixels in their place.
The stencil is used as a mask on a per-pixel basis, determining whether or not a pixel should
be rendered. This can be used for rendering techniques such as dissolves, decaling (for
example, scratches on a wall), outlining, silhouettes, shadows, fades, swipes, and composites
(for example, a rear view mirror in a driving simulation), or within deferred rendering
techniques for determining where lighting should be applied.
 
Search WWH ::




Custom Search