How can I obtain a pixel buffer object and get the RGB pixels into an array, given a CUDA graphics resource? Could somebody provide an example or confirm if my own attempt is correct? The existing code looks like this:
cutilSafeCall(cudaGraphicsMapResources(1, &render_cuda_pbo_resource, stream));
uchar4 *d_output;
size_t num_bytes;
cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&d_output, &num_bytes, render_cuda_pbo_resource));
I have added the following code:
glBindTexture (GL_TEXTURE_2D, renderTex);
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, 0);
glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0);
glBegin(GL_QUADS);
glTexCoord2f (0.0, 0.0);
glVertex3f (-1.0, -1.0, 0.0);
glTexCoord2f (1.0, 0.0);
glVertex3f (1.0, -1.0, 0.0);
glTexCoord2f (1.0, 1.0);
glVertex3f (1.0, 1.0, 0.0);
glTexCoord2f (0.0, 1.0);
glVertex3f (-1.0, 1.0, 0.0);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glReadPixels(10, 10, width, height, GL_BGRA, GL_UNSIGNED_BYTE, data);
You don’t.
OpenGL objects are OpenGL objects; CUDA objects are CUDA objects. If you want CUDA to put stuff into OpenGL objects, you must give CUDA OpenGL objects and have it put the stuff into them. This is generally done with
cudaGraphicsGLRegisterBuffer.