Hey, guys.
I am working on a project involving opengl and cuda.
My problems is how I can convert an opengl texture (id is known) into a cuda array, or cuda texture? So that I can deal with the data with CUDA.
Thanks.
Hey, guys.
I am working on a project involving opengl and cuda.
My problems is how I can convert an opengl texture (id is known) into a cuda array, or cuda texture? So that I can deal with the data with CUDA.
Thanks.
Have you read through the CUDA Programming Guide? There is a whole section on CUDA/OpenGL Interoperability. Basically, you need to register/map an OpenGL buffer object so that CUDA kernels can write to it; if you’re using the driver API, start reading at page 59 (page 67 of the PDF).
I know how to map pbo to cuda array, but I don’t know how I pack texture to pbo. I went through the programming guide, but I didn’t find any tips about that, can you point out it?
There are a number of ways to do this.
PBO = pixel buffer object
FBO = framebuffer object
create PBO with appropriate size
register PBO in cuda
bind GL_PIXEL_PACK_BUFFER to PBO
bind texture to target
perform glGetTexImage on target with data pointer set to 0
unbind GL_PIXEL_PACK_BUFFER to 0
map PBO in cuda
create PBO with appropriate size
register PBO in cuda
create FBO
bind GL_FRAMEBUFFER to FBO
attach texture to COLOR_ATTACHMENT0 of FBO
bind GL_PIXEL_PACK_BUFFER to PBO
perform gReadpixels with data pointer set to 0
unbind GL_PIXEL_PACK_BUFFER to 0
bind GL_FRAMEBUFFER to 0
map PBO in cuda
3 [fastest, experimental CUDA 3.0 beta]
search the 3.0 beta reference manual for
registering:
cudaGraphicsGLRegisterImage
cudaGraphicsUnregisterResource
mapping:
cudaGraphicsMapResources
cudaGraphicsUnmapResources
cudaGraphicsSubResourceGetMappedArray : maps GL texture to cuda array
cudaGraphicsResourceGetMappedPointer: maps PBO to cuda
N.
Thank you very much, Nico.
And, can you tell me how to transfer data from pbo to texture? I used:
glBindTexture(GL_TEXTURE_2D, m_texture->getTexture());
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, m_pboId);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, 0);
And I got an error at:glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_width, m_height, GL_BGRA, GL_UNSIGNED_BYTE, 0);
If you transfer data TO a PBO, you have to bind the PBO to GL_PIXEL_PACK_BUFFER_ARB.
If you want to transfer FROM a PBO (like you’re trying to do) then you have to bind it to GL_PIXEL_UNPACK_BUFFER_ARB.
N.