Author: clayman learning for personal use, please do not reprint, not for any commercial purposes. Because the level of this is limited, it is inevitable that it is unclear, please ask you to make an original. Welcome everyone to communicate with me. BLOG: http://blog.9cbs.net/soilworkclayman_joe@yahoo.com.cn
Chapter two
Select the correct
DEVICE
Today, there are a large number of different types of display cards in the market, remember that the characteristics supported by each graphics are almost impossible. You should ask
DEVICE
Let it tell you what it supports. We will discuss next:
Enumerate all adapters in the system (
Adapter
)
Enumerate every one
DEVICE
Supported format
Determine the listed device function
Enumerate the adapter in the system
Most of the systems today support multi-display. Although this is not mainstream configuration, the multi-display is really useful, and it is increasingly popular. In the past, this is a high-end graphics card proprietary function. but now
ATI
,
NVIDIA
as well as
Matrox
They all support multiple display technologies for multiple monitors to share a graphics card.
Direct3D
of
DEVICE
You must specify to each adapter. Here, you can understand the "adapter" as a graphics card that links a specific display. such as
ATI Radeon 9700
The graphics card is just a physical adapter, but it has two display interfaces (
DVI
with
VGA
),Thus, in
Direct3D
It has two adapters. Maybe you don't know which one is choosing, or even how much is it?
DEVICE
In the system running the game, how do you detect them and choose the correct one?
in
Direct3D
In one called
Manager
Static classes can be simple to complete the above tasks: enumerates the adapter and
DEVICE
Information; get the system
DEVICE
Information supported.
Manager
The most important attribute of class is the list of adapters. This property will be used in many places. It has a ""
count
"Members store the number of adapters in the system. Therefore, you can directly use the index to access the adapter (
e.g. Manager.adapters [0]
)
,
You can also enumerate all adapters in the system.
Test this feature with a simple program that will display the adapter in the system in a tree structure, and the display modes they support:
1.
Creative new
C # Windows Formd
engineering;
2.
Add to
DirectX
Component;
3.
Create
TreeView
Control, and account for full windows:
Dock
Attribute settings
Fill
Ok, now add to each adapter, display the function of each display mode supported:
Public void loadinggraphics ()
{
Foreach (AdapterInformation Ai In Manager.Adapters)
{
Treenode root = new treenode (ai.information.description);
Treenode Driverinfo = New Treenode (Striver Information: {0} - {1} ", ai.information.drivername, ai.information.driververs);
Root.Node.Add (DriverInfo);
Treenode DisplayMode - New Treenodej (String.Format ("Vurrent Display Mode: {0} ×
{1}
×
{2} ", ai.currentdisplaymode.width, ai.currentdisplaymode.height, ai.currentdisplayumode.format);
Foreach (DisplayMode DM in ai.supportedDisplayModes)
{
Treenode SupportedNode = New Treenode (String.Format ("Supported: {0}
×
{1}
×
{2} ", DM.Width, DM.HEight, DM.FORMAT);
DisplayMode.Nodes.Add (SupportedNode);
}
Root.Nodes.Add (DisplayMode);
TreeView1.Node.Add (root);
}
}
Although the code looks little, it is actually very simple. You can see what we have made first. First, we enumerate the adapter in the system.
C #
of
Foreach
The iterator makes this process simple. For each adapter, this loop is only executed and fills with a given adapter.
AdapterInformation
structure. Observe
AdapterInformation
Structure, there are several members
Public struct AdapterInformation
{
Int adapter;
DisplayMode CurrentdIndDisplayMode;
AdapterDetails Information;
AdapterDetails getWhqlinformation ();
DisplayModeEnumerator SupportedDisplayModes;
}
Here
Adapter
Member finger
DEVICE
The number of adapters. The number of orders is based on
0
The index, and the number of orders is equal to the number of adapters in the system. Two returns
Adapterdetails
Both members of the structure returns the same result using the same method. Correct
Information
Member,
Windows Hardware Quality Labs
(
WHQL
) Do not return to the details, and
GetWhqlinformation
It can be. Getting this information takes some costs and events, so we divide it into two parts.
Adapterdetails
The structure saves a large amount of information of the adapter, including the description of the adapter itself and the driving information. Although this is not necessarily used, the application can make judgments for hardware types in turn.
The remaining two members return
DisplayMode
structure. These structures contain a large number of display modes, including the displayed height and width, refresh rate, and usage format.
CurrentDisplayMode
Returns the current display mode,
SupportedDisplayModes
Returns a list of patterns supported by the adapter.
SO
, We use
Information
Attribute obtained
DEVICE
Description
Tree view
The root node. Then a child node representing the name of the driver and the version number. A child node showing the current display mode is also added, and all supported display modes are listed under this subtitle.
Operating a program, you can see a list of all support patterns. filling
Present Parameter
These modes can be used as the correct backup buffer format when the structure is structured. Every enumerated mode has a string displayed in a fixed mode (
E.G x8r8g8b8
)
,
Letters and numbers alternate. The letter represents the type of data, the number indicates the number of digits of this type of data. Low is a common letter: a
-
Alpha B
-
Blue X - UNUSED L ---- Luminance R ---- Red P ---- Palette G --- Green
(Although there are many formats, there are only a few of the correct use of backup buffers and display mode. Can be used for back buffering modes include:
A2R10G10B10, A1R5G5B5, A8R8G8B8, X1R5G5B5, X8R8G8B8, R5G5B5; Display formats can be the same as the back buffer formats, with the exception of those that contain an alpha component The only format that can be used for a display weith alpha is A2R10G10B10.
,
And Even THAT I'S ONLY IN FULL-Screen Mode.
)
The number of digits accounted for each type is the total size of this format. such as
X8R8G8B8
It is
32
Bit format, red, green, blue
8
Bit, there are
8
Nothing is used.
So far, we have obtained the number of adapters to be created, and the backup buffer format to be supported, then
DEVICE
What should the other parameters of the constructor? very lucky,
Manager
There are everything we need.
Judgment which device is available
Manager
There are many ways to use to detect if your adapter supports a specific function. For example, you need to detect if the adapter supports a special format, but does not want to enumerate all possible adapters and formats, then you can use
Manager
Class to solve this problem. Use the following method:
Pubic Static System.Boolean CheckDeviceType (int Adapter, DeviceType CheckType, Format DisplayFormat, Format BackbufferFormat, Bool Windowed, int result)
This method can quickly detect
DEVICE
Do you support the format you will use. The first parameter is the number of adapters you want to detect; the second is to detect
DEVICE
Type, but this value is set to
DeviceType.fardware
. Then specify the backup buffer type and display formats that will be used, and whether full screen is required. The last parameter is optional, if used, he will return an integer for this method (ie
COM
middle
HRESULT
). If this is an effective device, the method returns
True
Otherwise,
False
. This method is useful when you know the format to use in advance.
(It should be noted that in window mode, the format of the backup buffer does not have to match the display format, as long as your hardware supports the appropriate color conversion. No matter whether your hardware supports this function,
CheckDeviceType
The method will return the appropriate result and should be used.
Manager
Category
CheckDeviceFormatConversion
This conversion is judged to determine if this conversion is supported. You can also use in window mode
Format.unknown
. This conversion is not required in full screen mode. )
Detection
DEVICE
Function (
Capabilities
)
Let's take every Device
It is called "full-hardware implementation"
Capability
", Or abbreviation
CAP
".
Direct3D
One
Caps
Structure can be listed
DEVICE
Supported every possible
Capabilities
. created
DEVICE
After that, you can use it.
DEVICE
of
Caps
Attributes to detect the features he support, but if you want to know if you create a device
DEVICE
What should I do? natural,
Manager
A class also has a method to complete this task.
Now, add a little code in the previous program to get every adapter in the system.
Capabilities
. We will no longer use
Tree view
To display these
Capabilities
It should contain hundreds of thousands of kinds.
Capabilities
. The best way is to use one
TEXT BOX
. Return
Windows Form
Design mode, put
Tree view
of
Dock
Attribute change to "
Left
", Change the width to half; into
TEXT BOX
Control, put
Dock
Attribute settings "
Fill
"
Multiline
Set as
True
,
Scrollbars
Set as"
Both
".
Now you may want to add a hook to the program (
hook
), After selecting an adapter,
Textbox
The data will be updated. use
Tree view
of
AfTerselect
Event, add the following code:
Private void TreeView_1AFTERSELECT (Object Sender, System.Windows.Forms E)
{
IF (e.node.parent == null)
{
TextBox1.text = E.Node.Text "Capabilities: / R / N / R / N" Manager.GetDeviceCaps (E.Node.indes, DeviceType.hardware) .tostring (). Replace ("/ n", " / r / n ");
}
}
As you can see, it is quite simple. Run a look at the results.