2 Replies Latest reply on Jun 3, 2015 10:25 AM by adams

    OpenGL interop on CPU device type

    adams

      This might be a silly question, but is it possible to write to GPU texture with OpenCL context created from device type CL_DEVICE_TYPE_CPU? The version I am targetting is 1.2.

       

      If the answer is no, is there any fast way I can copy image from OpenCL memeory to OpenGL texture in this scenario? Or am I forced to use clEnqueueReadImage and then glTexImage2D every frame?

        • Re: OpenGL interop on CPU device type
          dipak

          I think, it should work as long as the CPU device supports cl_khr_gl_sharing extension and its in the list of all CL devices which may be associated with the specified OpenGL context queried using clGetGLContextInfoKHR . You may try following workflow:

           

          // Say, you have declared the context property as below:

           

          cl_context_properties props[] =

          {

          //OpenCL platform

            CL_CONTEXT_PLATFORM, (cl_context_properties)   platform,

          //OpenGL context

                CL_GL_CONTEXT_KHR,   (cl_context_properties)   hRC,

          //HDC used to create the OpenGL context

                CL_WGL_HDC_KHR,     (cl_context_properties)   hDC,

                0

              };

          ...

           

          // Get the list of all CL devices which may be associated with the specified OpenGL context.

          clGetGLContextInfoKHR(props, CL_DEVICES_FOR_GL_CONTEXT_KHR, listSize, deviceList, NULL));

           

           

          // Check if the "deviceList" contains the CPU device and if so, find the CPU device from the "deviceList" using clGetDeviceInfo(..,CL_DEVICE_TYPE, …)

          // Say, cpu device id is cpuDeviceId

           

          // Then create a context only for CPU device

          context = clCreateContext(props, 1, &cpuDeviceId, 0, 0, NULL);

           

          // Now, its possible to share the GL texture or buffer

           

          Regards,

          1 of 1 people found this helpful