Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
SSW_8_11.doc
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
5.22 Mб
Скачать

14.6 Direct3d Integration with DirectDraw

DirectDraw presents programmers with a single, unified object. This object encapsulates both the DirectDraw and Direct3D states. Both the DirectDraw driver COM interfaces and the Direct3D driver COM interface allow you to communicate with the same underlying object. When an application uses Direct3D, no Direct3D object is created—rather, the application uses the standard COM QueryInterface method to obtain a Direct3D interface to a DirectDraw object.

The following example demonstrates how to create the DirectDraw object and obtain a Direct3D interface for communicating with that object:

LPDIRECTDRAW lpDD;

LPDIRECT3D lpD3D;

ddres = DirectDrawCreate(NULL, &lpDD, NULL);

if (FAILED(ddres))

.

.

ddres = lpDD->QueryInterface(IID_IDirect3D,

&lpD3D);

if (FAILED(ddres))

.

The code shown in the previous example creates a single object and obtains two interfaces to that object. Therefore, the object's reference count is 2 after the IDirectDraw2::QueryInterface method call. The important implication of this is that the lifetime of the Direct3D driver state is the same as that of the DirectDraw object. Releasing the Direct3D interface does not destroy the Direct3D driver state. That state is not destroyed until all references to that object—whether they are DirectDraw or Direct3D references—have been released. Therefore, if you release a Direct3D interface while holding a reference to a DirectDraw driver interface, and then query the Direct3D interface again, the Direct3D state will be preserved.

Direct3d Device Interface

As with the Direct3D object, there is no distinct Direct3D device object. A Direct3D device is simply an interface for communicating with a DirectDrawSurface object used as a 3D-rendering target. The following example creates a Direct3D device interface to a DirectDrawSurface object:

LPDIRECTDRAWSURFACE lpDDSurface;

LPDIRECT3DDEVICE lpD3DDevice;

ddres = lpDD->CreateSurface(&ddsd, &lpDDSurface,

NULL);

if (FAILED(ddres))

.

ddres = lpDDSurface->QueryInterface(lpGuid,

&lpD3DDevice);

if (FAILED(ddres))

.

The same rules for reference counts and state lifetimes for objects apply to DirectDrawSurface objects and Direct3D devices. (For information about these rules, see Direct3D Driver Interface.) Additionally, multiple, distinct Direct3D device interfaces can be obtained for the same DirectDrawSurface object. It is possible, therefore, that a single DirectDrawSurface object could be the target for both a ramp-based device and an RGB-based device.

Direct3d Texture Interface

Direct3D textures are not distinct object types, but rather another interface of DirectDrawSurface objects. The following example obtains a Direct3D texture interface from a DirectDrawSurface object:

LPDIRECTDRAWSURFACE lpDDSurface;

LPDIRECT3DTEXTURE lpD3DTexture;

ddres = lpDD->CreateSurface(&ddsd, &lpDDSurface,

NULL);

if (FAILED(ddres))

.

ddres = lpDDSurface->QueryInterface(

IID_IDirect3DTexture, &lpD3DTexture);

if (FAILED(ddres))

.

The same rules for reference counts and state lifetimes for objects apply to Direct3D textures. It is possible to use a single DirectDrawSurface object as both a rendering target and a texture.

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]