Direct3D Immediate Mode Objects and Interfaces

[Previous] [Next]

Direct3D Immediate Mode is composed of a number of COM objects and interfaces to these objects that you can use to construct and control your application's 3D world. In this section, we'll examine the objects and their interfaces (along with some DirectDraw objects and interfaces).

DirectDraw Object

As you saw in Chapter 3, you create DirectDraw objects by using the DirectDrawCreateEx function. The DirectDrawCreateEx function exposes the newest DirectDraw and Direct3D interfaces of DirectX 7. The DirectDraw object is the first object you create in any Direct3D application because it represents and provides access to the display device, which implements many Direct3D features. IDirectDraw7 is the newest interface to the DirectDraw object in DirectX 7, and it's very different from the previous interfaces. It is also the one we'll be using in this book.

DirectDrawSurface Object

In a Direct3D program, the DirectDrawSurface (the IDirectDrawSurface7 interface) object is used to create the front buffer, back buffer, texture maps, and depth buffer. A surface represents an area of memory either in one of your video cards or in the standard system memory of your computer.

If you create a DirectDrawSurface object using the DDSCAPS_3DDEVICE capability flag, you can then use IDirect3D7::CreateDevice with the surface to create a Direct3D device object that uses the surface as its rendering target. This is generally what you do when creating the back buffer. You can also create a DirectDrawSurface object with texture map capabilities by using the IDirectDraw7::CreateSurface method and the DDSCAPS_TEXTURE flag. It can then be filled with the bitmap you want to use for texturing an object in your scene.

Direct3DDevice Object

The Direct3DDevice object is the rendering component of Direct3D. It encapsulates and stores the rendering state for an Immediate Mode application and a method to render primitives using that state. A rendering state defines the parameters used for rendering, which can include information such as texturing, shading, color, and fog. With DirectX 7, a device-object model supplied by the IDirect3DDevice7 interface is provided.

You create the Direct3D device object by using the IDirect3D7::CreateDevice method. This call lets you acquire an IDirect3DDevice7 interface. Unlike in previous versions of DirectX, the IDirect3DDevice7 interface doesn't use separate COM objects for materials, lights, and viewports. With DirectX 7, this new interface includes methods that supply these capabilities as a part of the Direct3D device's internal data structures.

Several types of Direct3D devices can be created on the target system:

  • HAL device
  • TnLHAL device
  • RGB device
  • Reference rasterizer device

Two others that were available in prior versions of DirectX, the MMX device and the Ramp device, are not present in DirectX 7.

The HAL device is a 3D renderer that supports Direct3D by implementing rasterization, but not transformation and lighting, in hardware. (Transformation, lighting, and rasterization are explained in more detail in the next two chapters). If a HAL device is located during enumeration, you should use it for your application—though if your program is written to take advantage of hardware transformation and lighting, the TnLHAL is even better.

The TnLHAL ("Transform 'n' Lighting HAL") device implements all the transformation, lighting, and rasterization modules in hardware and tends to be the fastest device type. Unlike the HAL device, this device performs hardware-accelerated transformation and lighting operations. Thus, it offloads these tasks from the CPU, speeding up an application considerably. You can tell whether a device provides hardware-accelerated transformation and lighting by checking for the D3DDEVCAPS_HWTRANSFORMANDLIGHT device capability.

The RGB device is provided for systems that don't have any hardware capable of 3D acceleration. The RGB device emulates the 3D operations in software. This means that it runs significantly slower than the HAL device, but it does utilize any special instructions provided by the system's CPU. This rasterizer will use CPUs supporting the MMX instruction set (on some Intel processors) or the AMD 3DNow! (on some AMD processors) to speed rendering. The MMX instruction set is used to accelerate rasterization and the 3DNow! instruction set accelerates transformation and lighting operations. But even with these special instruction sets, the RGB device is still slower than the HAL or TnLHAL.

The final device type is the reference rasterizer device. This renderer supports all Direct3D features, but the implementation is optimized for accuracy rather than for speed. Because of this, the reference rasterizer is quite slow and should be used only for testing Direct3D features your card doesn't support.

Direct3D doesn't enumerate the reference rasterizer by default. To enumerate it, you first need to use RegEdit to set the EnumReference value in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Direct3D\Drivers registry key to a nonzero DWORD value.

Direct3DVertexBuffer Object

This object is a memory buffer that contains vertices that are rendered with the vertex buffer rendering methods provided in the IDirect3DDevice7 interface. A vertex buffer is created, and an interface for it retrieved, using the IDirect3D7::CreateVertexBuffer method. Vertices and vertex buffers are explained in detail in the next chapter.



Inside Direct3D
Inside Direct3D (Dv-Mps Inside)
ISBN: 0735606137
EAN: 2147483647
Year: 1999
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net