小编ham*_*mer的帖子

WPF 显示 FPS

我正在尝试显示 Viewport3D 的 FPS。

经过一些搜索,我发现了 CompositionTarget.Rendering,但这似乎给“WPF Performance suite”工具中显示的 FPS 提供了不同的结果。

使用 CompositionTarget.Rendering 时,我会显示稳定的 60 fps,直到我与视口相机交互(响应鼠标/键盘事件),然后 fps 飙升至 150 到 200 fps,而“WPF 性能套件”工具仍显示稳定的 60 fps。

我认为这是因为“WPF 性能套件”工具显示准确的 FPS,即每当 WPF 团队实际在后台缓冲区上调用 Present 时,而 CompositionTarget.Rendering 是内部更新的 fps,但不代表真实的 fps。

我想显示一些更符合“WPF Performance suite”工具的东西,我怎样才能实现这一点?

我使用 CompositionTarget.Rendering 如下 -

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();
    }
Run Code Online (Sandbox Code Playgroud)

wpf viewport3d frame-rate

5
推荐指数
0
解决办法
3075
查看次数

标签 统计

frame-rate ×1

viewport3d ×1

wpf ×1