CUDA Deviceptr from OpenGL Texture

Hello all,

I need a Cuda Deviceptr from the OpenGL texture, after rendering the texture in the OpenGL.

Now what Iam doing is :-

  1. Register OpenGL buffer with cudaResource Buffer
  2. Map the buffer with cuda
  3. Using cuGraphicsResourceGetMappedPointer I got a cuda devicePtr
  4. After some cuda kernel performance
  5. Unmap the Resource
  6. Render the Texture using OpenGL API
  7. Using glReadPixel I read the texture from GPU to CPU //Here I need an another option

In the last step I take the texture out from GPU to CPU. But I need a Cuda Deviceptr from the OpenGL texture for the further process like scaling using npp.

So, how could I get a Cuda deviceptr from the OpenGL texture???

Any Idea??

run your npp code in step 4.

Or if you prefer, go through the sequence again, up to step 4, then run your npp code.

You cannot get a permanent cuda device pointer to an OpenGL texture. You must go through the interop registration process.

If you want to make a copy of the data, do a cuda device to device copy in step 4. You can then run npp on the copy of the data anytime you want. after that, if you need to display the copy of the data, then run your interop process up to step 4, and then copy the data from your buffer copy back to the interop copy.


I have a similar question and I saw this thread while searching for info.
In my case it is textures used as render targets for the first pass of an OpenGL deferred renderer so they are updated every frame.
If I got it right the interop. process is as follows:


for each frame:
// render to textures (OpenGL)
// cuda work

According to the documentation cudaGraphicsSubResourceGetMappedArray() may return a different cudaArray pointer every time the resource is mapped so it seems that creating -once- cudaTextureObject’s from those arrays is not a viable option since they’ll get (potentially) invalidated every frame.
I see that there’s a cudaMemcpy2DArrayToArray() function which I suppose could be used to copy the data to permanent cudaArrays (haven’t tried it yet) but that still involves doing copies of all texture data every frame.

Is this the only way?


Hello sir,

Thank you for your reply @Robert_Crovella

Here I have multiple textures, each pixel buffer mapped with cuda and convert it into BGRA using cuda kernel and then render it using OPENGL.

So after render the whole texture inside OPENGL , I want to take those textures(one over another) out from OPENGL (inside GPU only) and convert those textures into YUV using npp conversion.

Here I don’t want to use npp conversion multiple times for each textures. I like to do this once for all the textures.

So finally what i want is a CUDA Device Pointer for npp conversion.

Using glReadPixels it works fine, but I don’t want to take the textures out from GPU to CPU.

So my question is How could I get a common device pointer from OpenGL textures.