0

给定 CUDA 图形资源,如何获取像素缓冲区对象并将 RGB 像素放入数组中?有人可以提供一个例子或确认我自己的尝试是否正确吗?现有代码如下所示:

    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));

我添加了以下代码:

    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);
4

1 回答 1

3

你没有。

OpenGL对象是OpenGL对象;CUDA 对象是 CUDA 对象。如果您希望 CUDA 将内容放入 OpenGL 对象中,您必须提供CUDA OpenGL 对象并让它将内容放入其中。这通常使用cudaGraphicsGLRegisterBuffer.

于 2012-08-20T22:07:55.250 回答