问题
I'm wondering how to properly enable vsync with eglSwapBuffers
when using xlib. It seems that calls to eglSwapInterval
are simply ignored.
I'm running both in a windowed and full-screen mode. Is it possible that it simply isn't supported in the windowed mode? In this case, what is a good way to reduce the frequency at which I render (sleeping tends to cause errative behaviour as there is no guarantee when it awakes).
回答1:
Eventually I found this after a lot of googling:
http://lists.freedesktop.org/archives/mesa-commit/2010-May/021020.html
egl: Implement EGL_NOK_swap_region
This extension adds a new function which provides an alternative to eglSwapBuffers. eglSwapBuffersRegionNOK accepts two new parameters in addition to those in eglSwapBuffers. The new parameters consist of a pointer to a list of 4-integer blocks defining rectangles (x, y, width, height) and an integer specifying the number of rectangles in the list.
And /usr/include/EGL/eglmesaext.h declares
EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);
There's also some example usage here:
https://github.com/blazt/piglit/blob/master/tests/egl/egl-nok-swap-region.c
So I tried using it like this:
EGLint dirtyRect[4] = { 0, 0, 0, 0 };
PFNEGLSWAPBUFFERSREGIONNOK swap_buffers_region = (PFNEGLSWAPBUFFERSREGIONNOK)
eglGetProcAddress("eglSwapBuffersRegionNOK");
and in my window resizing callback
dirtyRect[2] = windowWidth;
dirtyRect[3] = windowHeight;
and in my main loop
if (swap_buffers_region)
swap_buffers_region(egl_dpy, egl_surf, 1, dirtyRect);
else
eglSwapBuffers(egl_dpy, egl_surf);
It does seem smoother and slowed down the frame rate, but only down to the range of 180-200 FPS; so I still need to do a usleep between frames. Maybe it only blocks swapping buffers during some short interval of critical GPU operations? Or maybe I'm not doing it right. Not sure.
来源:https://stackoverflow.com/questions/11971947/xlib-egl-how-to-get-vsync-swapinterval-on-eglswapbuffers