Determining Whether a Hardware Device Is Available
The manager class has a
public static System.Boolean CheckDeviceType ( System.Int32 adapter , Microsoft.DirectX.Direct3D.DeviceType checkType , Microsoft.DirectX.Direct3D.Format displayFormat , Microsoft.DirectX.Direct3D.Format backBufferFormat , System.Boolean windowed , System.Int32 result )
This can be used to determine quickly whether your device supports the type of format you wish to use. The first parameter is the adapter ordinal you are checking against. The second is the type of device you are checking, but this will invariably be DeviceType.Hardware the majority of the time. Finally, you specify the back buffer and display formats, and whether or not you want to run in windowed or full screen mode. The final parameter is optional, and if used, will return the integer code (HRESULT in COM) of the function. The method will return true if this is a valid device type, and false
This is quite useful if you know beforehand the only types of formats you will support. There isn't much of a need to enumerate through every possible permutation of device types and formats if you already know what you need. |
Checking Device CapabilitiesFor every possible thing a device can do that may or may not be capable of happening purely in hardware, there is an item called a "capability," or "Cap" for short. There is a Caps structure in the Direct3D runtime that lists every possible capability a device can have. Once a device is created, you can use the "Caps" property of the device to determine the features it supports, but if you want to know the features the device can support before you've created it, then what? Naturally, there is a method in the Manager class that can help here as well.
Now to add a little code to our existing application that will get the capabilities of each adapter in our system. We can't add the list of capabilities to the current tree view because of the sheer number of capabilities included (there are hundreds of different capabilities that can be checked). The
Go ahead and go back to design view for our
Now you will want to add a hook to the application so that when one of the adapters is selected, it will update the text box with the capabilities of that adapter. You should hook the "AfterSelect" event from the tree view (I will assume you already know how to hook these events). Use the following code in the event handler function:
private void treeView1_AfterSelect(object sender,System.Windows.Forms.TreeViewEventArgs e)
{
if (e.Node.Parent == null) // root node
{
// Get the device caps for this node
textBox1.Text = e.Node.Text + " Capabilities: \r\n\r\n" + Manager.GetDeviceCaps
(e.Node.Index, DeviceType.Hardware).ToString().Replace("\n", "\r\n");
}
}
As you can see, this is relatively simple. For the root nodes (which happen to be our adapters), after they are selected we call the Manager.GetDeviceCaps function, passing in the adapter ordinal for the node (which happens to be the same as the index). The ToString member of this structure will return an extremely large list of all capabilities of this device. Running the application now will result in something like Figure 2.2. Figure 2.2. Device display mode and capabilities.
Now, there are quite a few different capabilities that can be supported, as you can tell by the very large list that was generated. Anything that can be supported by a device is listed here. If you want to see if your device supports fogging, it's here. If you want to know the maximum simultaneous render targets, it's here as well. The Caps structure is broken down
Throughout the book, we may discuss individual capabilities as we need them. |