Enhancing Your 3D Effects

[Previous] [Next]

Now let's look at some ways that you can get the most out of the special effects you use in your Direct3D applications.

Multitexturing

You should always use multitexturing (discussed in Chapter 8) for your applications. The more textures you use and the higher their resolution, the better your applications will look. You should use single-pass multitexturing (also called multiple-texture blending) when you can rather than multipass texturing (also called multipass texture blending). Keep in mind, however, that many cards don't support single-pass multitexturing for more than a few texture stages. The following code checks for multitexturing support by determining the maximum number of textures that can be simultaneously bound to the texture blending stages.

 // // Fill pD3D with an IID_IDirect3D7 interface. // Create a LPD3DDEVICEDESC7 variable: m_d3dDeviceDesc. // {          pD3D->GetCaps(m_d3dDeviceDesc);          if (m_d3dDeviceDesc->wMaxSimultaneousTextures >= 2)         return S_OK; } 

Once you know that the system supports single-pass multitexturing, you can use the IDirect3DDevice7::ValidateDevice method to verify that the device can render, in a single pass, the texture-blending operations and arguments you've set. Here's the call for this method:

 pD3D->ValidateDevice(&dwExtraPasses); 

Triple Buffering

Triple buffering, which works like double buffering (but with three buffers), allows you to avoid the problems that occur when you attempt to wait for vsync (a video-stream signal indicating that the display device is about to draw a new screen). With double buffering, waiting for vsync results in frame-rate dependencies. If you try to avoid frame-rate dependencies by not waiting for vsync, the redraw appears as though it's tearing because you see it while it's updating. Here's the code for creating the primary surface and two back buffers:

 DDSURFACEDESC2 ddsd2; ZeroMemory(&ddsd2, sizeof(ddsd2)); // // Create the primary surface with two back buffers. // ddsd2.dwSize = sizeof(ddsd2); ddsd2.dwFlags = DSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd2.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP |                        DDSCAPS_COMPLEX; ddsd2.dwBackBufferCount = 2; hr = lpDD7->CreateSurface(&ddsd2, &lpDDSPrimary, NULL); // // If CreateSurface fails here, use double buffering instead. // 

Triple buffering uses more video memory than double buffering, of course, but in some configurations the performance gain can be worthwhile.

True-Color Rendering

True-color rendering, which requires 24 or 32 bits per pixel (bpp), provides the most realistic visuals because it allows you to produce photo-quality color. When you use multiple alpha layers in lower color modes (for example, 16 bpp), you often get a number of undesirable artifacts because rounding errors are more severe. When enumerating devices, you should try to obtain a device that supports true-color rendering if the capability exists.



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