c++ - 来自 GLFW 上下文的 QOpenGLContext

标签 c++ qt opengl glfw openglcontext

我们有一个使用 GLFW 创建的 3D 渲染窗口,我们希望使用 QWebkit 在渲染中显示 QWebPage(也称为将 QWebPage 渲染为 OpenGL 纹理)。只使用CPU版本太慢,Qt支持将QWebkit渲染成QOpenGLFramebufferObjects(使用QOpenGLPaintDevice)。

但是,这样做需要创建一个 QOpenGLContext(需要它自己的窗口等),最终会干扰我们的整个应用程序。 (GLFW和Qt Context之间切换也会导致无限量的GL_INVALID_OPERATION)

最佳案例解决方案:我们让 Qt 使用 GLFW 上下文。

代码示例:

QOpenGLFramebufferObject qfbo(mWidth, mHeight); //< this crashes because he will implicitly try to get QOpenGLFunctions which gets the default context which is null
qfbo.bind();
QOpenGLPaintDevice paintdev(mWidth, mHeight);

QPainter painter(&paintdev);
painter.beginNativePainting();
mPage->mainFrame()->render( &painter );
painter.endNativePainting();

这里有一些问题:

  • 是否可以让 Qt 使用 GLFW OpenGL 上下文?
  • 如果没有,我们如何在 GLFW 上下文和 Qt 上下文之间切换? (使用纹理共享来传输渲染的QWebPage)
  • 如果这一切都不可能,是否有一个免费的 Webkit 项目,支持 64 位、Windows/Linux/Mac,并且可以使用 OpenGL 进行渲染?

最佳答案

@Sebastian Cabot 写道:

You can't directly mix the two context objects using QT. QT is great but in order to keep itself portable it also has some limitations - mainly accessing the low level handles of the objects and manipulating them directly. So Even trying to use a QOpenGLContext from a different thread then the one it was created in will fail. And in order to use any of the QT OpenGL wrappers you will need a valid QOpenGLContext current. So what you want is not possible without hacking into the QT implementation.

关于c++ - 来自 GLFW 上下文的 QOpenGLContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20570680/

相关文章:

c++ - qt binarycreator 不创建 dmg

c++ - 用于枚举的模板化 QDataStream 运算符<<

c++ - OpenGL 着色器不与着色器程序链接

OpenGL 为什么需要统一变量(而不仅仅是常量)

无法调用 C++ 函数

c# - WPF 与 C++,这可能吗?

iphone - 为什么这会不断出错?

c++ - 如何在 Windows 10 中获取 QDialog 的 HWND

opengl - 我如何在java中使用opengl实现strafe?

C++:将 vector 中的项目存储到 map 中