是否可以在Qt的顶级窗口之间使用相同的OpenGL上下文? [英] Is it possible to use the same OpenGL context between top-level windows in Qt?

查看:562
本文介绍了是否可以在Qt的顶级窗口之间使用相同的OpenGL上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Qt中开发一个编辑器,该编辑器将在多个顶级窗口中同时运行多个GL上下文.由于无法在上下文之间共享VAO,因此我试图提出一种基于每个上下文进行管理的方法,事实证明这相当复杂.

I'm developing an editor in Qt that will have multiple GL contexts running simultaneously in multiple top-level windows. Since VAOs can't be shared between contexts, I'm trying to come up with a way to manage them on a per-context basis, which is proving to be fairly complicated.

如果我可以简单地在两者之间使用相同的上下文,则要简单得多,但是Qt 5.4似乎无法做到这一点. QGLWidget能够显式地将QGLContext指针用作构造函数参数,但是QOpenGLWidget没有相应的功能.这是文档关于上下文共享的内容:

It would be a lot simpler if I could just simply use the same context between both, but this doesn't seem to be possible with Qt 5.4. QGLWidget was able to explicitly take a QGLContext pointer as a constructor parameter, but there's no corresponding function for QOpenGLWidget. This is what the documentation says about context sharing:

将多个QOpenGLWidgets作为子级添加到同一顶层Widget时,它们的上下文将彼此共享.这不适用于属于不同窗口的QOpenGLWidget实例.

When multiple QOpenGLWidgets are added as children to the same top-level widget, their contexts will share with each other. This does not apply for QOpenGLWidget instances that belong to different windows.

有没有办法解决这个问题?

Is there a way around this?

不幸的是,由于QOpenGLWidget相对较新,我找不到关于该主题的太多信息-我所能找到的大部分都是关于QGLWidget的.

I can't find too much info on the subject unfortunately, since QOpenGLWidget is relatively new - most of what I can find is talking about QGLWidget.

edit:我正在尝试一些不同的事情,并且在创建自定义GL小部件方面取得了一些成功,因此我可以自己管理上下文,尽管存在一些错误.但是,在某些情况下,听起来好像实际上需要为不同的窗口提供不同的上下文,这意味着我应该坚持使用QOpenGLWidget并提出一个VAO管理系统.如果对这个主题有更多知识/经验的人可以解释它是如何工作的,那就太好了.

edit: I'm trying some different things and I've had a little bit of success creating a custom GL widget so I can manage the contexts myself, although there's some bad bugs. However it's sounding like it's actually required to have different contexts for different windows in some cases, which would mean I should just stick with QOpenGLWidget and come up with a VAO-management system. It would be cool if someone with more knowledge/experience on the subject could explain how this works though.

推荐答案

来自

设置属于QOpenGLWidget实例之间的共享 不同的窗口,设置Qt :: AA_ShareOpenGLContexts应用程序 实例化QApplication之前的属性.这将触发共享 在所有QOpenGLWidget实例之间切换,而无需任何其他步骤.

To set up sharing between QOpenGLWidget instances belonging to different windows, set the Qt::AA_ShareOpenGLContexts application attribute before instantiating QApplication. This will trigger sharing between all QOpenGLWidget instances without any further steps.

根据应用程序属性文档,此标记为在版本5.4中引入

According to the Application Attribute documentation, this flag was introduced in version 5.4

这篇关于是否可以在Qt的顶级窗口之间使用相同的OpenGL上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆