Display GPU system information with xNa

Source: Internet
Author: User

In the development of graphicsProgramIn order to ensure good compatibility in various hardware environments, we often need to make some adjustments based on the specific hardware, including the most common task of allowing users to modify the resolution. first, you must know the features supported by the hardware. in the original MDX example, we re-wrote it with xNa today, which is very simple, with 100 rowsCodeLeft and right :)

Two classes are used here: graphicsadapter and graphicsdevicecapabilities. graphicsadapter actually represent your video card. The Static Property adapters can be used to obtain information about all GPUs in the current system (if you have multiple GPUs). GPUs with an index of 0 are usually used by the system by default. Graphicsadapter contains all GPU information, including the model, name, driver version, and manufacturer. The supporteddisplaymodes set contains all valid display modes in full screen mode.

Among the many graphicsadapter methods, the most common ones are checkdevicemultsampletype () and getcapabilities (). The former can be used to obtain the multi-sample type and the maximum number of samples supported by the current GPU. The latter returns graphicsdevicecapabilities, an object containing all the capability of the video card. All attributes of this Class represent certain attributes of the video card. Note that all attributes ending with capabilities are a structure defined in the graphicsdevicecapabilities namespace.

There are more than 300 features with different types. To display them, the easiest way is to manually encode and access all attributes :). Of course, we certainly won't do this. We can use strong reflection in. Net to access all attributes in sequence:

Void Adapterinfotrv_afterselect ( Object Sender, treevieweventargs E)
{
Stringbuilder complexcapsb =   New Stringbuilder ( 9000 );
Stringbuilder simplecapsb =   New Stringbuilder ( 1000 );
If (E. node. Parent =   Null )
{
Complexcapsb. append (E. node. Text +   " Capabilities: \ r \ n " );
Simplecapsb. append ( " Other capabilities: \ r \ n " );
Graphicsdevicecapabilities caps = Graphicsadapter. adapters [E. node. Index]. getcapabilities (devicetype. Hardware );
Type type =   Typeof (Graphicsdevicecapabilities );
Propertyinfo [] allcaps = Type. getproperties ();
Foreach (Propertyinfo prop In Allcaps)
{
If (Complexcaps. Contains (prop. Name ))
{
Complexcapsb. append (prop. Name +   " : \ R \ n " );
Object Capobject = Prop. getvalue (caps, Null );
Type subcaptype = Capobject. GetType ();
Propertyinfo [] complexcapprops = Subcaptype. getproperties ();
Foreach (Propertyinfo complexpropcap In Complexcapprops)
{
Complexcapsb. append ( " "   + Complexpropcap. Name +   " : "   + Complexpropcap. getvalue (capobject, Null ). Tostring () +   " \ R \ n " );
}  
Complexcapsb. append ( " \ R \ n " );
}  
Else  
{
Object Value = Prop. getvalue (caps, Null );
Simplecapsb. append ( "   "   + Prop. Name +   " : "   + Value. tostring () +   " \ R \ n " );
}  
}  
}  
Complexcapsb. append (simplecapsb );
Devicecaptbx. Text = Complexcapsb. tostring ();
}  

The complete code can be downloaded here, And vs2008 and xNa 3.0 are required.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.