MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / LoadWallsTextures

Method LoadWallsTextures

PanzerChasm/client/map_drawer_soft.cpp:741–855  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

739}
740
741void MapDrawerSoft::LoadWallsTextures( const MapData& map_data )
742{
743 const PaletteTransformed& palette= *rendering_context_.palette_transformed;
744
745 std::vector<unsigned char> file_content;
746
747 for( unsigned int i= 0u; i < MapData::c_max_walls_textures; i++ )
748 {
749 WallTexture& out_texture= wall_textures_[i];
750 out_texture.size[0]= out_texture.size[1]= 0u;
751
752 const char* const texture_file_path= map_data.walls_textures[i].file_path;
753 if( texture_file_path[0] == '\n' )
754 continue;
755
756 game_resources_->vfs->ReadFile( texture_file_path, file_content );
757 if( file_content.empty() )
758 continue;
759
760 const CelTextureHeader& header= *reinterpret_cast<const CelTextureHeader*>( file_content.data() );
761 if( header.size[0] % ( g_max_wall_texture_width / 16u ) != 0u ||
762 header.size[1] < g_wall_texture_height )
763 {
764 Log::Warning( "Invalid wall texture size: ", header.size[0], "x", header.size[1] );
765 continue;
766 }
767
768 out_texture.size[0]= header.size[0];
769 out_texture.size[1]= g_wall_texture_height;
770
771 const unsigned int pixel_count= header.size[0] * g_wall_texture_height;
772 const unsigned int storage_size= pixel_count + pixel_count / 4u + pixel_count / 16u + pixel_count / 64u;
773 const unsigned char* const src= file_content.data() + sizeof(CelTextureHeader);
774
775 out_texture.data.resize( storage_size );
776 out_texture.mip0= out_texture.data.data();
777 out_texture.mips[0]= out_texture.mip0 + pixel_count;
778 out_texture.mips[1]= out_texture.mips[0] + pixel_count / 4u;
779 out_texture.mips[2]= out_texture.mips[1] + pixel_count / 16u;
780
781 for( unsigned int j= 0u; j < pixel_count; j++ )
782 out_texture.mip0[j]= palette[ src[j] ];
783 BuildMipAlphaCorrected( out_texture.mip0 , out_texture.size[0] , out_texture.size[1] , out_texture.mips[0] );
784 BuildMipAlphaCorrected( out_texture.mips[0], out_texture.size[0] / 2u, out_texture.size[1] / 2u, out_texture.mips[1] );
785 BuildMipAlphaCorrected( out_texture.mips[1], out_texture.size[0] / 4u, out_texture.size[1] / 4u, out_texture.mips[2] );
786 MakeBinaryAlpha( out_texture.mips[0], pixel_count / 4u );
787 MakeBinaryAlpha( out_texture.mips[1], pixel_count / 16u );
788 MakeBinaryAlpha( out_texture.mips[2], pixel_count / 64u );
789
790 // Calculate top and bottom alpha-rejected texture rows.
791 out_texture.full_alpha_row[0]= 0u;
792 out_texture.full_alpha_row[1]= g_wall_texture_height;
793
794 bool is_only_alpha= false;
795 for( unsigned int y= 0u; y < g_wall_texture_height; y++ )
796 {
797 bool is_full_alpha= true;
798 for( unsigned int x= 0u; x < header.size[0]; x++ )

Callers

nothing calls this directly

Calls 3

BuildMipAlphaCorrectedFunction · 0.85
MakeBinaryAlphaFunction · 0.85
ReadFileMethod · 0.80

Tested by

no test coverage detected