Freigeben über


Flipping Surfaces (Windows CE 5.0)

Send Feedback

A Microsoft® Direct3D® Mobile application typically displays an animated sequence by generating the frames of the animation in back buffers and presenting them in sequence. Back buffers are organized into swap chains. A swap chain is a series of buffers that flip to the screen one after another. This can be used to render one scene in memory and then flip the scene to the screen when rendering is complete. This avoids the phenomenon known as tearing and allows for smoother animation.

Each device created in Direct3D Mobile has at least one swap chain. When you initialize the first Direct3D Mobile device, you set the BackBufferCount member of the D3DMPRESENT_PARAMETERS structure, which tells Direct3D Mobile the number of back buffers that will be in the swap chain. The call to IDirect3DMobile::CreateDevice then creates the Direct3D Mobile device and corresponding swap chain.

When you use the IDirect3DMobileDevice::Present method to request a surface flip operation, the pointers to surface memory for the front buffer and back buffers are swapped. Flipping is performed by switching pointers that the display device uses for referencing memory, not by copying surface memory. When a flipping chain contains a front buffer and more than one back buffer, the pointers are switched in a circular pattern, as shown in the following illustration.

ms923375.dx3d-trplflip(en-us,MSDN.10).gif

You can create addition swap chains for a device by calling IDirect3DMobileDevice::CreateAdditionalSwapChain. An application can create one swap chain per view and associate each swap chain with a particular window. The application renders images in the back buffers of each swap chain, and then presents them individually. The two parameters that CreateAdditionalSwapChain takes are a pointer to a D3DMPRESENT_PARAMETERS structure and the address of a pointer to an IDirect3DMobileSwapChain interface. You can then use IDirect3DMobileSwapChain::Present to display the contents of the next back buffer to the front buffer. Note that a device can only have one full-screen swap chain.

You can gain access to a specific back buffer by calling the IDirect3DMobileDevice::GetBackBuffer or IDirect3DMobileSwapChain::GetBackBuffer methods, which return a pointer to a IDirect3DMobileSurface interface that represents the returned back buffer surface. Note that calling this method increases the internal reference count on the IDirect3DMobileDevice interface so be sure to call IUnknown::Release when you are done using this surface or you will have a memory leak.

Remember, Direct3D Mobile flips surfaces by swapping surface memory pointers within the swap chain, not by swapping the surfaces themselves. This means that you will always render to the back buffer that will be displayed next.

It is important to note the distinction between a flipping operation, as performed by a display adapter driver, and a Present operation applied to a swap chain created with D3DMSWAPEFFECT_FLIP.

The term flip conventionally denotes an operation that alters the range of video memory addresses that a display adapter uses to generate its output signal, thus causing the contents of a previously hidden back buffer to be displayed. In Direct3D Mobile, the term is often used more generally to describe the presentation of a back buffer in any swap chain created with the D3DMSWAPEFFECT_FLIP swap effect.

While such Present operations are almost invariably implemented by flip operations when the swap chain is a full-screen one, they are necessarily implemented by copy operations when the swap chain is windowed. Furthermore, a display adapter driver may use flipping to implement Present operations against full-screen swap chains based on the D3DMSWAPEFFECT_DISCARD, D3DMSWAPEFFECT_COPY and D3DMSWAPEFFECT_COPY_VSYNC swap effects.

The discussion above applies to the commonly used case of a full-screen swap chain created with D3DMSWAPEFFECT_FLIP.

For a more general discussion of the different swap effects for both windowed and full-screen swap chains, see D3DMSWAPEFFECT.

See Also

Surfaces

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.