Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
Windows Phone Zone is brought to you in partnership with:

I've been a game developer since 2005. After working 3 years in the game industry I've decided to go indie and create a little development studio called Different Pixel. We've debuted our first game Vizati on June 2010 David is a DZone MVB and is not an employee of DZone and has posted 17 posts at DZone. You can read more from them at their website. View Full User Profile

Using PerfHUD with XNA

05.20.2011
Email
Views: 2524
  • submit to reddit
It's so easy to get up and running with your first Windows Phone app!  Just pick up the FREE toolkit from Microsoft, register at AppHub, and start checking out some fundamental tutorials.

I am definitely a fan of ATI cards. Had a few Geforces but didn’t liked them very much. I actually noticed image quality decrease when switching from an old Radeon 9800 to a Geforce 8k something. I’m very happy with my Radeon 4890, now for the downside, PerfHUD, a very handy tool for Game Developers is only available for NVIDIA chipsets and although ATI has it’s own GPUPerfStudio it’s not the same thing.
Anyway for those who have one and are developing for XNA you may have noticed that it doesn’t run PerfHUD out of the box.
You will get an error, something like:
“This applications is not configured for using PerfHUD. Consult the User’s Guide for more information”

perfHUD_Error

Luckily there’s a little trick we can use to fix this, first we create a new class:

// class that inherits from GraphicsDeviceManager
public class PerfHUDGraphicDeviceManager : GraphicsDeviceManager
    {
        public PerfHUDGraphicDeviceManager(Game game)
            : base(game) // Pass game to base class
        {
        }
        // We override the RankDevices to search for a PerfHUD
        protected override void RankDevices(List foundDevices)
        {
            base.RankDevices(foundDevices);
            bool has_perfHud = false;
 
            foreach (var device in foundDevices)
            {
                if (device.Adapter.Description.Contains("PerfHUD"))
                {
                    has_perfHud = true;
                    break;
                }
            }
            // Found PerfHUD
            if (has_perfHud)
            {
                var temp = foundDevices.OrderBy(
                    (gdi) => !(gdi.Adapter.Description.Contains("PerfHUD"))
                ).ToArray();
 
                foundDevices.Clear();
                foundDevices.AddRange(temp);
 
                foreach (var dev in foundDevices)
                {
                    dev.DeviceType = DeviceType.Reference;
                }
            }
        }
    }

This class basically searches for PerfHUD, so when you open it with it this class detects that the software exists and allows it’s usage. If not found, the regular GraphicDeviceManager is used. Now instead of creating a new GraphicsDeviceManager() on your Game class just do something like:

public class Game1 : Game
{
		public Game1()
		{
                    new PerfHUDGraphicDeviceManager(this);
                }
}

perfHUD_runperfHUD_working_xna

I hope this helps.

References
Published at DZone with permission of David Amador, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

The Windows Phone Microzone, which is supported by Microsoft, is your one-stop-shop for news, tutorials, perspectives, and research on the mobile platform that is making waves in smartphone ecosystem.