3
votes

I use CUDA surface Reference to write and read OpenGL 3D Texture fllowing this post Write to 3D OpenGL textures in CUDA ... .

There is a problem confused me. For example,this function

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY, volDim_.x, volDim_.y
        , volDim_.z, 0, GL_LUMINANCE, getVolumeTypeGL(vol), vol->getData());

the third parameter is internal format.

In CUDA kernel,I need write or read the texture,like below code,

ElementType v;
surf3Dread(&v,surfaceRef,x*sizeof(ElementType),y,z);
surf3Dwrite(&v,surfaceRef,x*sizeof(ElementType),y,z);

I don't know how to match Internal Format with ElementType. Example

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY, volDim_.x, volDim_.y
    , volDim_.z, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, vol->getData());

In host memory,the type of volume data type is unsigned char. Which ElementType shuld I choose?

uchar4 or uchar ,or float

My some code could find in here My GitHub

UPDATE:

I have solved this problem.

GL_RGBA32F ---- float4

GL_RGBA ---- uchar4

GL_INTENSITY -- uchar

1
Please add your solution as an answer to your question, rather than an EDIT. It is perfectly OK to answer your own question, and you will also be able to eventually accept the answer. This is how questions are marked as solved on Stack Overflow, rather than by editing the question title. Please don't do it that way. Thankstalonmies
@talonmies Thanks,I will do that soon!FeizCNU
Thank you for posting an answertalonmies

1 Answers

2
votes

If the internal format of glTeximage3D is GL_INTENSITY, the element type of surf3Dread or surf3Dwrite is unsigned char. GL_RGBA32F matches float4 and GL_RGBA matches uchar4.