gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:29:54 26 4
gpt4 key购买 nike

我想知道在使用 xlib 时如何使用 eglSwapBuffers 正确启用 vsync。似乎对 eglSwapInterval 的调用被简单地忽略了。

我在窗口模式和全屏模式下运行。是否有可能在窗口模式下根本不支持它?在这种情况下,什么是降低我渲染频率的好方法( sleep 往往会导致错误行为,因为无法保证何时醒来)。

最佳答案

经过大量谷歌搜索,我终于找到了这个:

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.

并且/usr/include/EGL/eglmesaext.h 声明

EGLAPI EGLBoolean EGLAPIENTRY eglSwapBuffersRegionNOK(EGLDisplay dpy, EGLSurface surface, EGLint numRects, const EGLint* rects);

这里还有一些示例用法:

https://github.com/blazt/piglit/blob/master/tests/egl/egl-nok-swap-region.c

所以我尝试这样使用它:

EGLint dirtyRect[4] = { 0, 0, 0, 0 };
PFNEGLSWAPBUFFERSREGIONNOK swap_buffers_region = (PFNEGLSWAPBUFFERSREGIONNOK)
eglGetProcAddress("eglSwapBuffersRegionNOK");

在我的窗口大小调整回调中

dirtyRect[2] = windowWidth;
dirtyRect[3] = windowHeight;

在我的主循环中

if (swap_buffers_region)
swap_buffers_region(egl_dpy, egl_surf, 1, dirtyRect);
else
eglSwapBuffers(egl_dpy, egl_surf);

它确实看起来更流畅并降低了帧率,但仅降至 180-200 FPS 的范围;所以我仍然需要在帧之间做一个 sleep 。也许它只会在关键 GPU 操作的一些短时间间隔内阻止交换缓冲区?或者也许我做得不对。不确定。

关于linux - xlib/egl 如何在 eglSwapBuffers 上获取 VSync/swapInterval,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11971947/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com