得到每帧的渲染耗时

Getting the Time for Each Frame

To accurately time your animations, you need to call the QueryPerformanceCounter function
twice within the game loop: once before you start a drawing, and once after all drawing
has been completed. Both values returned contain the number of counts from the system
at the time the function was called. Because the performance counter has such a high resolution,
both of these values should be unique. You can use the difference between these
two values to determine the number of counts that has passed between the calls.
For example, you could write the following code:
LARGE_INTEGER timeStart;
LARGE_INTEGER timeEnd;
QueryPerformanceCounter(&timeStart);
Render( );
QueryPerformanceCounter(&timeEnd);
LARGE_INTEGER numCounts = ( timeEnd.QuadPart – timeStart.QuadPart )

Now that you’ve updated the sprite code, you have to add in the timer code. The timer
code requires three new global variables:

LARGE_INTEGER timeStart; // holds the starting count
LARGE_INTEGER timeEnd; // holds the ending count
LARGE_INTEGER timerFreq; // holds the frequency of the counter

Next, you need to make a call to QueryPerformanceFrequency to get the frequency of the
counter. You should call this function right before the main message loop:

QueryPerformanceFrequency(&timerFreq);

Finally, you need to add the calls around the Render function to QueryPerformanceCounter.
The first one should go right before the call to Render.

QueryPerformanceCounter(&timeStart);

The second call should go after the call to Render.

QueryPerformanceCounter(&timeEnd);

Immediately following the last QueryPerformanceCounter function, you must determine the
new animation rate.

anim_rate = ( (float)timeEnd.QuadPart - (float)timeStart.QuadPart ) /
timerFreq.QuadPart; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值