| 1349 | } |
| 1350 | |
| 1351 | void MapDrawerGL::LoadMonstersModels() |
| 1352 | { |
| 1353 | ModelsTexturesCorrector textures_corrector; |
| 1354 | |
| 1355 | const std::vector<Model>& in_models= game_resources_->monsters_models; |
| 1356 | const Palette& palette= game_resources_->palette; |
| 1357 | |
| 1358 | monsters_models_.resize( in_models.size() ); |
| 1359 | |
| 1360 | std::vector<unsigned char> texture_data_rgba; |
| 1361 | |
| 1362 | std::vector<unsigned short> indeces; |
| 1363 | std::vector<Model::Vertex> vertices; |
| 1364 | std::vector<Model::AnimationVertex> animations_vertices; |
| 1365 | |
| 1366 | // TODO - load gibs from models. |
| 1367 | for( unsigned int m= 0u; m < monsters_models_.size(); m++ ) |
| 1368 | { |
| 1369 | const Model& in_model= in_models[m]; |
| 1370 | MonsterModel& out_model= monsters_models_[m]; |
| 1371 | |
| 1372 | // Prepare texture. |
| 1373 | texture_data_rgba.clear(); |
| 1374 | texture_data_rgba.resize( in_model.texture_data.size() * 4u ); |
| 1375 | for( unsigned int i= 0u; i < in_model.texture_data.size(); i++ ) |
| 1376 | { |
| 1377 | const unsigned char color_index= in_model.texture_data[i]; |
| 1378 | unsigned char* const out_pixel= texture_data_rgba.data() + i * 4u; |
| 1379 | for( unsigned int j= 0u; j < 3u; j++ ) |
| 1380 | out_pixel[ j ]= palette[ color_index * 3u + j ]; |
| 1381 | out_pixel[ 3u ]= color_index == 0u ? 0u : 255u; |
| 1382 | } |
| 1383 | |
| 1384 | if( filter_textures_ ) |
| 1385 | textures_corrector.CorrectModelTexture( in_model, texture_data_rgba.data() ); |
| 1386 | |
| 1387 | out_model.texture= |
| 1388 | r_Texture( |
| 1389 | r_Texture::PixelFormat::RGBA8, |
| 1390 | in_model.texture_size[0], in_model.texture_size[1], |
| 1391 | texture_data_rgba.data() ); |
| 1392 | |
| 1393 | if( filter_textures_ ) |
| 1394 | out_model.texture.SetFiltration( r_Texture::Filtration::LinearMipmapLinear, r_Texture::Filtration::Linear ); |
| 1395 | else |
| 1396 | out_model.texture.SetFiltration( r_Texture::Filtration::NearestMipmapLinear, r_Texture::Filtration::Nearest ); |
| 1397 | out_model.texture.BuildMips(); |
| 1398 | |
| 1399 | const auto prepare_geometry= |
| 1400 | [&]( const Submodel& submodel, ModelGeometry& model_geometry ) |
| 1401 | { |
| 1402 | // Copy vertices. |
| 1403 | const unsigned int first_vertex_index= vertices.size(); |
| 1404 | vertices.resize( vertices.size() + submodel.vertices.size() ); |
| 1405 | std::memcpy( |
| 1406 | vertices.data() + first_vertex_index, |
| 1407 | submodel.vertices.data(), |
| 1408 | submodel.vertices.size() * sizeof(Model::Vertex) ); |
nothing calls this directly
no test coverage detected