Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Problem with glTexSubImage3D() and GL_TEXTURE_2D_ARRAY

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    190

    Problem with glTexSubImage3D() and GL_TEXTURE_2D_ARRAY

    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
    };
    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);

    GL_TEXTURE_3D:
    Click image for larger version. 

Name:	Texture_Formats_702465_1.png 
Views:	46 
Size:	3.5 KB 
ID:	920
    for 2d_array:
    Click image for larger version. 

Name:	Texture_Formats_702465.png 
Views:	46 
Size:	8.1 KB 
ID:	921

    By removing subimage3D call, 2darray works fine.
    code works fine when xoffset=yoffset=0 and width=height=8
    Last edited by debonair; 12-13-2012 at 02:05 AM. Reason: corrected subdata

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •