I did not have any success binding the depth buffer itself. One work-around for this is to render the depth pixel value into a color buffer and bind the color buffer as you do. You will need to write your own shader to accomplish this.
Cuda Render Buffer Interop for depth component
-
06-03-2022 - |
Question
What I am trying to do is to use OpenGL to perform some rendering, then use CUDA to perform some read-only post-processing (computations) directly on the rendered RGB and depth components, without copying the data to a PBO.
To do this, I create a FBO and I attach two RBO's to it (one for the RGBA and one for the DEPTH).
Then, I call cudaGraphicsGLRegisterImage for each RBO with GL_RENDERBUFFER as parameter. For the color RBO cudaGraphicsGLRegisterImage returns cudaSuccess, but for the depth RBO, I receive a cudaErrorInvalidValue.
I've read somewhere in the forums that CUDA render buffer interop for the depth component is not currently supported by nVidia, though it is well present in the documentation.
I am using CUDA Toolkit 5.0 and I have a Quadro 2000 card.
Have someone succeeded to do this, and how ?
Here are some code extracts :
glGenRenderbuffers(1, &rbo_color);
glBindRenderbuffer(GL_RENDERBUFFER, rbo_color);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA, WIDTH, HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (cudaGraphicsGLRegisterImage(&resource_color, rbo_color, GL_RENDERBUFFER, cudaGraphicsMapFlagsReadOnly) != cudaSuccess)
fprintf(stderr, "Error in registering rbo color with cuda\n");
glGenRenderbuffers(1, &rbo_depth);
glBindRenderbuffer(GL_RENDERBUFFER, rbo_depth);
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT32F, WIDTH, HEIGHT);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
if (cudaGraphicsGLRegisterImage(&resource_depth, rbo_depth, GL_RENDERBUFFER, cudaGraphicsMapFlagsReadOnly) != cudaSuccess)
fprintf(stderr, "Error in registering rbo depth with cuda\n");
Solution