我有一个 DirectX9 应用程序,它只在屏幕上渲染一个三角形,但无论我是否打开了 VSync,我都获得了 60 FPS 的帧速率。为什么是这样?
这是我为计算 FPS 所做的代码,但我不知道这是否是它的问题。
游戏计时器.h
#pragma once
#include "Windows.h"
class GameTimer {
public:
GameTimer();
~GameTimer(){}
void Update();
float GetFrameTime();
inline float GetFramePerSec(){return framesPerSec;}
inline float GetMillSecPerFrame(){return millSecPerFrame;}
private:
float secsPerCount;
_int64 prevTimeStamp;
float framesPerSec;
float millSecPerFrame;
};
游戏定时器.cpp
#include "GameTimer.h"
GameTimer::GameTimer() {
_int64 countsPerSec = 0;
QueryPerformanceFrequency((LARGE_INTEGER*)&countsPerSec);
secsPerCount = 1.0f / (float)countsPerSec;
prevTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)&prevTimeStamp);
framesPerSec = 0.0f;
millSecPerFrame = 0.0f;
}
void GameTimer::Update()
{
static float numFrames = 0.0f;
static float timeElapsed = 0.0f;
numFrames += 1.0f;
timeElapsed += GetFrameTime();
if(timeElapsed >= 1.0f)
{
framesPerSec = numFrames;
millSecPerFrame = 1000.0f / numFrames;
numFrames = 0;
timeElapsed = 0;
}
}
float GameTimer::GetFrameTime() {
_int64 currentTimeStamp = 0;
QueryPerformanceCounter((LARGE_INTEGER*)¤tTimeStamp);
float timeDiff = (currentTimeStamp - prevTimeStamp) * secsPerCount;
prevTimeStamp = currentTimeStamp;
return timeDiff;
}
知道它只是屏幕上的一个三角形(没有绘制复杂的东西),如果我关闭 VSync,它应该每秒渲染超过 1000 帧,不是吗?