1

here is the scenario: I pass an 3D OpenGL Texture to CUDA by cudaBindTextureToArray transforming it with a non rigid transformation and writed it to a 3d surface and then I want to pass it by a texture to GLSL shader for volume rendering. and GLSL only knows texture id?how I use this 3d surface as an ordinary OpenGL texture?

pseudo code

craete a texture with opengl like this

glTexImage3D(GL_TEXTURE_3D, 0,............);

pass it to cuda

create and fill a surface with

cutilSafeCall(cudaBindSurfaceToArray(volumeTexOut, outTexture->content));
......
..
  cutilSafeCall( cudaMalloc3DArray(&vol->content, &vol->channelDesc, dataSize,  cudaArraySurfaceLoadStore ) );

after transformation,..

  surf3Dwrite(short(voxel), volumeTexOut, sizeof(short)*x1,y1, z1);

and now i want to use this surface as an opengl Texture and pass it to GLSL

4

1 回答 1

4

更新:下面建议的 API 相当陈旧,已被弃用。请参阅 CUDA 的当前图形互操作 API

CUDA OpenGL 互操作(不幸的是)是一种单向 API:要在 CUDA 和 OpenGL 之间进行互操作,您必须使用 OpenGL 分配 GL 代码中所需的所有内存,然后将其绑定到 CUDA 数组或设备指针,以便在 CUDA 中访问它。您不能做相反的事情(使用 CUDA 分配内存并从 OpenGL 访问它)。这适用于由 CUDA 读取或写入的数据。

因此,对于您的输出,您希望在 OpenGL 中分配 3D 纹理,而不是使用cudaMalloc3DArray(). 然后您想使用 调用cudaGraphicsGLRegisterImagecudaGraphicsRegisterFlagsSurfaceLoadStore然后使用 将表面绑定到结果数组cudaBindSurfaceToArray。这在 CUDA 4.2 CUDA C 编程指南的第 3.2.11.1 节中进行了讨论。CUDA 参考指南提供了关于我提到的功能的完整文档。

请注意,表面写入需要计算能力 2.0 或更高的 GPU。

于 2012-08-31T02:46:23.570 回答