title: Instantiating OpenCL cl_mem by casting the handle of OpenCV UMat
body: <p>I was rendering in OpenGL and acquiring a texture, that I had bound to the FrameBuffer, to an OpenCL cl_mem, doing some modifications in OpenCL, and then returning the modified image to the FrameBuffer for display.  I am trying to do the same thing with OpenCV cv::UMat instead, with the only changes shown below. The last line, call to acquire the GLObjects, is where the fault occurs...</p>
  
  <pre><code>UMat cvImage(480,640,CV_8UC4, ACCESS_RW);
  cl_mem clImage = (cl_mem)cvImage.handle(ACCESS_RW);
  --- generate/bind/etc glFrameBuffer
  --- render stuff
  clEnqueueAcquireGLObjects(ocl_queue, 1, &amp;clImage , 0, NULL, NULL); //
  </code></pre>
  
  <p>I was previously instantiating clImage with:</p>
  
  <pre><code>clImage = clCreateFromGLTexture2D(context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, g_fb_tex, &amp;err);
  </code></pre>
  
  <p>and it was working fine. In debug I can see the memory addresses are the same for cvImage and clImage so maybe I haven't created a large enough image size for cvImage? I do not know how the clCreateFromGLTexture2D
  call does it.  Alternatively, I could maintain the way I had it and transfer the cl_mem to UMat after the AcquireGLObjects call.</p>
  
  <p>--------Update 1-------</p>
  
  <p>Based on boiler96's response, I tried the following process which doesn't fault but only gives me a nice blue screen (not a BSOD, but a similar shade in the CV window) and an INVALID_CONTEXT error:</p>
  
  <pre><code>UMat cvImage(480,640,CV_8UC4, cv::ACCESS_RW);
  cl_mem clImage = clCreateFromGLTexture2D(context, CL_MEM_READ_ONLY, GL_TEXTURE_2D, 0, g_fb_tex, &amp;err);
  clEnqueueAcquireGLObjects(ocl_queue, 1, &amp;clImage, 0, NULL, NULL); //
  clEnqueueCopyImageToBuffer(ocl_queue, clImage, (cl_mem)cvImage.handle(ACCESS_RW), origin, region,0,0,NULL,NULL);
  imshow("window", me);
  waitKey(0);
  </code></pre>
  
  <p>More work to do... next attempt will try clCreateFromGLBuffer instead.  Thanks!</p>