I am using teximage3D with gl_texture_3D and gl_texture_2D_array as a targets.
I am creating 4 layers of colors and applying that on a sphere. So i am expecting that it will apply 4 layers on sphere equally.
But for GL_TEXTURE_3D, it repeats all the layers 2 times. whereas for gl_texture_2D_array it applies those layers only once as per expected.
int w = 4, h = 4, d = 4;
size_t size = w * h * d;
*format=GL_RGBA;
GLubyte *dataRGBA=new GLubyte[4*size];
for (int i=0; i<size/4; i++)
{
dataRGBA[4*i]=200;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;
}
for (int i=size/4; i<size/2; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=255;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;
}
for ( int i=size/2; i<(3*size)/4; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;
}
for ( int i=(3*size)/4; i<size; i++)
{
dataRGBA[4*i]=255;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;
}
glGenTextures(1,&id);
glBindTexture(*target11, id);
glTexParameteri(*target11, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// when this texture needs to be magnified to fit on a big polygon, use linear interpolation of the texels to determine the color
glTexParameteri(*target11, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// we want the texture to repeat over the S axis, so if we specify coordinates out of range we still get textured.
glTexParameteri(*target11, GL_TEXTURE_WRAP_S, GL_REPEAT);
// same as above for T axis
glTexParameteri(*target11, GL_TEXTURE_WRAP_T, GL_REPEAT);
// same as above for R axis
glTexParameteri(*target11, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexImage3D(*target11, 0, *format, w, h, d, 0, GL_RGBA, GL_UNSIGNED_BYTE, dataRGBA);
I believe that the issue is that a 2d texture array uses integers as texture indices, while a 3d texture scales the R axis 0-1 like the S and T axes.