|
|
|
|
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.

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); } } }
- Website design & XNA + DirectX code : Riemer Grootjans - ©2003 - 2011 Riemer Grootjans
|
|
|
|
|