How to use OpenGL ES3.0 3DTexture

Hi,
I have a 3D volume with type short. I want to use it as a 3D texture.

------------------I create the 3D texture as follows:----------------------

GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
GLES30.glGenTextures(textures.length, textures, 0);
GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, textures[0]);
 textureUniform = GLES30.glGetUniformLocation(program, "u_Texture");
GLES30.glUniform1i(textureUniform, 0);

GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_S, GLES30.GL_CLAMP_TO_EDGE);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_T, GLES30.GL_CLAMP_TO_EDGE);
GLES30.glTexParameterf(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_WRAP_R, GLES30.GL_CLAMP_TO_EDGE);

GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MIN_FILTER, GLES30.GL_LINEAR);
GLES30.glTexParameteri(GLES30.GL_TEXTURE_3D, GLES30.GL_TEXTURE_MAG_FILTER, GLES30.GL_LINEAR);
  
   
int size = 256*256*256;
ShortBuffer textureData =ByteBuffer.allocateDirect(size*2).order(ByteOrder.nativeOrder()).asShortBuffer();

short[] data = new short[size];

    for(int i = 0; i < size; i++)
         data[i] = 128;
    textureData.put(data).position(0);

GLES30.glTexImage3D(GLES30.GL_TEXTURE_3D, 0, GLES30.GL_R16I, 256, 256, 256, 0, GLES30.GL_RED_INTEGER, GLES30.GL_SHORT, textureData);   

GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, 0);

-----------------then active texture unit in the onDrawFrame -----------------------
   GLES30.glActiveTexture(GLES30.GL_TEXTURE0);
    GLES30.glBindTexture(GLES30.GL_TEXTURE_3D, textures[0]);

------------------------------the fragment shader---------------------

uniform sampler3D u_Texture;

smooth in vec3 v_TexCoord3D;

void main(){

...
  vec4 objectColor = texture(u_Texture, v_TexCoord3D);
...

}

I already test that the v_TexCoord3D is a valid value between [0, 1], but I get 0 for objectColor.r for all fragments.

Any help are very appreciated!

Best,

YL

One thing which I note is that GL_LINEAR filtering isn’t appropriate for an integer format. I don’t know if that will cause it to fail, but the usual failure mode for invalid texture state is that sampling returns zeros.

Also: have you tried calling glGetError to check for reported errors?

Thanks, GCelements, you are right. When I change the filtering type to GL_NEAREST, I got non-zero value.
But the value is very small. Does OpenGL scale the short value to a float value between [0, 1] by dividing 32767?

This variable:

should be an isampler3D for a texture with a signed integer internal format such as GL_R16I. The corresponding texture overload returns an ivec4.

It works.
Many thanks, GClements.