Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. QtPlatformHeaders and QCocoaNativeContext
Qt 6.11 is out! See what's new in the release blog

QtPlatformHeaders and QCocoaNativeContext

Scheduled Pinned Locked Moved Solved Installation and Deployment
4 Posts 2 Posters 1.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arkiruthis
    wrote on last edited by Arkiruthis
    #1

    Greetings everyone. I'm needing to get the nativeHandle for a QOpenGLWidget in order to set up initialisation for some OpenCL (note: CL, not GL) functions. As I am on Mac, it seems I need to include some specific Qt headers.

    #include <QtPlatformHeaders/QCocoaNativeContext>
    

    However, in QtCreator it doesn't seem to be finding these specific platform headers.
    I can confirm my Qt installation contains them at: (MyQtDir)/5.12.1/clang_64/include/QtPlatformHeaders/

    The following page:
    https://doc.qt.io/qt-5/qtplatformheaders-index.html
    indicates :-

    As the module is header-only, no further modifications to the .pro files are required to use it.
    
    Note: The module name (QtPlatformHeaders) must appear in the #include directive.
    
    Note: It is not necessary to enclose the code in #ifdef directives depending on platform.
    

    Sadly I'm at something of a loss as to how to resolve this.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Doesnt winId fill the bill ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arkiruthis
        wrote on last edited by Arkiruthis
        #3

        Hi @SGaist , thanks for the welcome!

        Unfortunately, I need to access the native context (a special struct dependent on platform). I'm able to use OpenCL fine in Qt at the moment, but it's much faster if I can use the GL/CL interoperability instead of manually storing pixel data, running OpenCL on it, then uploading it to the GPU again.

        The closest topic I can find is this one:
        Provide OpenGl context to a OpenCL context

        From the code section in that posting:

        QVariant nativeHandle = context->nativeHandle();
        if (!nativeHandle.isNull() && nativeHandle.canConvert<QWGLNativeContext>()) {
            QWGLNativeContext nativeContext = nativeHandle.value<QWGLNativeContext>();
            HGLRC hglrc = nativeContext.context();
            ...
        }
        

        Where @wwolff has used QWGNNativeContext for Windows, I would need to use QCocoaNativeContext for Mac. At that point, I think it's then used as CGLContextObj to obtain the share group, etc. for linking OpenGL and OpenCL.

        Both of these are structs are declared in the Qt/<version>/<compiler>/include/QtPlatformHeaders/ include path, which very strangely doesn't seem to be accessible from QtCreator. I've not succeeded in finding a way to get Qt to see this path.

        (in that post you did point to a QtOpenCL implementation which I'm looking at now for clues!)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Arkiruthis
          wrote on last edited by
          #4

          Hi @SGaist , I actually found the code I was looking for in that old QtOpenCL project you linked. Turns out to be a lot simpler than I had originally thought! Very portable too.

          Here it is in case anyone searches in future:

              glWidget->makeCurrent(); 
          
              if(CGLContextObj context = CGLGetCurrentContext()) {
                  if(CGLShareGroupObj shareGroup = CGLGetShareGroup(context)) {
                      cl_context_properties properties[] = { CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE, cl_context_properties(shareGroup), 0 };
                      auto appleCLContext = cl::Context(CL_DEVICE_TYPE_ALL, properties);
                      auto availableDevices = appleCLContext.getInfo<CL_CONTEXT_DEVICES>();
                      for(auto& d : availableDevices) {
                          qDebug() << d.getInfo<CL_DEVICE_NAME>().c_str();
                      }
                  }
              }
          
          

          NOTE: This method is specific to Apple which uses sharegroups to initialise OpenCL/OpenGL interoperability. The Windows and Linux methods are different.

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved