我正在 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/