Hi, I'm using vsync for frame flipping, but I'm a bit confused on how to control the frame flipping. Right now i time a frame and try to guess what frequency vsync is running at (See code below). I've read games will render a heavy scene (lots of particle effects & sprites/models) at startup and use that dt value for the game.
The questions I had were:
1. Is there a way to get the rates that vysnc will occur at? I found 24fps was a common frame rate by timing. Can vysnc only be the monitor refresh rate equally divided by a whole number. ie. for 60fps the rates would be 60, 30, 15, 10?
2. If the monitor refresh rate is 120fps but i wanted to cap the game at 60fps would i use setSwapInterval for this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | float idealFrameTime = 1.0f / mode.refresh_rate; //use monitor refresh rate
...
...
dt = timeInFrameSeconds / 1000;
float frameRates[] = {idealFrameTime*1.0f, idealFrameTime*2.0f, idealFrameTime*4.0f};
float smallestDiff = 0;
bool set = false;
float newRate = idealFrameTime;
for(int i = 0; i < arrayCount(frameRates); ++i) {
float val = frameRates[i];
float diff = dt - val;
if(diff < 0.0f) {
diff *= -1;
}
if(diff < smallestDiff || !set) {
set = true;
smallestDiff = diff;
newRate = val;
}
}
dt = newRate;
assert(dt <= frameRates[2]);
|
Thanks for you help.