views:

256

answers:

2

Can CUDA be used to generate OpenGL textures? I know it can be done by reading the CUDA results back into system memory, and then loading that into a texture... But I'd like to find a way to save this copy... Can CUDA be used to generate textures?

+2  A: 

Yes, CUDA has API functions to allow for OpenGL Interoperability

Use cudaGLRegisterBufferObject(GLuint bufObj) to register to CUDA and then use cudaGLMapBufferObject( void ** devPtr, GLuint bufObj) to get the device memory pointer to manipulate the buffer in your CUDA kernal.

Once done, you unmap cudaGLUnmapBufferObject(GLuint bufObj) and then display.

Full explanation is in the CUDA Programming Guide that you download in the CUDA Toolkit.

sjchoi
+2  A: 

Sort of. You can't write directly to textures from a kernel, but you can do a copy of the results from your kernel to the texture's mapped cudaArray without having to copy it back to system memory. Look into cudaGraphicsGLRegisterImage(), cudaGraphicsMapResources() and cudaGraphicsSubResourceGetMappedArray().

a stray cat
Also note that these are the new 3.0 versions. The other GL - Dx will be deprecated
fabrizioM