glfwSwapInterval(1) fails to enable vsync?
Asked Answered
D

3

12

glfwSwapInterval(1) doesn't seem to be working for me. If I force VSync in CCC or setVerticalSyncEnabled(true) in SFML my fps drops to 60, but GLFW just keeps running at 9000 fps. Am I going about this the wrong way or is GLFW bugged?

Dairying answered 29/4, 2013 at 18:18 Comment(6)
What GPU are you using? GLFW FAQ says something about glfwSwapInterval not working on some ATI drivers. I've never used GLFW, but could you perhaps try directly calling (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT")?Brainwash
@EdwardA yes it ATI. Why would it work in SFML then though? wglSwapIntervalEXT works for some reason... So GLFW is bugged?Dairying
I can't tell you for sure, although if wglSwapIntervalEXT works it sure means it has something to do with GLFW. You could try downloading the GLFW source, compile your program alongside with it and put a breakpoint @ line 831 window.c and line 1638 win32_window.c to see whats really happening. It could be one of those if checks failing.Brainwash
Well... _glfwIsCompositionEnabled() returns true. Oh well gotta do it manually then. Thanks :)Dairying
I see the same issue on Intel HD 4600 graphics on Windows7. So it is not a strictly ATI problem.Pigeon
@EdwardA This GLFW issue was fixed in release 3.1.2.Jacklin
D
9

Well looks like GLFW doesn't want to turn VSync on when desktop compositing is enabled. If you want VSync anyway this will work on Windows:

#ifdef _WIN32
    // Turn on vertical screen sync under Windows.
    // (I.e. it uses the WGL_EXT_swap_control extension)
    typedef BOOL (WINAPI *PFNWGLSWAPINTERVALEXTPROC)(int interval);
    PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
    wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
    if(wglSwapIntervalEXT)
        wglSwapIntervalEXT(1);
#endif

For other OSs google will help you.

Dairying answered 30/4, 2013 at 15:42 Comment(1)
This fix did not work on my Intel HD 4600, as the proc address was 0. But configuring GLFW3 to use GLFW_USE_DWM_SWAP_INTERVAL did.Pigeon
P
3

Rebuild GLFW3 with the GLFW_USE_DWM_SWAP_INTERVAL option.

See glfw/src/config.h

The GLFW docs warn about jitter problems, but I don't see those myself.

Pigeon answered 17/9, 2013 at 23:21 Comment(1)
With release 3.1.2 this flag was removed; however, the fix is also in, so it isn't needed any longer :)Jacklin
P
2

Found that glfwSwapInterval needed calling again after changing between window and full screen mode, otherwise the framerate would be massive.

if (fullScreen)
            {
                glfwSetWindowMonitor(window, monitor, 0, 0, monitorMode->width, monitorMode->height, monitorMode->refreshRate);

                // Added to fix framerate to vertical refresh //
                glfwSwapInterval(1);
            }
            else
            {
                glfwSetWindowMonitor(window, NULL, 0, 0, monitorMode->width, monitorMode->height, monitorMode->refreshRate);
            }
Prove answered 1/1, 2019 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.