DirectX SDK

The DirectDraw Object and Direct3D

Direct3D is implemented through COM objects and interfaces. Applications written in C++ directly access these interfaces and objects, whereas Visual Basic application interact with a layer of code—visible as the DirectX for Visual Basic Classes—that marshals data from a Visual Basic application to the DirectX run time. The information specific to C++ in this topic describes important relationships between DirectDraw and Direct3D. The discussion is followed by details about similar relationships between the classes exposed by DirectX for Visual Basic.

[C++]

The Direct3D interfaces are actually interfaces to the DirectDraw object. DirectDraw presents programmers with a single, unified object that encapsulates both the DirectDraw and Direct3D states. The DirectDraw object is the first object that your application creates and the last object that your application releases. Since the DirectDraw object represents the display device and the display device implements many of the most important features of Direct3D, the abilities of Direct3D are incorporated into DirectDraw.

Note  For DirectX 7.0, there are two ways to create the DirectDraw object from which you access Direct3D: the new DirectDrawCreateEx function and the legacy DirectDrawCreate function used in previous releases of DirectX. The DirectDrawCreateEx function creates a DirectDraw object that is capable of exposing the newest set of Direct3D interfaces offered in DirectX 7.0. The DirectDrawCreate function, on the other hand, creates a DirectDraw object that is incapable of spawning a Direct3D interface that supports the features of DirectX 7.0. This documentation assumes that all applications will create their DirectDraw objects by using the DirectDrawCreateEx function. For more information, see Direct3D Interfaces and Device Interfaces.

This means 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 is preserved.

The DirectDraw object created by the DirectDrawCreateEx function contains a single Direct3D interface, IDirect3D7. (DirectDraw objects created with the legacy DirectDrawCreate function support the legacy interfaces IDirect3D, IDirect3D2, and IDirect3D3. These interfaces are obsolete and are provided for backward compatibility.) New applications should use the IDirect3D7 interface to create other Direct3D objects. For details, see Direct3D Interfaces.

[Visual Basic]

Although the DirectDraw and Direct3D share much of the same code—in fact, they are basically the same root object—DirectX for Visual Basic exposes them according to how you will use them: as functionally separate classes. DirectX for Visual Basic uses the DirectDraw7 and Direct3D7 classes from which your application can create objects. The underlying relationship (as described in the C++ portion of this topic) between DirectDraw and Direct3D is apparent even from within Visual Basic. The global DirectX7 class contains a method to create a DirectDraw7 object, but no equivalent method for Direct3D. Rather, the DirectDraw7 class defines a method to retrieve the Direct3D7 class, called DirectDraw7.GetDirect3D because these two classes actually refer to the same object within DirectX.

The GetDirect3D method does not create a new object. Rather, the method creates a new class that exposes the Direct3D-related features offered by the DirectDraw object that created it.

The DirectDraw7 class provides the two-dimensional features for a display device, whereas the Direct3D7 class offers the 3-D features for the device. Use the DirectDraw7 class to create the surfaces that the Direct3D class uses for rendering targets, depth buffers, and textures. The Direct3D class is then used to create the subordinate objects that Direct3D requires, such as vertex buffers and enumeration classes.