Platform SDK: DirectX

Creating Complex Surfaces and Flipping Chains

[C++]

You can also create complex surfaces. A complex surface is a set of surfaces created with a single call to the IDirectDraw7::CreateSurface method. If the DDSCAPS_COMPLEX flag is set when you call CreateSurface call, DirectDraw implicitly creates one or more surfaces in addition to the surface explicitly specified. You manage complex surfaces just like a single surface—a single call to the IDirectDraw::Release method releases all surfaces, and a single call to the IDirectDrawSurface7::Restore method restores them all. However, implicitly created surfaces cannot be detached. For more information, see IDirectDrawSurface7::DeleteAttachedSurface.

[Visual Basic]

You can also create complex surfaces. A complex surface is a set of surfaces created with a single call to the DirectDraw7.CreateSurface method. If the DDSCAPS_COMPLEX flag is set when you call CreateSurface call, DirectDraw implicitly creates one or more surfaces in addition to the surface explicitly specified. You manage complex surfaces just like a single surface—a single call to the DirectDrawSurface7.Restore method restores them all. However, implicitly created surfaces cannot be detached. For more information, see DirectDrawSurface7.DeleteAttachedSurface.

One of the most useful complex surfaces you can create is a flipping chain. Usually, a flipping chain is made of a primary surface and one or more back buffers. The DDSCAPS_FLIP flag indicates that a surface is part of a flipping chain. Creating a flipping chain this way requires that you also include the DDSCAPS_COMPLEX flag.

[C++]

The following example shows how to prepare for creating a primary surface flipping chain.

DDSURFACEDESC2 ddsd2; 
ddsd2.dwSize = sizeof(ddsd2); 
 
// Tell DirectDraw which members are valid. 
ddsd2.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; 
 
// Request a primary surface with a single 
// back buffer 
ddsd2.ddsCaps.dwCaps = DDSCAPS_COMPLEX | DDSCAPS_FLIP | 
DDSCAPS_PRIMARYSURFACE; 
ddsd2.dwBackBufferCount = 1; 

The previous example constructs a double-buffered flipping environment—a single call to the IDirectDrawSurface7::Flip method exchanges the surface memory of the primary surface and the back buffer. If you specify 2 for the value of the dwBackBufferCount member of the DDSURFACEDESC2 structure, two back buffers are created, and each call to Flip rotates the surfaces in a circular pattern, providing a triple-buffered flipping environment. For more information, see Flipping Surfaces.

[Visual Basic]

The following example shows how to prepare for creating a primary surface flipping chain.

Dim ddsd2 As DDSURFACEDESC2
 
' Tell DirectDraw which members are valid.
ddsd2.lFlags = DDSD_CAPS Or DDSD_BACKBUFFERCOUNT
 
' Request a primary surface with a single
' back buffer
ddsd2.ddsCaps.lCaps = DDSCAPS_COMPLEX Or DDSCAPS_FLIP Or _
DDSCAPS_PRIMARYSURFACE
ddsd2.lBackBufferCount = 1

The previous example constructs a double-buffered flipping environment—a single call to the DirectDrawSurface7.Flip method exchanges the surface memory of the primary surface and the back buffer. If you specify 2 for the value of the lBackBufferCount member of the DDSURFACEDESC2 type, two back buffers are created, and each call to Flip rotates the surfaces in a circular pattern, providing a triple-buffered flipping environment. For more information, see Flipping Surfaces.

Note  To create a flipping chain that comprises surfaces that will be used as 3-D render targets, be sure to include the DDSCAPS_3DDEVICE capability flag in the surface description, as well as the DDSCAPS_COMPLEX and DDSCAPS_FLIP flags.

[C++]

Unlike the CreateSurface method exposed by the IDirectDraw3 and earlier interfaces, you cannot use IDirectDraw7::CreateSurface to implicitly create a flipping chain of render target surfaces with an attached depth-buffer. The DDSURFACEDESC2 structure that the IDirectDraw7::CreateSurface method accepts doesn't contain a field to specify a depth-buffer bit depth. As a result, applications must create a depth-buffer surface explicitly, then attach it to the back-buffer render target surface. For more information, see Depth Buffers.