I have an image in a CUDA pointer object thingy (or whatever the correct lingo is) and I want to either use it as an OpenGL texture or copy it to a texture but mapping a texture gives me some strange “cudaArray” thing that I cant do anything with, I have tried various methods of copying the data to it but nothing works.
So how do I copy data from CUDA to a mapped OpenGL texture? thanks.
I setup the texture like this: glGenTextures(1, &m_iTexture); glBindTexture(GL_TEXTURE_2D, m_iTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, nImageWidth, nImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, whiteimg); cudaGraphicsGLRegisterImage(&resource, m_iTexture, GL_TEXTURE_2D, cudaGraphicsRegisterFlagsNone);
texture parameters omitted
and attempt to copy to it like this every frame: cudaGraphicsMapResources(1, &resource); cudaArray* texarray; cudaGraphicsSubResourceGetMappedArray(&texarray, resource, 0, 0); auto width = 0; auto height = 0; GrabFrame(&width, &height); CopyFrame(texarray); cudaGraphicsUnmapResources(1, &resource);
where CopyFrame is this: cudaMemcpy2DToArray(texarray, 0, 0, reinterpret_cast<void*>(pDevGrabBuffer), frameGrabInfo.dwWidth*4, frameGrabInfo.dwWidth*4, frameGrabInfo.dwHeight, cudaMemcpyDeviceToDevice);