【发布时间】:2016-04-12 10:38:50
【问题描述】:
Windows 的 C++ 端相当新 - 特殊的非 Win32,例如 UWP -
我试图通过简单地每 1000/60 毫秒打勾(更新/渲染)将 FPS 限制在稳定的 60 FPS。我面临着一个奇怪的情况。如果我使用 Present(0,0),交换链将自动锁定和垂直同步,一切都很好。如果我使用 Present1(0,DXGI_PRESENT_DO_NOT_WAIT, ¶ms) ...我达到 600 FPS...
现在,在释放 FPS (600) 的同时,我想实现自己的代码。到目前为止,我有:
bool Ticker::Tick() {
long currentTick = GetTickCount64();
long deltaTicks = (currentTick - gLastTick);
bool tick = false;
// determine whether it is tick time
if (deltaTicks >= gUpdateTime) {
gLastTick = currentTick;
gTicksCount++;
char buf[256];
sprintf_s(buf, "Current delta: %30d\n", deltaTicks);
OutputDebugStringA(buf);
tick = true;
}
// this metric must happen regardless of actual true Ticks
if (currentTick - gSecondTime >= 1000) {
gCurrentFrameRate = gTicksCount;
gSecondTime = currentTick;
OutputDebugStringW(L"Second is up\n");
gTicksCount = 0;
}
return tick;
}
不用说这是行不通的……当我的目标刷新率非常高 1000/60 时,我达到了 20/21 FPS。
我相信我犯了一个相当愚蠢的错误,但我看不出在哪里。
谢谢。
【问题讨论】:
-
这听起来像是一个愚蠢的问题...但是为什么要限制在 60 fps?当您在 75 Hz 显示器上运行它时会发生什么?只需正确执行并让 Present 阻止 - 这是限制 FPS 的正确方法。
-
@Sunius 不错,没错,但有时在调整帧速率时,您可能需要更多粒度,而不管 Present 如何阻止,对吧?
-
不,不是。你为什么要这样做?
标签: c++ uwp directx-11 frame-rate game-loop