Sign in to follow this  

glTexSubImage3D() with GL_TEXTURE_2D_ARRAY

This topic is 1861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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:
[code]
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
};
[/code]
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
[code]
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);
[/code]
GL_TEXTURE_3D
[attachment=12754:YT8o9.png]

GL_TEXTURE_2D_ARRAY
[attachment=12755:R0OUO.png]

I tried changing filters. By removing subimage3D call, 2darray works fine.
code works fine when xoffset=yoffset=0 and width=height=8 Edited by rgc183

Share this post


Link to post
Share on other sites

This topic is 1861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this