简体   繁体   English

如何从CGLContextObj创建QGLWidget?

[英]How to create a QGLWidget from a CGLContextObj?

I'm using Qt 4.8.4 on Mac OS 10.8. 我在Mac OS 10.8上使用Qt 4.8.4。

I already have a CGLContextObj (created outside my control). 我已经有一个CGLContextObj (在控件之外创建)。

I would like to create a QGLWidget from (or at least shared with) my existing CGLContextObj — so I can render the textures which were created on the CGLContextObj . 我想从现有的CGLContextObj (或至少与之共享)创建QGLWidget ,以便渲染在CGLContextObj上创建的纹理。

How can I create a QGLContext from the existing CGLContextObj ? 如何创建一个QGLContext从现有CGLContextObj


Already tried 已经尝试过

  • I found QGLContext::fromPlatformGLContext() , but this method appears to only be available when Qt is built in QPA mode (...but ./configure -qpa cocoa fails to build, and I haven't been able to find any documentation on exactly what the -qpa flag does). 我发现了QGLContext::fromPlatformGLContext() ,但是这种方法仅在以QPA模式构建Qt时才可用(...但是./configure -qpa cocoa无法构建,并且我找不到任何文档-qpa标志的作用)。

QPA (Qt Platform Abstraction) was still a work in progress in Qt 4. It's fully integrated into Qt 5 . QPA(Qt平台抽象)仍在Qt 4中进行。它已完全集成到Qt 5中 If you have the option to upgrade to Qt 5, things might be easier. 如果您可以选择升级到Qt 5,事情可能会更容易。

In Qt 5, you can construct a QCocoaGLContext (a derived class of QPlatformOpenGLContext ), and from that get a QOpenGLContext ( QPlatformOpenGLContext::context() ), and from that get a QGLContext ( QGLContext::fromOpenGLContext(QOpenGLContext *) ). 在Qt 5,您可以构建一个QCocoaGLContext (派生类的QPlatformOpenGLContext ),并从获得QOpenGLContextQPlatformOpenGLContext::context()并从获得QGLContextQGLContext::fromOpenGLContext(QOpenGLContext *) That gets you pretty close, but how do you get from a CGLContextObj to a QCocoaGLContext ? 这使您非常接近,但是如何从CGLContextObjQCocoaGLContext

Unfortunately, I don't see an option to construct a QCocoaGLContext from a CGLContextObj . 不幸的是,我看QCocoaGLContextCGLContextObj构造QCocoaGLContext的选项。 It does have a NSOpenGLContext private data member, which is initialized inside the existing constructor, so maybe you could add another constructor. 它确实有一个NSOpenGLContext私有数据成员,该成员在现有构造函数中初始化,因此也许您可以添加另一个构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM