Game Development Reference
In-Depth Information
Presenting the back buffer
Once we have a frame ready to display, we need to tell Direct3D that we are done
drawing and it can flip the back buffer with the front buffer. To do this we tell the API
to present the frame.
When we present the frame, we can indicate to DXGI that it should wait until the
next vertical retrace before swapping the buffers. The vertical retrace is the period
of time where the monitor is not refreshing the screen. It comes from the days of
CRT monitors where the electron beam would return to the top of the screen to start
displaying a new frame.
We previously looked at tearing, and how it can impact the visual quality of the game.
To fix this issue we use VSync . Try turning off VSync in a modern game and watch
for lines in the display where the frame is broken by the new frame.
Another thing we can do when we present is define a region that has changed,
so that we do not waste power updating all of the screen when only part of it has
changed. If you're working on a game you probably won't need this; however, many
other Direct3D applications only need to update part of the screen and this can be a
useful optimization in an increasing mobile and low-power world.
To get started, we need to define a DXGI_PRESENT_PARAMETERS structure in which
we will define the region that we want to present, as follows:
DXGI_PRESENT_PARAMETERS parameters = {0};
parameters.DirtyRectsCount = 0;
parameters.pDirtyRects = nullptr;
parameters.pScrollRect = nullptr;
parameters.pScrollOffset = nullptr;
In this case we want to clear the entire screen, so Direct3D lets us indicate that by
presenting with zero dirty regions.
Now we can commit by using the Present1() method in the swap chain:
m_swapChain->Present1(1, 0, &parameters);
Search WWH ::




Custom Search