Opengl深度缓冲到cuda

我是Opengl的新程序员,

我的目标是将深度缓冲区检索到FBO中,以便能够在不使用glReadpixels的情况下转移到cuda.

这是我已经做过的事情:

void make_Fbo()
{

    glGenFramebuffers(1, &fbo);
    glBindFramebuffer(GL_FRAMEBUFFER, fbo);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                               GL_DEPTH_ATTACHMENT,
                           GL_RENDERBUFFER,
                                           fbo);
    check_gl_error("make_fbo");
}


void make_render_buffer()
{
    glGenRenderbuffers(1, &rb);
    glBindRenderbuffer(GL_RENDERBUFFER, rb);
    glRenderbufferStorage(GL_RENDERBUFFER,
                          GL_DEPTH_COMPONENT,
                               win.width,
                               win.height);
    check_gl_error("make render_buffer");
}

此代码使用正确的深度值创建我的FBO.

现在出现了一个新问题,根据文章“在cuda上使用不规则z缓冲区的快速三角形光栅化”
无法从Cuda访问连接到FBO的深度缓冲区.

这是文章的引用:

Textures or render buffers can be attached onto the depth
attachment point of FBOs to accommodate the depth values. However, as far as
we have tested, they cannot be accessed by CUDA kernels. […]
we managed to use the color attachment points on the FBO. Apparently
in this case we have to write a simple shader program to dump the depth values onto
the color channels of the frame buffer. According to the GLSL specification [KBR06],
the special variable gl_FragCoord

陈述是否仍然正确?
您建议我将深度缓冲区转储到颜色通道?
纹理?

最佳答案 是的,没有.问题是,当他们绑定到FBO时,您无法访问CUDA中的资源.

据我所知,使用cudaGraphicsGLRegisterImage()可以启用cuda访问任何类型的图像数据.因此,如果您使用深度缓冲区作为渲染目标并且未绑定到FBO,则可以使用它.

这是cuda API信息:

https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__OPENGL.html#group__CUDART__OPENGL_1g80d12187ae7590807c7676697d9fe03d

在本文中,他们解释了你应该对深度缓冲区进行循环或双缓冲,或者在CUDA中使用它之前复制数据(但是你或多或少会使整个互操作的想法无效).

http://codekea.com/xLj7d1ya5gD6/modifying-opengl-fbo-texture-attachment-in-cuda.html

点赞