Hi all,
I am confused about the storing mechanism of textures. Here is my understanding, please tell me if I am correct.
According to the documentation http://docs.gl/gl4/glTexImage2D
glTexImage2D()
stores each element as four floats. For example, I first load a single-channel image in cpu memory:
uint16_t* pGrayscale = new uint16_t[nPixels];
fread_s((void*)pGrayscale , nPixels * sizeof(uint16_t), sizeof(uint16_t), nPixels , datafile);
then write it to a texture:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RED, width, height, 0, GL_RED, GL_UNSIGNED_SHORT, (void*)pGrayscale );
and it should be the same as
glTexImage2D(GL_TEXTURE_2D, 0, GL_R32F, width, height, 0, GL_RED, GL_UNSIGNED_SHORT, (void*)pGrayscale );
then Opengl allocates a gpu memory with the size 4 * nPixels * sizeof (float)
. However, I followed the Cuda-Opengl interoperatibility guide https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#opengl-interoperability
, and got a cudaArray pointer to this gpu memory, I FAILED to copy this from device to host using cudaMemcpyFromArray as usual. So I think my understanding may be wrong.
Best regards