3
0

MaterialFunctorSourceData.cpp 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/MaterialFunctorSourceData.h>
  9. #include <Atom/RPI.Reflect/Material/MaterialNameContext.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/Json/RegistrationContext.h>
  12. namespace AZ
  13. {
  14. namespace RPI
  15. {
  16. void MaterialFunctorSourceData::Reflect(AZ::ReflectContext* context)
  17. {
  18. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  19. {
  20. serializeContext->Class<MaterialFunctorSourceData>();
  21. }
  22. }
  23. void MaterialFunctorSourceData::AddMaterialPropertyDependency(Ptr<MaterialFunctor> functor, MaterialPropertyIndex index) const
  24. {
  25. functor->m_materialPropertyDependencies.set(index.GetIndex());
  26. }
  27. const MaterialPropertiesLayout* MaterialFunctorSourceData::RuntimeContext::GetMaterialPropertiesLayout() const
  28. {
  29. return m_materialPropertiesLayout;
  30. }
  31. const RHI::ShaderResourceGroupLayout* MaterialFunctorSourceData::RuntimeContext::GetShaderResourceGroupLayout() const
  32. {
  33. return m_shaderResourceGroupLayout;
  34. }
  35. MaterialPropertyIndex MaterialFunctorSourceData::RuntimeContext::FindMaterialPropertyIndex(Name propertyId) const
  36. {
  37. m_materialNameContext->ContextualizeProperty(propertyId);
  38. MaterialPropertyIndex propertyIndex = m_materialPropertiesLayout->FindPropertyIndex(propertyId);
  39. AZ_Error("MaterialFunctorSourceData", propertyIndex.IsValid(), "Could not find property '%s'.", propertyId.GetCStr());
  40. return propertyIndex;
  41. }
  42. RHI::ShaderInputConstantIndex MaterialFunctorSourceData::RuntimeContext::FindShaderInputConstantIndex(Name inputName) const
  43. {
  44. m_materialNameContext->ContextualizeSrgInput(inputName);
  45. return m_shaderResourceGroupLayout->FindShaderInputConstantIndex(inputName);
  46. }
  47. RHI::ShaderInputImageIndex MaterialFunctorSourceData::RuntimeContext::FindShaderInputImageIndex(Name inputName) const
  48. {
  49. m_materialNameContext->ContextualizeSrgInput(inputName);
  50. return m_shaderResourceGroupLayout->FindShaderInputImageIndex(inputName);
  51. }
  52. const MaterialPropertiesLayout* MaterialFunctorSourceData::EditorContext::GetMaterialPropertiesLayout() const
  53. {
  54. return m_materialPropertiesLayout;
  55. }
  56. MaterialPropertyIndex MaterialFunctorSourceData::EditorContext::FindMaterialPropertyIndex(Name propertyId) const
  57. {
  58. m_materialNameContext->ContextualizeProperty(propertyId);
  59. MaterialPropertyIndex propertyIndex = m_materialPropertiesLayout->FindPropertyIndex(propertyId);
  60. AZ_Error("MaterialFunctorSourceData", propertyIndex.IsValid(), "Could not find property '%s'", propertyId.GetCStr());
  61. return propertyIndex;
  62. }
  63. } // namespace RPI
  64. } // namespace AZ