No I tried the follows:
Creating a PBO:
int num_texels = width * height;
int num_values = num_texels;
int size_tex_data = sizeof(GLfloat) * num_values;
void *data = malloc(size_tex_data);
glGenBuffers(1, &depthBuffer);
glBindBuffer(GL_ARRAY_BUFFER, depthBuffer);
glBufferData(GL_ARRAY_BUFFER, size_tex_data, data, GL_DYNAMIC_DRAW);
free(data);
glBindBuffer(GL_ARRAY_BUFFER, 0);
// register this buffer object with CUDA
cutilSafeCall(cudaGraphicsGLRegisterBuffer(&cuda_depthBuffer, depthBuffer, cudaGraphicsMapFlagsNone));
Getting the depthbuffer and map it for CUDA:
glBindBuffer(GL_PIXEL_PACK_BUFFER, depthBuffer);
glReadPixels(0, 0, width, height, GL_DEPTH_COMPONENT, GL_FLOAT, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, depthBuffer);
cutilSafeCall(cudaGraphicsMapResources(1, &cuda_depthBuffer, 0));
size_t num_bytes_depth;
cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&depth_array, &num_bytes_depth, cuda_depthBuffer));
...
cudacall
...
cutilSafeCall(cudaGraphicsUnmapResources(1, &cuda_depthBuffer, 0));
The Kernel puts it into a texture:
texture<float, 2, cudaReadModeElementType> depthTex;
…
struct cudaChannelFormatDesc desc;
cutilSafeCall(cudaBindTextureToArray(depthTex, depth_array));
cutilSafeCall(cudaGetChannelDesc(&desc, depth_array));
This works fine by the first call. At the second I get an error:
at:
cutilSafeCall(cudaGraphicsMapResources(1, &cuda_depthBuffer, 0));
Does someone know why, and can someone give me a hint how I can reach my goal ?
Thanks