问题描述
我有一个DirectX9应用程序,它只能在屏幕上渲染一个三角形,但是无论是否启用了VSync,我的帧速率都为60 FPS.为什么会这样?
I have an DirectX9 application which only renders a triangle on the screen, but I am getting a frame rate of 60 FPS no matter if I've got VSync on or not. Why is this?
这是我用来计算FPS的代码,但我不知道这是否是问题所在.
Here is the code I've done to calculate the FPS, but I dont know if this is the problem to it.
GameTimer.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;
};
GameTimer.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帧以上吗?
Knowing that it's only a triangle on the screen (no complicated stuff being drawn), it should render over 1000 frames per second if I have VSync off shouldn't it?
推荐答案
在CreateDevice
调用中,将D3DPRESENT_PARAMETERS
参数的PresentationInterval
设置为D3DPRESENT_INTERVAL_IMMEDIATE
.
In the CreateDevice
call, set the PresentationInterval
of the D3DPRESENT_PARAMETERS
parameter to D3DPRESENT_INTERVAL_IMMEDIATE
.
这篇关于关闭了VSync,但在DirectX 9应用程序中仍然获得60FPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!