SELECTING YOUR D3D DEVICE

The interface through which you communicate with the hardware (or software emulation) is the D3D device interface. When you create a device using the interface's CreateDevice() function, you specify two important settings for shader usage. The first is the type of device—hardware, software, or reference rasterizer.

  • D3DDEVTYPE_HAL: Hardware rasterization and shading with software, hardware, or mixed transform and lighting.

  • D3DDEVTYPE_REF: This is the Microsoft Direct3D reference rasterizer. It's provided so that software and hardware developers can test their programs against a known implementation. Hardware manufacturers use this to make sure their hardware and drivers are performing properly. You can use this to check against driver bugs. If you get weird results using hardware and you think it's not your fault, test it with the reference rasterizer. If the problem goes away, you've probably found a hardware or driver bug.

  • D3DDEVTYPE_SW: A pluggable software device previously registered with the RegisterSoftwareDevice() function. I know of none that are available yet.

If you don't have a videocard that can support hardware processing, then you can select the reference rasterizer (refrast, for short). The refrast is useful only for testing purposes. It supports almost every feature, so it's useful for testing code when you don't have a device handy that has the features you need. But you do not want to use it in production code since it's very slow. In fact, the refrast is not normally viewable to the retail installation of DirectX, but has to be switched on in the control panel. However, it does give you a way of testing things like shaders without having the hardware.

Once you've selected your device, you choose the other important setting—the behavior flag. This flag tells the device how to behave. The flags that concern shaders are as follows:

  • D3DCREATE_HARDWARE_VERTEXPROCESSING: Specifies hardware vertex processing.

  • D3DCREATE_PUREDEVICE: Specifies hardware rasterization, transform, lighting, and shading. Used as a modifier for the preceding flag.

  • D3DCREATE_MIXED_VERTEXPROCESSING: Specifies mixed (both software and hardware) vertex processing.

  • D3DCREATE_SOFTWARE_VERTEXPROCESSING: Specifies software vertex processing.

Unless you are programming exclusively for a chipset that supports hardware vertex processing,[4] you should specify "mixed" vertex processing to get the maximum speed advantage out of the hardware while letting the vertex processing fall back to the software driver. Note that if you previously used the "pure" device (an optimized hardware interface), then you'll be forced to select "mixed" if you want to use vertex shaders on devices that don't have hardware support. See the section titled "Checking for Shader Support" to check to see if your current device supports shaders.

Note that there are two times you can call GetDeviceCaps(). The first is when you have a device specific interface, that is, an IDirect3D interface. After you call CreateDevice() on that interface, you'll get an IDirect3DDevice interface. Calling GetDeviceCaps() on the device-specific interface may tell you that it doesn't support vertex shaders. When you create the IDirect3DDevice interface (possibly using software or mixed vertex processing flags), you'd call GetDeviceCaps() on it and get the interface augmented with any software vertex pipeline capabilities that are available in software vertex processing mode.

[4]As of July 2002, the cards that have some support for pixel and vertex shaders are ATI's Radeon 8500 or better, the NIVIDA GeForce3 or better (except the GeForce4MX and GeForce4Go), the Matrox Parhelia, the SiS Xabre 400, and the 3Dlabs WildcatVP.



Real-Time Shader Programming(c) Covering Directx 9. 0
Real-Time Shader Programming (The Morgan Kaufmann Series in Computer Graphics)
ISBN: 1558608532
EAN: 2147483647
Year: 2005
Pages: 104
Authors: Ron Fosner

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