MaterialAssetTestUtils.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #pragma once
  9. #include <Common/TestUtils.h>
  10. #include <Atom/RPI.Reflect/Material/MaterialAsset.h>
  11. #include <Atom/RPI.Reflect/Material/MaterialTypeAssetCreator.h>
  12. #include <AzCore/Name/Name.h>
  13. namespace UnitTest
  14. {
  15. template<typename T>
  16. void CheckPropertyValue(const AZ::Data::Asset<AZ::RPI::MaterialTypeAsset>& asset, const AZ::Name& propertyName, T expectedValue)
  17. {
  18. const AZ::RPI::MaterialPropertyIndex propertyIndex = asset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyName);
  19. EXPECT_TRUE(propertyIndex.IsValid());
  20. AZ::RPI::MaterialPropertyValue value = asset->GetDefaultPropertyValues()[propertyIndex.GetIndex()];
  21. EXPECT_TRUE(value == expectedValue);
  22. }
  23. template<typename T>
  24. void CheckMaterialPropertyValue(const AZ::Data::Asset<AZ::RPI::MaterialAsset>& asset, const AZ::Name& propertyName, T expectedValue)
  25. {
  26. const AZ::RPI::MaterialPropertyIndex propertyIndex = asset->GetMaterialPropertiesLayout()->FindPropertyIndex(propertyName);
  27. EXPECT_TRUE(propertyIndex.IsValid());
  28. AZ::RPI::MaterialPropertyValue value = asset->GetPropertyValues()[propertyIndex.GetIndex()];
  29. EXPECT_TRUE(value == expectedValue);
  30. }
  31. void AddMaterialPropertyForSrg(
  32. AZ::RPI::MaterialTypeAssetCreator& materialTypeCreator,
  33. const AZ::Name& propertyName,
  34. AZ::RPI::MaterialPropertyDataType dataType,
  35. const AZ::Name& shaderInputName);
  36. void AddCommonTestMaterialProperties(AZ::RPI::MaterialTypeAssetCreator& materialTypeCreator, AZStd::string propertyGroupPrefix = "");
  37. AZ::RHI::Ptr<AZ::RHI::ShaderResourceGroupLayout> CreateCommonTestMaterialSrgLayout();
  38. } //namespace UnitTest