4

I'm trying to display the FPS for a Viewport3D.

Doing some searching, I came across CompositionTarget.Rendering, but this seems to give different results to the FPS displayed in the "WPF Performance suite" tool.

When using CompositionTarget.Rendering, I get a steady 60 fps being displayed until i interact with the viewport camera, (in response to mouse/keyboard events) then the fps shoots up to between 150 and 200 fps, while the "WPF Performance suite" tool still displays a steady 60 fps.

I assume this is because the "WPF Performance suite" tool displays the accurate FPS, ie whenever the WPF team actually call Present on the backbuffer, while the CompositionTarget.Rendering is the fps thats updated internally, but not representative of the real fps.

I'd like to display something more in line with the "WPF Performance suite" tool, how can I achieve this?

Im using CompositionTarget.Rendering as follows -

Viewport3D()
{
    CompositionTarget.Rendering += (s, a) =>
                {
                    ++m_frames;
                };

            DispatcherTimer fpsTimer = new DispatcherTimer();
            fpsTimer.Interval = TimeSpan.FromSeconds(1);
            fpsTimer.Tick += (s, a) =>
                {
                    m_fpsText.Text = string.Format("FPS:{0}", m_frames);
                    m_frames = 0;
                };
            fpsTimer.Start();
    }
hammer
  • 145
  • 1
  • 10
  • Point is that WPF is meant to be a GUI suite, not a game suite. I'm not a knowledgeable guy around the inner workings of WPF but i'd bet it wont refresh anything unless strictly needed (Mouse overs, key events that trigger invalidation, WM_PAINT (?) messages and so on) – Machinarius Dec 15 '12 at 14:24
  • In order to get the precise rate at which the Rendering event is fired, you would need to measure the actual elapsed time between invocations of your Tick handler. You can't assume that it always is exactly one second. See the Remarks section [here](http://msdn.microsoft.com/en-us/library/system.windows.threading.dispatchertimer.interval.aspx). – Clemens Dec 15 '12 at 16:17

0 Answers0