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

Method LoadModels

PanzerChasm/client/map_drawer_gl.cpp:1187–1349  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1185}
1186
1187void MapDrawerGL::LoadModels(
1188 const std::vector<Model>& models,
1189 std::vector<ModelGeometry>& out_geometry,
1190 r_PolygonBuffer& out_geometry_data,
1191 AnimationsBuffer& out_animations_buffer,
1192 GLuint& out_textures_array ) const
1193{
1194 ModelsTexturesCorrector textures_corrector;
1195
1196 const Palette& palette= game_resources_->palette;
1197
1198 const unsigned int model_count= models.size();
1199 out_geometry.resize( model_count );
1200
1201 const unsigned int c_texture_size[2]= { 64u, 2048u };
1202 ModelsTexturesPlacement textures_placement;
1203 CalculateModelsTexturesPlacement( models, c_texture_size[1], textures_placement );
1204
1205 const unsigned int c_texels_in_layer= c_texture_size[0u] * c_texture_size[1u];
1206 std::vector<unsigned char> textures_data_rgba( 4u * c_texels_in_layer * textures_placement.layer_count, 0u );
1207
1208 std::vector<unsigned short> indeces;
1209 std::vector<Model::Vertex> vertices;
1210 std::vector<Model::AnimationVertex> animations_vertices;
1211
1212 for( unsigned int m= 0u; m < model_count; m++ )
1213 {
1214 const Model& model= models[m];
1215 ModelGeometry& model_geometry= out_geometry[m];
1216
1217 unsigned int model_texture_height= model.texture_size[1];
1218 if( model.texture_size[1u] > c_texture_size[1u] )
1219 {
1220 Log::Warning( "Model texture height is too big: ", model.texture_size[1u] );
1221 model_texture_height= c_texture_size[1u];
1222 }
1223
1224 // Copy texture into atlas.
1225 unsigned char* const texture_dst=
1226 textures_data_rgba.data() +
1227 4u * textures_placement.textures_placement[m].layer * c_texels_in_layer +
1228 4u * textures_placement.textures_placement[m].y * c_texture_size[0];
1229 for( unsigned int y= 0u; y < model_texture_height; y++ )
1230 for( unsigned int x= 0u; x < model.texture_size[0u]; x++ )
1231 {
1232 const unsigned int i= ( x + y * c_texture_size[0u] ) << 2u;
1233 const unsigned char color_index= model.texture_data[ x + y * model.texture_size[0u] ];
1234 for( unsigned int j= 0u; j < 3u; j++ )
1235 texture_dst[ i + j ]= palette[ color_index * 3u + j ];
1236 texture_dst[ i + 3u ]= color_index == 0u ? 0u : 255u;
1237 }
1238
1239 if( filter_textures_ )
1240 textures_corrector.CorrectModelTexture( model, texture_dst );
1241
1242 if( model_texture_height > 0u )
1243 {
1244 // Fill lower border

Callers

nothing calls this directly

Calls 2

CorrectModelTextureMethod · 0.80

Tested by

no test coverage detected