Game Development Reference
In-Depth Information
Direct3D 10 and later versions provide access to the different graphics resources us-
ing constructs called views . These let us tell the API how to use the resource, and
provide a way of accessing the resources after creation.
In the following code snippet we are creating a render target view
( ID3D11RenderTargetView ), which, as the name implies, provides a view into a
render target. If you haven't encountered the term before, a render target is a tex-
ture that you can draw into, for use later. This allows us to draw to off-screen tex-
tures , which we can then use in many different ways to create the final rendered
frame.
m_d3dDevice->CreateRenderTargetView(
backBuffer.Get(),
nullptr,
&m_renderTargetView
)
Now that we have a render target view, we can tell the graphics context to use this as
the back buffer and start drawing, but while we're initializing our graphics let's create
a depth buffer texture and view so that we can have some depth in our game.
A depth buffer is a special texture that is responsible for storing the depth of each
pixel on the screen. This can be used by the GPU to quickly cull pixels that are hid-
den by other objects. Being able to avoid drawing objects that we cannot see is im-
portant, as drawing those objects still takes time, even though they do not contribute
to the scene. Previously, I mentioned that we need to draw a frame in a small amount
of time to achieve certain frame rates.
In complex games, this can be difficult to achieve if we are drawing everything, so
culling is important to ensure that we can achieve the performance we want.
The depth buffer is an optional feature that isn't automatically generated with the
swap chain, so we need to create it ourselves. To do this, we need to describe the
texture we want to create with a D3D11_TEXTURE2D_DESC structure. Direct3D 11.1
provides a nice helper structure in the form of a CD3D11_TEXTURE2D_DESC that
handles filling in common values for us, as follows:
Search WWH ::




Custom Search