Hello everybody !
I am new with CUDA, and maybe that’s why I fail to make CUDA processing textures which are stored by openGL.
What I want to do:
Two textures, which are also used by openGL are with equal rights. The first is used as a input to the CUDA process the ohter as output. The resolution and the Format are the same. But I want the setting, that you can switch the role of these textures anytime.
Firstly I tried to create a texture in openGL with a corresponding CUDA-Resource as follow:
void createTexture2D(GLuint *textureName, struct cudaGraphicsResource **texture_res,
unsigned int texture_res_flag)
{
if(textureName)
{
glGenTextures(1, textureName);
glBindTexture(GL_TEXTURE_2D, *textureName);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mesh_width, mesh_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, mesh_width, mesh_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
//glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA16F_ARB, mesh_width, mesh_height, 0, GL_ALPHA, GL_FLOAT, 0);
//GL_TEXTURE_3D, 0,GL_RGBA32F, 16, 16,16, 0, GL_RGBA, GL_FLOAT,data
glBindTexture(GL_TEXTURE_2D, *textureName);
cutilSafeCall(cudaGraphicsGLRegisterImage(texture_res, *textureName, GL_TEXTURE_2D, texture_res_flag));
}
else
{
printf("Fehler in Datei: %s Zeile %s : Textur konnte nicht richtig initialisert werde.", __FILE__, __LINE__);
}
}
As far as good, when I trie to use this cuda-resource with:
cutilSafeCall(cudaGraphicsResourceGetMappedPointer((void **)&dptrTexA, &num_bytesTexA,
cuda_texture_resourceA));
I got a runtime Error:
So I look at the others CUDA Samples (postProcessGL ,recursiveGaussian, …) but I can hardly understand everything and I am of the opinion that they are too complex for my “simple” Problem.
Is there anyone who can give me a hint how I can go forward (I am trying since days but without any success)?
The Format of the textures should be GL_FLOAT if possible.
Thanks a lot !
Many regards
Matthias
PS. Am running a GeForce 460GT on Windows 7 if this matters.