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