Qt QGLWidget OpenGL 在 swapBuffers() 上从线程块渲染

发布于 2024-12-13 20:13:33 字数 849 浏览 0 评论 0原文

我有一个奇怪的问题,从与主线程不同的线程将 OpenGL 渲染到 QGLWidget。

Qt 开发者有很多官方声明称“完全有可能”从不同的线程进行渲染。我遵循以下解释:

http://doc.qt.nokia.com /qq/qq06-glimpsing.html#writingmultithreadedglapplications

我以几乎相同的方式实现了它。唯一的区别是,我不将 QWorkspace 与不同的 GLWidget 一起使用,而是仅创建一个以 GLWidget 作为中央小部件的 MainWindow。

当我启动应用程序时,渲染线程开始在随机位置渲染带有三角形的帧。一段时间后(有时 2 秒,有时 10 秒),线程开始在 swapBuffers() 调用上阻塞很长时间。有时,swapBuffers() 会在几秒钟后自动返回。当我将鼠标指针移动到小部件或主窗口上时,swapBuffers 立即返回,并且只要我移动鼠标指针,swapBuffers() 就不会阻塞。将鼠标移出小部件或停止移动鼠标后,渲染会继续几秒钟,然后 swapBuffers 再次开始阻塞。

我对这种行为完全没有任何解释。我知道 swapBuffers() 会定期阻塞,直到一帧完成,而且我也清楚,在 OpenGL 缓冲区交换调用期间也可能发生等待 vsync。但这应该在几毫秒内发生,并且不会阻塞几秒钟。环境是 X11 和 GLX。

有人知道这里发生了什么吗? 我什至不知道如何找出问题所在。

是否有人尝试按照我上面链接的文档中的说明从不同线程实现渲染?

I have a strange problem rendering OpenGL to QGLWidget from a different thread than the main thread.

There are a lot of official statements from Qt Developers that it is "perfectly possible" to do rendering from a different thread. I followed the explanation in:

http://doc.qt.nokia.com/qq/qq06-glimpsing.html#writingmultithreadedglapplications

I implemented it nearly the same way. The only difference is, that I dont use QWorkspace with different GLWidgets but instead I just create a MainWindow with GLWidget as central widget.

When I start the application, the rendering thread starts rendering frames with a triangle at a random position. After a while (sometimes 2 seconds, sometimes 10 seconds) the thread starts to block on the swapBuffers() call for a very long time. Sometimes swapBuffers() returns spontanously after several seconds. When I move the mouse pointer over the widget or the main window, the swapBuffers returns immediately and the as long as I move the mouse pointer swapBuffers() does not block. After moving the mouse out of the widget or just stop moving the mouse, rendering continues for some seconds and then swapBuffers start blocking again.

I have absolutely no explanation for this behaviour. I am aware that swapBuffers() regulary blocks until a frame is completed and it's also clear to me, that a wait for vsync also might happen during OpenGL buffer swap call. But that should happen in some milliseconds and not block for several seconds. The environment is X11 with GLX.

Does anybody has an idea wtf is going on here?
I dont even have an idea how to find out what the problem might be..

Does anyone tried to implement the rendering from different thread as explained in the document that I linked above?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文