Game Development Reference
In-Depth Information
passed to the immediate context so that their commands can be issued on a single
thread, allowing for multithreading with an API that is not thread-safe.
To create an immediate ID3D11DeviceContext , just pass a pointer to the same
method that we used to create the device.
Deferred contexts are generally considered an advanced technique and are outside
the scope of this topic; however, if you're looking to take full advantage of modern
hardware, you will want to take a look at this topic to ensure that you can work with
the GPU without limiting yourself to a single CPU core.
If you're trying to remember which object to use when you're rendering, remember
that the device is about creating resources throughout the lifetime of the application,
while the device context does the work to apply those resources and create the im-
ages that are displayed to the user.
Swap chain
Working with Direct3D exposes you to a number of asynchronous devices, all oper-
ating at different rates independent of each other. If you drew to the same texture
buffer that the monitor used to display to the screen, you would see the monitor dis-
play a half-drawn image as it refreshes while you're still drawing. This is commonly
known as screen tearing .
To get around this, the concept of a swap chain was created. A swap chain is a
series of textures that the monitor can iterate through, giving you time to draw the
frame before the monitor needs to display it. Often, this is accomplished with just two
texture buffers known as a front buffer and a back buffer . The front buffer is what
the monitor will display while you draw to the Back Buffer. When you're finished ren-
dering, the buffers are swapped so that the monitor can display the new frame and
Direct3D can begin drawing the next frame; this is known as double buffering .
Sometimes two buffers are not enough; for example, when the monitor is still dis-
playing the previous frame and Direct3D is ready to swap the buffers. This means
that the API needs to wait for the monitor to finish displaying the previous frame be-
fore it can swap the buffers and let your game continue.
Search WWH ::




Custom Search