xlib / egl how to get VSync/swapInterval on eglSwapBuffers

百般思念 提交于 2019-12-25 16:58:10

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!