QOpenGLWidget与共享的OpenGL上下文? [英] QOpenGLWidget with shared OpenGL context?

查看:1289
本文介绍了QOpenGLWidget与共享的OpenGL上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有的OpenGL上下文,我想与一个新的QOpenGLWidget共享.

I have an existing OpenGL context that I would like to share with a new QOpenGLWidget.

我知道我可以做到:

  1. 创建QOpenGLWidget
  2. 等待直到调用initializeGL并保存上下文
  3. 创建新的QOpenGLContext,并使其与保存的上下文共享

但是,我想按其他顺序进行操作:

However, I would like to do it in the other order:

  1. 创建QOpenGLContext
  2. 创建QOpenGLWidget,提供现有上下文并使其共享

这可能吗?

推荐答案

编辑,我对QOpenGLFramebufferObject的了解不多,所以请忽略我以前的答案内容.

Edit, I don't know much about QOpenGLFramebufferObject yet so ignore my previous answer content.

在QOpenGLWidget中,它总是将其上下文设置为与其最接近的顶层窗口(如果是窗口,则为自身)共享.您的理解是正确的,如果没有子类化就无法完全改变其工作方式,则无法更改QOpenGLWidget成员上下文.在QOpenGLWidgetPrivate :: initialize()函数中,上下文是从defaultFormat和顶级shareContext初始化的.如果要在创建QOpenGLWidget之前使用上下文,则必须通过全局共享上下文.在创建QGuiApplication对象之前,需要先设置Qt :: AA_ShareOpenGLContexts.

In the QOpenGLWidget it always sets its context to share with its closest top level window (or itself if it is a window). You are correct in your understanding that there is no way to change the QOpenGLWidget member context without subclassing it to totally change how it works. In the QOpenGLWidgetPrivate::initialize() function the context is initialized from the defaultFormat and from the top level shareContext. If you want to work with the context before you create the QOpenGLWidget then it must be through the global shared context. Qt::AA_ShareOpenGLContexts needs to be set before your QGuiApplication object is created.

您需要等待QGuiApplication初始化全局上下文,然后才能尝试访问它.由于global_share_context是QOpenGLContext类的静态成员,因此您可以创建任何QOpenGLContext并通过context.globalShareContext()访问它.然后只需删除您的初始QOpenGLContext.您创建的任何QOpenGLWidget将自动与该上下文共享.如果在create()特殊上下文之前可以找到指向全局共享上下文的指针的方法,则可以与全局上下文共享,并且共享是双向的.共享是通过彼此共享的整个共享上下文组进行的,因此与一个上下文进行的任何共享都将与整个组共享.

You need to wait until QGuiApplication has initialized the global context before you try to access it. As the global_share_context is a static member of the QOpenGLContext class then you can just create any QOpenGLContext and access it via context.globalShareContext(). Then just delete your initial QOpenGLContext. Any QOpenGLWidget you create will share with that context automatically. If you can find a way of getting a pointer to the global shared context before you create() your special context then you can just share with the global context and you are good to go as the sharing goes both ways. The sharing is through the whole group of shared contexts that are shared with each other so any sharing with one context shares with the whole group.

此外,除了 QOpenGLContext表示它也可以共享帧缓冲对象.

Also, I don't know if this changes anything but The QOpenGLContext says it can share framebuffer objects too.

这篇关于QOpenGLWidget与共享的OpenGL上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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