| 890 | } |
| 891 | |
| 892 | void MapDrawerGL::LoadWallsTextures( const MapData& map_data ) |
| 893 | { |
| 894 | Log::Info( "Loading walls textures for map" ); |
| 895 | |
| 896 | const Palette& palette= game_resources_->palette; |
| 897 | |
| 898 | Vfs::FileContent texture_file; |
| 899 | |
| 900 | glBindTexture( GL_TEXTURE_2D_ARRAY, wall_textures_array_id_ ); |
| 901 | glTexImage3D( |
| 902 | GL_TEXTURE_2D_ARRAY, 0, GL_RGBA8, |
| 903 | g_max_wall_texture_width, g_wall_texture_height, MapData::c_max_walls_textures, |
| 904 | 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr ); |
| 905 | |
| 906 | for( unsigned int t= 0u; t < MapData::c_max_walls_textures; t++ ) |
| 907 | { |
| 908 | if( map_data.walls_textures[t].file_path[0] == '\0' ) |
| 909 | continue; |
| 910 | |
| 911 | game_resources_->vfs->ReadFile( map_data.walls_textures[t].file_path, texture_file ); |
| 912 | if( texture_file.empty() ) |
| 913 | continue; |
| 914 | |
| 915 | unsigned char texture_data[ g_max_wall_texture_width * g_wall_texture_height * 4u ]; |
| 916 | |
| 917 | unsigned short src_width, src_height; |
| 918 | std::memcpy( &src_width , texture_file.data() + 0x2u, sizeof(unsigned short) ); |
| 919 | std::memcpy( &src_height, texture_file.data() + 0x4u, sizeof(unsigned short) ); |
| 920 | |
| 921 | if( g_max_wall_texture_width / src_width * src_width != g_max_wall_texture_width || |
| 922 | src_height < g_wall_texture_height ) |
| 923 | { |
| 924 | Log::Warning( "Invalid wall texture size: ", src_width, "x", src_height ); |
| 925 | continue; |
| 926 | } |
| 927 | |
| 928 | const unsigned char* const src= texture_file.data() + 0x320u; |
| 929 | |
| 930 | for( unsigned int y= 0u; y < g_wall_texture_height; y++ ) |
| 931 | { |
| 932 | const unsigned int y_flipped= g_wall_texture_height - 1u - y; |
| 933 | |
| 934 | for( unsigned int x= 0u; x < src_width; x++ ) |
| 935 | { |
| 936 | const unsigned int color_index= src[ x + y_flipped * src_width ]; |
| 937 | const unsigned int i= ( x + y * g_max_wall_texture_width ) << 2; |
| 938 | |
| 939 | for( unsigned int j= 0u; j < 3u; j++ ) |
| 940 | texture_data[ i + j ]= palette[ color_index * 3u + j ]; |
| 941 | |
| 942 | texture_data[ i + 3u ]= color_index == 255u ? 0u : 255u; |
| 943 | } |
| 944 | |
| 945 | const unsigned int repeats= g_max_wall_texture_width / src_width; |
| 946 | unsigned char* const line= texture_data + g_max_wall_texture_width * 4u * y; |
| 947 | for( unsigned int r= 1u; r < repeats; r++ ) |
| 948 | std::memcpy( |
| 949 | line + r * src_width * 4u, |
nothing calls this directly
no test coverage detected