Вот моя функция, которая готовит текстуру и затем регистрирует ее в CUDA.Может быть, это может вам помочь.
// Create a texture and register it for sharing with CUDA.
void CreateAndRegisterTex(GLuint& tex, cudaGraphicsResource*& resource, u32 w, u32 h) {
u32 i(0);
uchar4* buf((uchar4*)malloc(w * h * sizeof(uchar4)));
glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1); // program works without this but maybe it should be in there?
glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, buf);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glBindTexture(GL_TEXTURE_2D, 0);
free(buf);
glBindTexture(GL_TEXTURE_2D, tex);
// Register this image for sharing with CUDA. cudaGraphicsGLRegisterImage()
// supports all texture formats with 1, 2, or 4 components and an internal
// type of float (e.g. GL_RGBA_FLOAT32) and unnormalized integer (e.g.
// GL_RGBA8UI). It does not currently support normalized integer formats (e.g.
// GL_RGBA8). Please note that since GL_RGBA8UI is an OpenGL 3.0 texture
// format, it can only be written by shaders, not the fixed function pipeline.
cutilSafeCall(cudaGraphicsGLRegisterImage(&resource, tex, GL_TEXTURE_2D,
cudaGraphicsMapFlagsWriteDiscard));
}
Перед вызовом этой функции я звоню:
InitGL(&argc, argv));
g_cuda_device = cutGetMaxGflopsDeviceId();
cudaSetDevice(g_cuda_device);
cudaGLSetGLDevice(g_cuda_device);
При изменении устройства на другое, отличное от значения по умолчанию, я звоню:
GLDeviceInit(g_cuda_device);