Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Provide OpenGl context to a OpenCL context
Forum Updated to NodeBB v4.3 + New Features

Provide OpenGl context to a OpenCL context

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 3.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.
  • W Offline
    W Offline
    wwolff
    wrote on 6 Apr 2016, 18:48 last edited by wwolff 4 Jun 2016, 18:50
    #1

    Hi!
    Im starting make some improvements using hardware optimizations and one of them involves share the OpenGl buffers with my OpenCL buffers.
    Everything is running fine, but to enable this specific feature i need inform to the OpenCL context what OpenGL context i am using.
    But the OpenCL context are prepeared to receive wgl contexts (hdc) and i dont know how can i provide my QOpenGL context and make OpenCL understand it.
    Anyone have an idea how i can enable GLCL sharing using Qt?

    Kind Regards.

    W 1 Reply Last reply 7 Apr 2016, 14:35
    0
    • W wwolff
      6 Apr 2016, 18:48

      Hi!
      Im starting make some improvements using hardware optimizations and one of them involves share the OpenGl buffers with my OpenCL buffers.
      Everything is running fine, but to enable this specific feature i need inform to the OpenCL context what OpenGL context i am using.
      But the OpenCL context are prepeared to receive wgl contexts (hdc) and i dont know how can i provide my QOpenGL context and make OpenCL understand it.
      Anyone have an idea how i can enable GLCL sharing using Qt?

      Kind Regards.

      W Offline
      W Offline
      wwolff
      wrote on 7 Apr 2016, 14:35 last edited by
      #2

      @wwolff
      Hi!
      I find out there is a nativeHandle function on the QOpenGLContext object, but it returns a QVariant object.
      I will need typecast this return with the native type context?
      Any example of QVariant typecast?

      Kind Regards.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 7 Apr 2016, 22:15 last edited by
        #3

        Hi,

        Are you looking for qvariant_cast ?

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

        W 1 Reply Last reply 11 Apr 2016, 13:17
        0
        • S SGaist
          7 Apr 2016, 22:15

          Hi,

          Are you looking for qvariant_cast ?

          W Offline
          W Offline
          wwolff
          wrote on 11 Apr 2016, 13:17 last edited by
          #4

          @SGaist
          No, my doubt is becouse the OpenCL function request a native Handle of the window AND the native handle of the context...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 11 Apr 2016, 20:24 last edited by
            #5

            There was a module called QtOpenCL but it was for Qt 4 with this repository being a WIP to make it work with Qt 5.

            In any case, it could be an interesting starting point to help you use OpenCL with Qt

            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
            • W Offline
              W Offline
              wwolff
              wrote on 15 Apr 2016, 00:10 last edited by
              #6

              Hi!
              Yes i know there is a QtOpeCL Module , but what i want is get the native structures for my Rendering OpenGL Window and provide to my own OpenCL classes.
              Everything is running , including the OpenCL Kernels and etc...
              But i´m trying use the OpenGL->OpenCL interoperation to optimize some graphics algorithms and using Visual Studio are working fine too.

              Basically in windows i need 3 structures to enable this interoperation:

              HWND hWnd, 
              HDC     &hDC, 
              HGLRC &hRCe
              

              The First One is the structure create when we call the CreateWindow function to create a window.
              The secondOne is the structure where we store the Device Context retrieved by the GetDC(gHwnd); function.
              And Finally the Last store the OpenGL Context provided by the hRC = wglCreateContext(hDC); function.

              During This days i find out a private library in Qt called QPlatformNativeInterface , but i not found any documentation about it , but it seems i can get this informations from it.

              Any information of how i can get a HWND structure from a QOpenGLWindow and a QGLWidget will be much Appreciated, since from a HWND i can get the DC context and from the OpenGL context i can get the HGLRC.

              Otherwise, i find out too a object in the documentation called QWGLNativeContext defined in the Qt Platform Headers , and it seems this object can be typecasted in the nativeHandle method of the QOpenGLContext class , providing this two structures...

              I will do some more tests , but if this last object works i dont need use the private library to access it.

              Kind Regards.

              1 Reply Last reply
              0
              • W Offline
                W Offline
                wwolff
                wrote on 15 Apr 2016, 00:39 last edited by
                #7

                Hi!

                I find in the documentation the following code:

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

                If everything goes ok, this is exactly what i was looking for!

                Kind Regards.

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  wwolff
                  wrote on 17 Apr 2016, 00:21 last edited by
                  #8

                  Ok, i Almost there...

                  Now i´m having problems with a function called GetDC(HWND) of windows.

                  Basically this function get the device context needed...

                  Everythig compiles , but when Qt compile the main module i receive a Link error becouse it not find the definition of this windows function.

                  Any tip to solved it?

                  Kind Regards.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 17 Apr 2016, 21:20 last edited by
                    #9

                    That's a function from the User32 library. You need to link against it.

                    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

                    8/9

                    17 Apr 2016, 00:21

                    • Login

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