QGLWidget的paintGL()方法是从哪个Qt线程调用的?
假设我使用 QGLWidget 的 PaintGL() 方法通过 OpenGL 绘制到小部件中。 Qt调用paintGL()方法后,会自动触发缓冲区交换。在OpenGL中,这种缓冲区交换通常会阻塞调用线程,直到帧渲染到后台缓冲区完成,对吧?我想知道哪个 Qt 线程调用 PaintGL 以及缓冲区交换。它是 Qt UI 主线程吗?如果是,那是不是意味着缓冲区交换期间的阻塞也会阻塞整个 UI?我一般找不到有关此过程的任何信息。
谢谢
suppose I use the QGLWidget's paintGL() method to draw into the widget using OpenGL. After the Qt called the paintGL() method, it automatically triggers a buffer swap. In OpenGL, this buffer swap usually blocks the calling thread until the frame rendering to the background buffer is completed, right? I wonder which Qt thread calls the paintGL as well as the buffer swap. Is it the main Qt UI thread? If it is, wouldn't that mean that the block during the buffer swap also blocks the whole UI? I could not find any information about this process in general..
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不经常使用 QGLWidget,但请考虑一下,是的,如果 swapBuffers() 是同步的,Qt GUI 线程就会卡住。这意味着在该操作期间您将无法处理事件。
无论如何,如果您在执行此操作时遇到困难,请考虑阅读这篇文章 它设法让多线程OpenGL克服这个困难。
更好的是,这篇文章很好地解释了这种情况,并介绍了 Qt 4.8 中新的多线程 OpenGL 功能,该版本目前处于候选版本中。
I don't use the QGLWidget very often, but consider that yes, if swapBuffers() is synchronous the Qt GUI thread is stuck. This means that during that operation you'll be unable to process events.
Anyway, if you're experiencing difficulties while doing this, consider reading this article which manage to allow multithreaded OpenGL to overcome this difficulty.
Even better, this article explains well the situation and introduces the new multithreading OpenGL capabilities in Qt 4.8, which is now in release candidate.
这取决于它如何实施。这意味着它因硬件和驱动程序而异。
即使它确实阻塞,也只会阻塞 1/60 秒。如果你的游戏速度变慢,可能是 1/30。如果你真的很慢,1/15。用户最多执行一次按键或鼠标操作仍将保留在消息队列中。
阻塞问题与用户界面无关。它的响应速度足以让用户不会注意到。但如果你有严格的时间安排(比如你可能会玩游戏),我建议完全避免
paintGL
。你应该在你想要的时候渲染,而不是在 Qt 告诉你的时候渲染。It depends on how it is implemented. Which means that it varies from hardware to hardware and driver to driver.
Even if it does block, it will only do so for 1/60th of a second. Maybe 1/30th if your game is slowing down. If you're really slow, 1/15th. The at most one keypress or mouse action that the user gives will still be in the message queue.
The issue with blocking isn't about the UI. It will be responsive enough for the user to not notice. But if you have strict timings (such as you might for a game), I would suggest avoiding
paintGL
at all. You should be rendering when you want to, not when Qt tells you to.