Question

I'm trying to perform combined rendering with OpenGL for polygonal rendering and CUDA for volume rendering. My idea is to render the OpenGL scene into a framebuffer, then use that color and depth buffer as input to my CUDA renderer, using it in the same way as OpenGL does, so I get proper alpha and depth compositing.

However, I'm running into a problem. When I call:

glGenTextures(1, &m_tex_color);
glGenTextures(1, &m_tex_depth);

glBindTexture(GL_TEXTURE_2D, m_tex_color);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, m_iWidth, m_iHeight, 0,
             GL_RGBA, GL_UNSIGNED_BYTE, 0);
glBindTexture(GL_TEXTURE_2D, m_tex_depth);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, m_iWidth, m_iHeight, 0,  
             GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
glBindTexture(GL_TEXTURE_2D, 0);

glGenFramebuffersEXT(1, &m_fbo);
glBindFramebuffer( GL_FRAMEBUFFER, m_fbo);

glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
                       GL_TEXTURE_2D, m_tex_color, 0 );
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
                       GL_TEXTURE_2D, m_tex_depth, 0 );
cudaError_t b;
b = cudaGraphicsGLRegisterImage(&m_cuda_color_resource, m_tex_color,
                                GL_TEXTURE_2D, cudaGraphicsMapFlagsNone);
printf("%s",  cudaGetErrorString(b));
b = cudaGraphicsGLRegisterImage(&m_cuda_depth_resource, m_tex_depth,
                                GL_TEXTURE_2D, cudaGraphicsMapFlagsNone);
printf("%s",  cudaGetErrorString(b));

I get no error on the first cudaGraphicsGLRegisterImage, but an "invalid argument" error on the second. Does CUDA 3.2 not support registering depth component textures? Does 4.0 (when it comes out)? Is there another way to approach this that I'm missing?

Was it helpful?

Solution

CUDA GL texture interop does not currently support GL_DEPTH_COMPONENT (as of CUDA 4.1).

This was unfortunately overlooked in the CUDA documentation. A documentation bug has been filed to rectify this.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top