title: Sharing texture between OpenGL and CUDA
body: <p>I am sharing data between OpenGL and CUDA as follows:</p>
  
  <pre><code>GLuint buffer;
  glGenBuffers(1, &amp;buffer);
  // Some image is bound to this texture buffer at some point.
  ...
  cudaGraphicsResource_t cgr;
  checkCudaErrors(cudaGraphicsGLRegisterBuffer(&amp;cgr, 
                  buffer, cudaGraphicsRegisterFlagsNone));
  checkCudaErrors(cudaGraphicsMapResources(1, &amp;cgr, 0));
  uchar4 * device_ptr = 0;
  size_t num_bytes;
  checkCudaErrors(cudaGraphicsResourceGetMappedPointer(
                 (void **)&amp;device_ptr, &amp;num_bytes, cgr));
  </code></pre>
  
  <p>This works fine and device_ptr is not a pointer to my CUDA memory. Now, at some point I want to resample this image using bilinear interpolation. It seems that the preferred way to do this in CUDA is map the device data to CUDA texture memory and then perform the interpolation using the tex2D calls.</p>
  
  <p>Now, my question is that the imaging data already exists in OpenGL texture memory and I wonder if there is a way to avoid calling cudaBindTexture2D again and somehow use the OpenGL texture from within CUDA for this interpolation?</p>