如何解决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 举报,一经查实,本站将立刻删除。