PDA

View Full Version : Problem with glTexSubImage3D() and GL_TEXTURE_2D_ARRAY



debonair
12-12-2012, 02:05 AM
I am trying to use gltexsubimage3D with the cube. When i use target as GL_texture_2D_array i get some weird o/p, however same code works fine with gl_texture_3d. I am copying my code and screenshots here: texture coordinates:


GLfloat tex_coordinates[]={
0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0,

0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0,

0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0,

0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0,

0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0,

0.0, 0.0,0.0,
1.0, 0.0,1.0,
1.0, 1.0,1.0,
0.0, 1.0,0.0
};
Now, i am using 8*8*8 texture, so that i am applying 8 layers of 2D images to each face of the cube. My texture data is:


for (int i=0; i<size/8; i++)
{
dataRGBA[4*i]=255;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;

sub_data[4*i]=255;
sub_data[4*i+1]=255;
sub_data[4*i+2]=255;
sub_data[4*i+3]=255;

}

for (int i=size/8; i<size/4; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=255;
dataRGBA[4*i+2]=0;
dataRGBA[4*i+3]=255;

sub_data[4*i]=128;
sub_data[4*i+1]=0;
sub_data[4*i+2]=58;
sub_data[4*i+3]=255;



}
for ( int i=size/4; i<(3*size)/8; i++)
{
dataRGBA[4*i]=0;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;

sub_data[4*i]=128;
sub_data[4*i+1]=255;
sub_data[4*i+2]=58;
sub_data[4*i+3]=255;


}

for ( int i=(3*size)/8; i<(4*size)/8;i++)
{
dataRGBA[4*i]=255;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;


sub_data[4*i]=0;
sub_data[4*i+1]=0;
sub_data[4*i+2]=0;
sub_data[4*i+3]=255;


}

for ( int i=(4*size)/8; i<(5*size)/8;i++)
{
dataRGBA[4*i]=56;
dataRGBA[4*i+1]=150;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;

sub_data[4*i]=54;
sub_data[4*i+1]=100;
sub_data[4*i+2]=12;
sub_data[4*i+3]=255;

}

for ( int i=(5*size)/8; i<(6*size)/8; i++)
{
dataRGBA[4*i]=150;
dataRGBA[4*i+1]=255;
dataRGBA[4*i+2]=58;
dataRGBA[4*i+3]=255;

sub_data[4*i]=56;
sub_data[4*i+1]=32;
sub_data[4*i+2]=155;
sub_data[4*i+3]=255;

}

for ( int i=(6*size)/8; i<(7*size)/8; i++)
{
dataRGBA[4*i]=150;
dataRGBA[4*i+1]=0;
dataRGBA[4*i+2]=255;
dataRGBA[4*i+3]=255;

sub_data[4*i]=222;
sub_data[4*i+1]=15;
sub_data[4*i+2]=155;
sub_data[4*i+3]=255;

}
for ( int i=(7*size)/8; i<(8*size)/8; i++)
{
dataRGBA[4*i]=100;
dataRGBA[4*i+1]=128;
dataRGBA[4*i+2]=58;
dataRGBA[4*i+3]=255;

sub_data[4*i]=156;
sub_data[4*i+1]=202;
sub_data[4*i+2]=15;
sub_data[4*i+3]=255;

}
glTexImage3D(*target11, 0, GL_RGBA, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE,dataRGBA);
glTexSubImage3D(*target11,0,0, 0,0,8, 4, 8, GL_RGBA,GL_UNSIGNED_BYTE,sub_data);

glTexParameteri(*target11, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(*target11, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(*target11, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(*target11, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(*target11, GL_TEXTURE_WRAP_R, GL_REPEAT);


GL_TEXTURE_3D:
920
for 2d_array:
921

By removing subimage3D call, 2darray works fine.
code works fine when xoffset=yoffset=0 and width=height=8