Is there a way to remove 60 fps cap in GLFW?
Asked Answered
S

2

14

I'm writting a game with OGL / GLFW in c++.

My game is always running at 60 fps and without any screen tearing. After doing some research, it seems that the glfwSwapInterval() function should be able to enable/disable V-sync or the 60fps cap.

However, no matter the value I pass to the function, the framerate stays locked at 60 and there is no tearing whatsoever. I have also checked the compositor settings on linux and the nvidia panel, and they take no effect.

This is a common thing I assume, is there a way to get around this fps cap?

Stila answered 18/5, 2018 at 13:37 Comment(7)
You may have vsync hard enabled in your GPU driver. Search how to disable it with whatever vendor, and see if it unlocks the framerate.Lukelukens
10 seconds of google (GLFW vsync) led me to this: glfw.org/docs/latest/… -- a way to query about your GLFW implementations implementation of extensions around tear support. When you called it what did it say about support for those extensions?Blubberhead
@Lukelukens I already tried that, the vsync in my driver is disabled but thank you anyways.Stila
@Yakk-AdamNevraumont I tried with "GLX_EXT_swap_control" and the result was true. I take it that means swap control can be used, but shouldn't that be the glfwSwapInterval() line I tried before?Stila
glfwSwapInterval(0) would be the programmatic way, unless you need to override it directly in a driver (GPU) control panel.Vishnu
Okay everyone, thank you for all your answers. I figured how to solve this in the end. Looks like setting glfwSwapInterval to 0 or 1 or other number greater than 1 just enables/disables it fully rendering it useless for the vsync purpose. Setting it to 0.5 however, tells glfw to double the framerate limit to twice your screen refresh rate (120 fps in my case) and also disables vsync. So what I did to get this working was to play with glfwSwapInterval() changing the value between 0 and 1. Hope this helps whoever finds this posts afterwards.Stila
@Stila use glfwSwapInterval(0), but call this function right after the call to glfwMakeContextCurrentBarcellona
D
19

Is there a way to remove 60 fps cap in GLFW?

The easiest way is to use single buffering instead of double buffering. Since at single buffering is always use the same buffer there is no buffer swap and no "vsync".

Use the glfwWindowHint to disable double buffering:

glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_FALSE);
GLFWwindow *wnd = glfwCreateWindow(w, h, "OGL window", nullptr, nullptr);

Note, when you use singel buffering, then you have to explicite force execution of the GL commands by (glFlush), instead of the buffer swap (glfwSwapBuffers).


Another possibility is to set the number of screen updates to wait from the time glfwSwapBuffers was called before swapping the buffers to 0. This can be done by glfwSwapInterval, after making the OpenGL context current (glfwMakeContextCurrent):

glfwMakeContextCurrent(wnd);
glfwSwapInterval(0);

But note, whether this solution works or not, may depend on the hardware and the driver.

Debag answered 19/5, 2018 at 17:27 Comment(3)
Are you sure about GL_FALSE / GLFW_FALSE.Trantrance
@Trantrance both are 0Debag
By using single buffering you'll not only get tearing, but also other glitches like e.g. half-rendered scene alternating with completely rendered version, depending on how often the driver flushes commands to the GPU before it gets actual glFlush. Using blocking commands like glReadPixels will also present half-baked scene. May be better to render to an FBO and then blit to present the complete scene.Belligerent
O
0

I used this:

glfwSwapInterval(0); // disable V-Sync, so fps aren't limited to 60

Orle answered 5/1 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.