QT 非 GUI 线程上的 WGL 窗口

问题描述

我开始尝试使用 QT 的 OpenGL 资源在非 GUI 线程上创建 OpenGL 渲染窗口,如该线程中所述:

https://forum.qt.io/topic/123151/qwindow-on-a-non-gui-thread

我尝试这样做的原因是因为我的 GUI 线程非常忙于处理大量事件和小部件,这会导致我在使用 QWindow 时出现卡顿和丢帧。

目前,我已经创建了一个用于创建 QOpenGLContext 的原生 WGL 上下文/窗口: 这是该项目的 github 链接https://github.com/rtavakko/WinGL

void OpenGLNativeRenderWindow::showNative()
{
    //Create native window and context
    createNative();

    //Allocate memory for the context object and prepare to create it
    openGLContext = new QOpenGLContext(this);

    QWGLNativeContext nativeContext(hglrc,hwnd);
    openGLContext->setNativeHandle(QVariant::fromValue(nativeContext));

    openGLContext->setFormat(openGLFormat);
    if(sharedOpenGLContext)
        openGLContext->setShareContext(sharedOpenGLContext);

    //Make sure the context is created & is sharing resources with the shared context
    bool contextCreated = openGLContext->create();
    assert(contextCreated);

    if(sharedOpenGLContext)
    {
        bool sharing = QOpenGLContext::areSharing(openGLContext,sharedOpenGLContext);
        assert(sharing);
    }

    //Resize / show window
    resize(renderSpecs.frameType.width,renderSpecs.frameType.height);
    visible = !ShowWindow(hwnd,SW_SHOWnorMAL);
}

所有资源(包括本机窗口)的创建都没有问题,我能够在单独的线程上使 QT 上下文当前,OpenGL 渲染也不会产生错误,但 Hello Triangle 不会在我的窗口上渲染。似乎原生 WGL 上下文和 QT 上下文仍然是独立的实体。

如果我直接调用 WGL 使上下文成为当前/交换缓冲区,我似乎能够在本机窗口上进行 OpenGL 调用,但似乎我仍然无法访问 QT 上下文呈现的资源(例如 FBO 输出纹理)。

对可能出什么问题有任何想法吗?

干杯!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)