dicroce
dicroce

Reputation: 46770

Can CUDA results be stored in an OpenGL accessible texture?

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?

Upvotes: 3

Views: 1995

Answers (2)

a stray cat
a stray cat

Reputation: 396

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().

Upvotes: 5

sjchoi
sjchoi

Reputation: 628

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.

Upvotes: 2

Related Questions