I am creating an OpenGL texture like this:
glGenTextures( 1, &boardTex );
glBindTexture( GL_TEXTURE_2D, boardTex );
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_RGBA32F, width, height, 0, GL_RGBA, GL_FLOAT, NULL);
I get a handle at board so I assume the texture’s been successfully created. I want to share this texture with CUDA so I register and map the resource:
cudaGLSetGLDevice(0);
cudaGraphicsGLRegisterImage( &boardImage, boardTex, GL_TEXTURE_2D, cudaGraphicsMapFlagsNone );
cudaGraphicsMapResources( 1, &boardImage, 0 );
Then I try to get the mapped pointer like this:
float4* mappedPointer;
size_t mappedSize;
cudaGraphicsResourceGetMappedPointer( (void**)&mappedPointer, &mappedSize, boardImage );
Unfortunately this call returns an error and refuses to work. I made sure the texture wasn’t bound in OpenGL context just in case. Still not working. cudaGetErrorString yields “unknown error” so I’m pretty stuck here. I’d appreciate any ideas.
Okay, I found this out myself:
cudaGraphicsSubResourceGetMappedArray (&array, resource, 0, 0);returns acudaArrayto work with. I have yet to wrap my mind around howcudaArrays work (and I might end up using PBOs) but at least it’s not crashing.Edit:
From the CUDA Reference Guide entry for
cudaGraphicsResourceGetMappedPointer():From the CUDA Reference Guide entry for
cudaGraphicsSubResourceGetMappedArray():In other words, use GetMappedPointer for mapped buffer objects. Use GetMappedArray for mapped texture objects.