linux - X11 窗口大小调整卡顿

标签 linux opengl x11

我正在 X11 中创建一个 openGL 窗口并使用 glxswapbuffers 进行双缓冲。

问题是:渲染看起来不错,但我发现 openGL 内容四处跳动,并且在调整大小时窗口边框断断续续。

我尝试过滤 ConfigureNotify 事件、延迟它们、使用 glXSwapInterval 关闭 vsync ... 没有任何效果。

这是我正在使用的代码

void Window::redraw() { // Called by any control which needs redrawing
  XEvent event;
  memset(&event, 0, sizeof(event));
  event.type = Expose;
  event.xexpose.display = display;
  XSendEvent(display, window, False, ExposureMask, &event);
}

void Window::resize(int width, int height) {
  this->Width = width;
  this->Height = height;
}

bool Window::wndProc(XEvent *evt) {
  switch (evt->type) {

      case Expose: {

        if (evt->xexpose.count == 0) { // handle last one only

          while (XCheckTypedWindowEvent(display, window, Expose, evt));

            if (Width != oldWidth || Height != oldHeight)
              resizeViewportAndUpdateDimensions();

          Renderer.drawGLStuff();

          this->redraw();
        }

        return true;

      } break;

      case ConfigureNotify: {
        this->resize(evt->xconfigure.width, evt->xconfigure.height);

        this->redraw();
        return true;
      } break;
  }
}

请注意,这是一个不同于 this previous post 的问题(严格与调整大小相关)我通过 XCheckTypedWindowEvent 解决了这个问题。

最佳答案

https://tronche.com/gui/x/xlib/events/window-state-change/configure.html

https://tronche.com/gui/x/xlib/events/structure-control/resize.html

从这两个链接中我可以读到 ConfigureNotify 在更改完成时发生。 ResizeRequest 在尝试调整大小时发生。具体来说:

The X server can report ResizeRequest events to clients wanting information about another client's attempts to change the size of a window.

我不喜欢“CAN report”的声音,但我想你应该试一试。不要忘记按照链接中的说明设置正确的事件位。至于在捕获事件时你应该​​做什么我不太确定......我会清除前台缓冲区并等待调整大小完成。

关于linux - X11 窗口大小调整卡顿,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36414716/

相关文章:

linux bash,尽管有足够的内存,但出现无法分配内存的错误,为什么?

linux - systemd 脚本 - 由 ExecStartPre 更新的环境文件

c++ - ulimit 对核心文件大小没有影响?

c++ - 将 glRotate 和 glTranslate 与碰撞检测结合使用

node.js - NPM 在通过 apt 安装时需要 x11

linux - X11 是否有 lifesign 或恒定流?

x11 - 如何在低级别上最小化 X 窗口(不是 wmctrl 或 xdotool)?

c++ - Linux 上的 .NET Core - 编码(marshal)结构

c++ - OpenGL 混合功能可消除图元重叠但保持整体不透明度

c - OpenGL (GLFW) 在 macOS Mojave 上不显示图像