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

Running XNA on the Reference device

XNA expects your graphics card to support Shader model v1.1 at least, and you better have a v2.0 enabled graphics card in your pc if youíre serious about game programming. For example, the XBOX 360 comes equipped with a v3.0 compatible graphics card, and DirectX 10 has set the standards for the v4.0 cards.

Very nice, but what if youíre unlucky and donít have one of the newer cards? Does this mean you simply cannot use XNA? Fortunately, no. You can instruct XNA to have all calculations performed on the CPU, instead of on the graphics card. This should enable all pcs to run any XNA application.

However, because a CPU, such as an Intel or a AMD chip, is a far more general processor than the GPU integrated on a graphics card, a CPU is also a LOT slower at doing graphical calculations. So, in short: yes, you are able to run XNA applications on old pcs, but it will run slowly. Even for less complex programs, you will get only 1 frame per second.

You have to set your XNA program to Reference mode to instruct XNA to run it on the CPU. Itís actually quite easy: before the device is created, XNA generates an event. We capture this event, and let XNA know we want a method to be executed before device creation. We capture this event by putting this line at the end of our Game1() method:


graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs> (SetToReference);
As a result of this line, immediately before device creation, our SetToReference method is called. Of course, we still need to provide this SetToReference method, so place it anywhere in you class:

 void SetToReference(object sender, PreparingDeviceSettingsEventArgs eventargs)
 {
     eventargs.GraphicsDeviceInformation.CreationOptions = CreateOptions.SoftwareVertexProcessing;
     eventargs.GraphicsDeviceInformation.DeviceType = DeviceType.Reference;
     eventargs.GraphicsDeviceInformation.PresentationParameters.MultiSampleType = MultiSampleType.None;
 }

This method instructs XNA to create a device that uses the CPU instead of the graphics card.

Thatís all there is to it! Now, when you run your program, it will run on the reference device (CPU).

This code will make your code ALWAYS run on the reference device, also if your computer is equipped with of the latest graphics card. So probably youíll want to chech for this first. Before the line in the Game1() method, you can add this line:

 if (GraphicsAdapter.DefaultAdapter.GetCapabilities(DeviceType.Hardware).MaxPixelShaderProfile < ShaderProfile.PS_2_0)

    graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs> (SetToReference);
This line checks if the graphics card in the pc supports Shader model v2.0, and only if it doesnít, it switches XNA to the Reference device. So, this will make sure your program will work on older pcs, and, if present, your graphics card will be used.

Running the XNA application on the CPU has also benefits for debugging: if your project runs on your graphics card, but doesnít do exactly what you expect it to do, you can see if it works in Reference mode. If it does work in Reference mode, you know the graphics driver is the problem here.




DirectX Tutorial 10 - Run XNA on older pcs

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



Click here to go to the forum on this chapter!

Or click on one of the topics on this chapter to go there:
  • How to use that tutorial in Silverlight
          Hi, I have a project in Silverlight and I want to ...
  • CreationOptions not found Help Please
          HI Guys... I have an old dell c640 laptop my da...
  • Event does not fire...
          I tried this one my laptop with an Intel 82855 chi...



    The code for an empty project, run in Reference mode:

     using System;
     using System.Collections.Generic;
     using Microsoft.Xna.Framework;
     using Microsoft.Xna.Framework.Audio;
     using Microsoft.Xna.Framework.Content;
     using Microsoft.Xna.Framework.Graphics;
     using Microsoft.Xna.Framework.Input;
     using Microsoft.Xna.Framework.Storage;
     
     namespace XNAReferenceDevice
     {
         public class Game1 : Microsoft.Xna.Framework.Game
         {
             GraphicsDeviceManager graphics;
             ContentManager content;
     
             public Game1()
             {
                 graphics = new GraphicsDeviceManager(this);
                 content = new ContentManager(Services);
     
                 if (GraphicsAdapter.DefaultAdapter.GetCapabilities(DeviceType.Hardware).MaxPixelShaderProfile < ShaderProfile.PS_2_0)

                    graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs> (SetToReference);
             }
     
             void SetToReference(object sender, PreparingDeviceSettingsEventArgs eventargs)
             {
                 eventargs.GraphicsDeviceInformation.CreationOptions = CreateOptions.SoftwareVertexProcessing;
                 eventargs.GraphicsDeviceInformation.DeviceType = DeviceType.Reference;
                 eventargs.GraphicsDeviceInformation.PresentationParameters.MultiSampleType = MultiSampleType.None;
             }
     
             protected override void Initialize()
             {
                 base.Initialize();
             }
     
             protected override void LoadGraphicsContent(bool loadAllContent)
             {
                 if (loadAllContent)
                 {
                 }
             }
     
             protected override void UnloadGraphicsContent(bool unloadAllContent)
             {
                 if (unloadAllContent == true)
                 {
                     content.Unload();
                 }
             }
     
             protected override void Update(GameTime gameTime)
             {
                 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                     this.Exit();
     
                 base.Update(gameTime);
             }
     
             protected override void Draw(GameTime gameTime)
             {
                 graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
     
                 base.Draw(gameTime);
             }
         }
     }


    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)
    2D Series: Shooters (22)
    3D Series 1: Terrain (13)
    3D Series 2: Flightsim (14)
    3D Series 3: HLSL (18)
    3D Series 4: Adv. terrain (19)
    Short Tuts (3)
    Run XNA on older pcs
    MessageBox in XNA
    Normal generation
    DirectX using C# (54)
    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!