简体   繁体   中英

xlib / egl how to get VSync/swapInterval on eglSwapBuffers

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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM