Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Using PerfHUD with XNA

DZone's Guide to

Using PerfHUD with XNA

· Mobile Zone
Free Resource

Discover how to focus on operators for Reactive Programming and how they are essential to react to data in your application.  Brought to you in partnership with Wakanda

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.

Learn how divergent branches can appear in your repository and how to better understand why they are called “branches".  Brought to you in partnership with Wakanda

Topics:

Published at DZone with permission of David Amador, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}