Radium Engine  1.5.0
MaterialConverters.cpp
1 #include <Engine/Data/MaterialConverters.hpp>
2 
3 #include <Core/Utils/Log.hpp>
4 
5 #include <map>
6 
10 
11 namespace Ra {
12 namespace Engine {
13 namespace Data {
14 using namespace Core::Utils; // log
15 
19 
20 namespace EngineMaterialConverters {
22 static std::map<std::string, std::function<RadiumMaterialPtr( AssetMaterialPtr )>>
24 
25 bool registerMaterialConverter( const std::string& name, ConverterFunction converter ) {
26  auto result = MaterialConverterRegistry.insert( { name, converter } );
27  return result.second;
28 }
29 
30 bool removeMaterialConverter( const std::string& name ) {
31  std::size_t removed = MaterialConverterRegistry.erase( name );
32  return ( removed == 1 );
33 }
34 
35 std::pair<bool, ConverterFunction> getMaterialConverter( const std::string& name ) {
36  auto search = MaterialConverterRegistry.find( name );
37  if ( search != MaterialConverterRegistry.end() ) { return { true, search->second }; }
38  auto result = std::make_pair( false, [name]( AssetMaterialPtr ) -> RadiumMaterialPtr {
39  LOG( logERROR ) << "Required material converter " << name << " not found!";
40  return nullptr;
41  } );
42  return result;
43 }
44 
45 bool cleanup() {
46  MaterialConverterRegistry.clear();
47  return true;
48 }
49 
50 } // namespace EngineMaterialConverters
51 } // namespace Data
52 } // namespace Engine
53 } // namespace Ra
represent material data loaded by a file loader. Material data must be identified by a unique name....
bool removeMaterialConverter(const std::string &name)
bool registerMaterialConverter(const std::string &name, ConverterFunction converter)
std::pair< bool, ConverterFunction > getMaterialConverter(const std::string &name)
std::function< RadiumMaterialPtr(AssetMaterialPtr)> ConverterFunction
static std::map< std::string, std::function< RadiumMaterialPtr(AssetMaterialPtr)> > MaterialConverterRegistry
Map that stores each conversion function.
Definition: Cage.cpp:3