/* gcc -Wall -Wextra -g3 -lglut -lGL test_program.c -o test_program */ #define GL_GLEXT_PROTOTYPES #include #include #include #include #include int main(int argc, char* argv[]) { unsigned char* buf; GLuint tex; glutInitDisplayMode( GLUT_RGBA ); glutInit( &argc, argv ); glutCreateWindow( "glGenerateMipmap crash" ); buf = calloc( 128*128*4*2, 1); memset( buf, 255, 128*128*4*2 ); /* set everything to white */ glGenTextures( 1, &tex ); glBindTexture( GL_TEXTURE_2D_ARRAY, tex ); glTexImage3D( GL_TEXTURE_2D_ARRAY , 0 , GL_COMPRESSED_RGBA , 128 , 128 , 2 , 0 , GL_RGBA , GL_UNSIGNED_BYTE , buf ); glGenerateMipmap( GL_TEXTURE_2D_ARRAY ); glGetTexImage( GL_TEXTURE_2D_ARRAY , 1 /* get the second mipmap layer */ , GL_RGBA , GL_UNSIGNED_BYTE , buf ); int layer_size = 64*64; int row_length = 64; /* Print the pixel value at (12, 12, 0). '(x, y, layer)' * * Prints (255, 255, 255, 255), like expected. */ printf("%d %d %d %d\n" , (int) buf[ 0 + (12 + 12*row_length + 0*layer_size)*4 ] , (int) buf[ 1 + (12 + 12*row_length + 0*layer_size)*4 ] , (int) buf[ 2 + (12 + 12*row_length + 0*layer_size)*4 ] , (int) buf[ 3 + (12 + 12*row_length + 0*layer_size)*4 ] ); /* Print the pixel value at (12, 12, 1). * * This one returns (0, 0, 0, 0), even though I'd expect it returns * (255, 255, 255, 255) (or at least close as this is a compressed, * lossy format(?)). * * This returns (255, 255, 255, 255) if we use non-compressed internal * format or the nVidia proprietary drivers. */ printf("%d %d %d %d\n" , (int) buf[ 0 + (12 + 12*row_length + 1*layer_size)*4 ] , (int) buf[ 1 + (12 + 12*row_length + 1*layer_size)*4 ] , (int) buf[ 2 + (12 + 12*row_length + 1*layer_size)*4 ] , (int) buf[ 3 + (12 + 12*row_length + 1*layer_size)*4 ] ); return 0; }