4.4.4 Frame Statistics
2015-10-28 21:24
113 查看
游戏和图形应用程序测量每秒被渲染帧数(FPS)是常见的。要做到这一点,我们简单地在一些指定的时间t计算帧的数量n。然后,平均FPS:fpsavg = n / t。如果我们设置t = 1,那么fpsavg = n / 1 = n。在我们的代码中,我们使用t = 1(第二个),因为它避免了除法,此外,一秒钟给了一个很好的平均-它不太长也不太短。计算FPS的代码是D3DApp:CalculateFrameStats函数:
另外,为了计算FPS,前面的代码也计算需要的毫秒数,平均地:
float mspf = 1000.0f / fps;
秒每帧只是FPS的倒数,我们可以乘以1000 ms / 1s实现从秒到毫秒的转换。
本文固定链接:http://www.oxox.work/web/directx11/frame-statistics/ | 虚幻大学
void D3DApp::CalculateFrameStats() { // Code computes the average frames per second, and also the // average time it takes to render one frame. These stats // are appended to the window caption bar. static int frameCnt = 0; static float timeElapsed = 0.0f; frameCnt++; // Compute averages over one second period. if( (mTimer.TotalTime() - timeElapsed) >= 1.0f ) { float fps = (float)frameCnt; // fps = frameCnt / 1 float mspf = 1000.0f / fps; std::wostringstream outs; outs.precision(6); outs << mMainWndCaption << L" " << L"FPS: " << fps << L" " << L"Frame Time: " << mspf << L" (ms)"; SetWindowText(mhMainWnd, outs.str().c_str()); // Reset for next average. frameCnt = 0; timeElapsed += 1.0f; } }
另外,为了计算FPS,前面的代码也计算需要的毫秒数,平均地:
float mspf = 1000.0f / fps;
秒每帧只是FPS的倒数,我们可以乘以1000 ms / 1s实现从秒到毫秒的转换。
本文固定链接:http://www.oxox.work/web/directx11/frame-statistics/ | 虚幻大学
相关文章推荐
- C++ 私有构造函数的作用
- 第一章 问题
- OnExit事件 OnChange事件
- 动态规划
- SpringMVC-初识SpringMVC
- Sting 串实现
- 79 Word Search
- Hadoop2.x下安装HBase
- 私有构造函数
- opencv MFC 错误解决办法
- 2015-10-28
- 蓝懿iOS 技术内容和心得 10。28技术内容交流和心得分享
- android按钮动画的实现
- 小米开源文件管理器MiCodeFileExplorer-源码研究(5)-AsyncTask异步任务
- 小米开源文件管理器MiCodeFileExplorer-源码研究(5)-AsyncTask异步任务
- 小米开源文件管理器MiCodeFileExplorer-源码研究(5)-AsyncTask异步任务
- 显式调用构造函数和析构函数
- 自定义View实现支付宝芝麻信用页面功能
- Mybatis基本配置和搭建
- 《需求工程-软件建模与分析》读书笔记3