简体   繁体   English

xlib / egl如何在eglSwapBuffers上获取VSync / swapInterval

[英]xlib / egl how to get VSync/swapInterval on eglSwapBuffers

I'm wondering how to properly enable vsync with eglSwapBuffers when using xlib. 我想知道使用eglSwapBuffers时如何使用eglSwapBuffers正确启用vsync。 It seems that calls to eglSwapInterval are simply ignored. 似乎对eglSwapInterval调用只是被忽略了。

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 http://lists.freedesktop.org/archives/mesa-commit/2010-May/021020.html

egl: Implement EGL_NOK_swap_region egl:实施EGL_NOK_swap_region

This extension adds a new function which provides an alternative to eglSwapBuffers. 此扩展添加了一个新功能,该功能可替代eglSwapBuffers。 eglSwapBuffersRegionNOK accepts two new parameters in addition to those in eglSwapBuffers. 除了eglSwapBuffers中的参数外,eglSwapBuffersRegionNOK还接受两个新参数。 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. 新参数包括一个指向定义矩形(x,y,宽度,高度)的4整数块列表的指针,以及一个指定列表中矩形数量的整数。

And /usr/include/EGL/eglmesaext.h declares 和/usr/include/EGL/eglmesaext.h声明

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 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; 它看起来确实更平滑并且降低了帧速率,但仅降低到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? 也许它仅在关键的GPU操作的短暂间隔内阻止交换缓冲区? Or maybe I'm not doing it right. 也许我做的不对。 Not sure. 不确定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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