xlib / egl how to get VSync/swapInterval on eglSwapBuffers
Asked Answered
R

1

1

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

Rhinencephalon answered 15/8, 2012 at 15:9 Comment(0)
A
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.

Alida answered 8/4, 2013 at 21:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.