zoukankan      html  css  js  c++  java
  • Retrieve OpenGL Context from Qt 5.5 on OSX

    In the latest Qt 5.5, the QOpenGLWidget is much better and has less bugs than the QGLWidget, but it doesn't supply the good API to retrieve the native OpenGL context. On Mac OSX the situation would be a bit more difficult, since the platform is in Obj-C not CC++ as Windows and Linux.

    So what you have to do to get the native Cocoa OpenGL context is to follow these steps.

    Write a header file CCocoaGLContext.h to declare the function interface.

    #pragma once
    
    void * GetCocoaGLContext(void * x);

    Write a Obj-C CCocoaGLContext.mm file, super easy

    #import <QCocoaNativeContext>
    
    #import "CCocoaGLContext.h"
    
    void * GetCocoaGLContext(void * x)
    {
        QCocoaNativeContext * p = (QCocoaNativeContext *)(x);
        if (p)
        {
            NSOpenGLContext * x = p->context();
            return [x CGLContextObj];
        }
        return 0;
    }

    In the application, that would be easy to get the native OpenGL handle.

    QVariant NativeHandle(GLContext->nativeHandle());
    #if defined(__APPLE__)
    CGLContextObj GLContext = reinterpret_cast<CGLContextObj>(GetCocoaGLContext(NativeHandle.data()));
    CGLShareGroupObj  GLShareGroup  = CGLGetShareGroup(GLContext);
    #elif defined(_MSC_VER)
    QWGLNativeContext WGLContext = NativeHandle.value<QWGLNativeContext>();
    #else
    QGLXNativeContext GLXContext = NativeHandle.value<QGLXNativeContext>();
    #endif

    It's super useful to initialize the OpenCL with GL Interop on 3 platforms.

  • 相关阅读:
    redis client 2.0.0 pipeline 的list的rpop bug
    Python解释器镜像源修改
    全连接层
    测试(张量)- 实战
    数据加载
    Python之微信-微信好友头像合成
    高阶操作
    MYSQL 查询缓存
    SQL Server 查看指定表上的索引
    MYSQL 查看表上索引的 1 方法
  • 原文地址:https://www.cnblogs.com/Jedimaster/p/5118744.html
Copyright © 2011-2022 走看看