简体   繁体   English

如何在简单的Direct2D应用中计算fps?

[英]How do I calculate fps in a simple Direct2D app?

Hey guys, and thanks for looking. 大家好,感谢您的光临。 I have built the simple D2D app from MSDN, available here . 我已经从MSDN构建了简单的D2D应用程序,可从此处获得 Now, I want to draw some primitives and add an fps counter. 现在,我想绘制一些图元并添加一个fps计数器。

I have an OnRender() event, where I draw the rectangles and so on. 我有一个OnRender()事件,在其中绘制矩形,依此类推。 I also have a call to RenderTextInfo() where I call RenderTarget->DrawText. 我也有一个对RenderTextInfo()的调用,在这里我将其称为RenderTarget-> DrawText。 Where do I add the logic for counting the number of frames per second? 在哪里添加用于计算每秒帧数的逻辑?

Thanks much. 非常感谢。

I don't know the exact Direct2D stuff, but this might help. 我不知道确切的Direct2D内容,但这可能会有所帮助。

Basically, you have two choices. 基本上,您有两种选择。 Either you update the framerate when you draw a frame, or each second (or any other time interval). 绘制帧时或每秒(或任何其他时间间隔)更新帧速率。

If you count it when you draw a frame, you can simply get the current time when you draw a frame, and subtract from it the time you drew the last frame. 如果在绘制框架时将其计数,则可以简单地获得绘制框架的当前时间,并从中减去绘制最后一帧的时间。 That gets you the time spent drawing this frame. 这样可以节省您绘制此框架的时间。 The reciprocal of that (ie 1/x) is the framerate. 该值的倒数(即1 / x)是帧速率。

If you count it at a regular time interval, you need to have some event firing at every interval that checks how many frames were drawn since the last time that event fired. 如果您按固定的时间间隔对其进行计数,则需要在每个间隔触发一次事件,以检查自上次触发事件以来已绘制了多少帧。 Divide that by your interval (if it's one second, you don't need to divide, of course) and that's your fps count. 将其除以您的间隔(如果是一秒钟,则无需除法),这就是fps计数。 Don't forget to increment some counter every time you draw a frame. 每次绘制框架时,请不要忘记增加一些计数器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM