XNA for C#
DirectX 9 for C#
DirectX 9 for C++
DirectX 9 for VB
Forum
   
My XNA Book
      
       Go to section on this site

Additional info


Latest Forum posts

 Account settings
  Posted by: Anonymous
  When: 07/05/2014 at 09:48:39

 forced subtitle
  Posted by: Applefly
  When: 07/05/2014 at 06:00:48

 convert DVD into PMS
  Posted by: Applefly
  When: 07/05/2014 at 05:55:25

 DVD to Digital Copy easily
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:52:29

 DVD on Xbox 360/Xbox One Console
  Posted by: VIKIVannessa
  When: 05/05/2014 at 06:51:47

 Extract .Srt Subtitles
  Posted by: Applefly
  When: 04/05/2014 at 03:54:38

 Encode Movie collection
  Posted by: Applefly
  When: 04/05/2014 at 03:52:41

 Convert DVD to WMV
  Posted by: Applefly
  When: 29/04/2014 at 05:53:50

 rip DVDs into digital files
  Posted by: Applefly
  When: 29/04/2014 at 05:51:20

 iTunes movies/music to Kindle Fire
  Posted by: ciciyu80
  When: 29/04/2014 at 05:10:20


Ads

Checking device capabilities

Throughout the tutorials I often mention the Reference rasterizer. This Reference device offers a software simulation of a complete top-notch graphics card. This means that when using the Reference device, you can use all DirectX commands, and the correct output will be drawn to the screen, even if you donít have the newest of video cards.

The backside, however, is that because all of this will be simulated in software, all of the calculations will happen on the systemís main CPU. The main system CPU is A LOT slower in performing these kind of tasks than the GPU, the processing unit of your graphics card. Because of this, the Reference device will deliver the correct results, but only for the simplest of cases you will reach one update per second, in most cases youíll have to wait a couple of seconds for the next frames.

Luckily, DirectX provides a way to check whether a dedicated graphics card is present in the system, the static Manager class. This class supports several ways to check for hardware support in your system. You can use this simple routine for example to check if the graphics card supports vertex transformations:

 Caps DevCaps = D3D.Manager.GetDeviceCaps(0, D3D.DeviceType.Hardware);
 CreateFlags DevFlags = CreateFlags.SoftwareVertexProcessing;
 if (DevCaps.DeviceCaps.SupportsHardwareTransformAndLight)
 {
  DevFlags = CreateFlags.HardwareVertexProcessing;
 }

First you get the structure from the Manager that contains all the capailities of your hardware graphics card. Then you default your device creation flag to SoftwareVertexProcessing, and have it changed to HardwareVertexProcessing only when the hardware supports this.

If youíre working with HLSL shaders, or want to dynimically set the type of device, you can use this code:

 Caps DevCaps = D3D.Manager.GetDeviceCaps(0, D3D.DeviceType.Hardware);
 D3D.DeviceType DevType = D3D.DeviceType.Reference;
 CreateFlags DevFlags = CreateFlags.SoftwareVertexProcessing;
 if ((DevCaps.VertexShaderVersion >= new Version(2, 0)) && (DevCaps.PixelShaderVersion >= new Version(2, 0)))
 {
     DevType = D3D.DeviceType.Hardware;
     if (DevCaps.DeviceCaps.SupportsHardwareTransformAndLight)
     {
         DevFlags = CreateFlags.HardwareVertexProcessing;
     if (DevCaps.DeviceCaps.SupportsPureDevice)
     {
         DevFlags |= CreateFlags.PureDevice;
     }
 }
 
 device = new D3D.Device(0, DevType, this, DevFlags, presentParams);

After getting the device capabilities, we default our device to the Reference rasterizer, and the creation flag to SoftwareVertexProcessing, which are the lowest settings possible. After verifying that our device supports shaders, we switch to the Hardware rasterizer. If our hardware also is capable of calculation all our transformations, we change to this creation flag. If our device is a pure device, we add this to the creation flags. A pure device is the fastest kind of device, as it allows some special kind of memory transactions. Finally, we create the device with the selected type of device and creation flags.

So when using this code, you make sure you have created the Ďbestí kind of device, and that youíre program will not crash on initialization. But even pure devices can have other limitations, such as the size of the maximum allowable lights, indices in an index buffer, or DirectX commands it cannot perform. Maybe your application will crash when it tries to use a backbuffer format your graphics card doesnít support. All of this can be checked this way:

 if (DevCaps.MaxVertexIndex < 30000)
     //do something

This will check if the device can handle index buffers with up to 30000 indices. If not, you will have to come up with an idea to handle this. Just scroll through the properties of DevCaps, and youíll see you can check almost every detail of your hardware.

When looking for supported screen formats, the current resolution and more of the like, you can select the Default one from the Adapters list. An adapter can be thought of as a connection port from your pc to a monitor. On my Radeon I have a normal vga-out and a svideo out. Together with the tv-out on my mainboard, this gives 3 Adapters. From this default adapter, you can find more info on the current display mode, as well as the supported display modes by this adapter. Displaying all supported display modes of your default adapter would go like this:

 AdapterInformation adinfo = D3D.Manager.Adapters.Default;
 
 string line = "";
 foreach (DisplayMode dispmode in adinfo.SupportedDisplayModes)
 {
     line = string.Format("{0} - {1}x{2}:{3}", line, dispmode.Width, dispmode.Height, dispmode.Format);
 }
 
 MessageBox.Show(line);

This conlcudes checking hardware capablities. If you have any comments on this, donít hesitate to put them on the forum!



Click here to go to the forum on this chapter!






Google
 
Webwww.riemers.net


If you appreciate the amount of time I spend creating and updating
these pages, feel free to donate -- any amount is welcome !



- Website design & XNA + DirectX code : Riemer Grootjans -
©2003 - 2011 Riemer Grootjans
Translations

This site in English
This site in Korean
This site in Czech

Microsoft MVP Award



2007 - 2011 MVP Award
DirectX - XNA

Contents

News
Home
Forum
XNA 2.0 Recipes Book (8)
XNA 3.0 Recipes Book (8)
Downloads
Extra Reading (3)
Matrices: geometrical
Matrix Mathematics
Homogenous matrices
Community Projects (1)
Tutorials (160)
XNA 4.0 using C# (89)
DirectX using C# (54)
Series 1:Terrain (14)
Series 2: Flightsim (19)
Series 3: HLSL (19)
Short Tuts (2)
Resizing problem
Checking Device caps
DirectX using C++ (15)
DirectX using VB (2)
-- Expand all --


Thank you!

Support this site --
any amount is welcome !

Stay up-to-date

I don't have the time to keep a News section, so stay informed about the updates by clicking on this RSS file!