3
0

MaterialFunctorSourceDataRegistration.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <Atom/RPI.Edit/Material/MaterialFunctorSourceDataRegistration.h>
  9. #include <AzCore/Interface/Interface.h>
  10. namespace AZ
  11. {
  12. namespace RPI
  13. {
  14. MaterialFunctorSourceDataRegistration* MaterialFunctorSourceDataRegistration::Get()
  15. {
  16. return Interface<MaterialFunctorSourceDataRegistration>::Get();
  17. }
  18. void MaterialFunctorSourceDataRegistration::Init()
  19. {
  20. Interface<MaterialFunctorSourceDataRegistration>::Register(this);
  21. }
  22. void MaterialFunctorSourceDataRegistration::Shutdown()
  23. {
  24. m_materialfunctorMap.clear();
  25. m_inverseMap.clear();
  26. Interface<MaterialFunctorSourceDataRegistration>::Unregister(this);
  27. }
  28. void MaterialFunctorSourceDataRegistration::RegisterMaterialFunctor(const AZStd::string& functorName, const Uuid& typeId)
  29. {
  30. auto iter = m_materialfunctorMap.find(functorName);
  31. if (iter != m_materialfunctorMap.end())
  32. {
  33. if (iter->second != typeId)
  34. {
  35. AZ_Error("Material Functor", false, "Material functor name \"%s\" was already registered with a different type Id!", functorName.c_str());
  36. }
  37. else
  38. {
  39. AZ_Warning("Material Functor", false, "Material functor name \"%s\" was already registered!", functorName.c_str());
  40. }
  41. return;
  42. }
  43. m_materialfunctorMap[functorName] = typeId;
  44. m_inverseMap[typeId] = functorName;
  45. }
  46. Uuid MaterialFunctorSourceDataRegistration::FindMaterialFunctorTypeIdByName(const AZStd::string& functorName)
  47. {
  48. auto iter = m_materialfunctorMap.find(functorName);
  49. if (iter == m_materialfunctorMap.end())
  50. {
  51. AZ_Warning("Material Functor", false, "Material functor name \"%s\" was NOT registered!", functorName.c_str());
  52. return {};
  53. }
  54. return iter->second;
  55. }
  56. const AZStd::string MaterialFunctorSourceDataRegistration::FindMaterialFunctorNameByTypeId(const Uuid& typeId)
  57. {
  58. auto iter = m_inverseMap.find(typeId);
  59. if (iter == m_inverseMap.end())
  60. {
  61. AZ_Warning("Material Functor", false, "Material functor type \"%s\" was NOT registered!", typeId.ToString<AZStd::string>().c_str());
  62. return AZStd::string();
  63. }
  64. return iter->second;
  65. }
  66. }
  67. }