Load unwrapped cube map.
| 880 | |
| 881 | // Load unwrapped cube map. |
| 882 | static bool LoadCubeMap( QDataStream & s, const DDSHeader & header, QImage & img ) |
| 883 | { |
| 884 | // Create dst image. |
| 885 | #if CUBE_LAYOUT == HORIZONTAL |
| 886 | img = QImage( 4 * header.width, 3 * header.height, QImage::Format_RGB32 ); |
| 887 | #elif CUBE_LAYOUT == VERTICAL |
| 888 | img = QImage( 3 * header.width, 4 * header.height, QImage::Format_RGB32 ); |
| 889 | #endif |
| 890 | |
| 891 | DDSType type = GetType( header ); |
| 892 | |
| 893 | // Enable alpha buffer for transparent or DDS images. |
| 894 | if( HasAlpha( header ) || type >= DDS_DXT1 ) { |
| 895 | img = img.convertToFormat( QImage::Format_ARGB32 ); |
| 896 | } |
| 897 | |
| 898 | // Select texture loader. |
| 899 | TextureLoader loader = GetTextureLoader( type ); |
| 900 | if( loader == NULL ) { |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | // Clear background. |
| 905 | img.fill( 0 ); |
| 906 | |
| 907 | // Create face image. |
| 908 | QImage face(header.width, header.height, QImage::Format_RGB32); |
| 909 | |
| 910 | int offset = s.device()->pos(); |
| 911 | int size = FaceOffset( header ); |
| 912 | |
| 913 | for( int i = 0; i < 6; i++ ) { |
| 914 | |
| 915 | if( !(header.caps.caps2 & face_flags[i]) ) { |
| 916 | // Skip face. |
| 917 | continue; |
| 918 | } |
| 919 | |
| 920 | // Seek device. |
| 921 | s.device()->seek( offset ); |
| 922 | offset += size; |
| 923 | |
| 924 | // Load face from stream. |
| 925 | if( !loader( s, header, face ) ) { |
| 926 | return false; |
| 927 | } |
| 928 | |
| 929 | #if CUBE_LAYOUT == VERTICAL |
| 930 | if( i == 5 ) { |
| 931 | face = face.mirror(true, true); |
| 932 | } |
| 933 | #endif |
| 934 | |
| 935 | // Compute face offsets. |
| 936 | int offset_x = face_offset[i][0] * header.width; |
| 937 | int offset_y = face_offset[i][1] * header.height; |
| 938 | |
| 939 | // Copy face on the image. |
no test coverage detected