3
0

AttachmentImageAssetCreator.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.Reflect/Image/AttachmentImageAssetCreator.h>
  9. #include <Atom/RPI.Public/Image/AttachmentImagePool.h>
  10. #include <Atom/RPI.Public/Image/ImageSystemInterface.h>
  11. #include <AzCore/Asset/AssetManager.h>
  12. namespace AZ
  13. {
  14. namespace RPI
  15. {
  16. void AttachmentImageAssetCreator::Begin(const Data::AssetId& assetId)
  17. {
  18. BeginCommon(assetId);
  19. }
  20. void AttachmentImageAssetCreator::SetImageDescriptor(const RHI::ImageDescriptor& descriptor)
  21. {
  22. if (ValidateIsReady())
  23. {
  24. m_asset->m_imageDescriptor = descriptor;
  25. }
  26. }
  27. void AttachmentImageAssetCreator::SetImageViewDescriptor(const RHI::ImageViewDescriptor& descriptor)
  28. {
  29. if (ValidateIsReady())
  30. {
  31. m_asset->m_imageViewDescriptor = descriptor;
  32. }
  33. }
  34. void AttachmentImageAssetCreator::SetPoolAsset(const Data::Asset<ResourcePoolAsset>& poolAsset)
  35. {
  36. if (ValidateIsReady())
  37. {
  38. m_asset->m_poolAsset = poolAsset;
  39. }
  40. }
  41. void AttachmentImageAssetCreator::SetOptimizedClearValue(const RHI::ClearValue& clearValue)
  42. {
  43. if (ValidateIsReady())
  44. {
  45. m_asset->m_optimizedClearValue = AZStd::make_shared<RHI::ClearValue>(clearValue);
  46. }
  47. }
  48. bool AttachmentImageAssetCreator::End(Data::Asset<AttachmentImageAsset>& result)
  49. {
  50. if (!ValidateIsReady())
  51. {
  52. return false;
  53. }
  54. // If the pool wasn't provided, use the system default attachment pool
  55. if (!m_asset->m_poolAsset.GetId().IsValid())
  56. {
  57. Data::Instance<RPI::AttachmentImagePool> pool = RPI::ImageSystemInterface::Get()->GetSystemAttachmentPool();
  58. m_asset->m_poolAsset = {pool->GetAssetId(), azrtti_typeid<ResourcePoolAsset>()};
  59. }
  60. m_asset->SetReady();
  61. return EndCommon(result);
  62. }
  63. void AttachmentImageAssetCreator::SetAssetHint(AZStd::string_view hint)
  64. {
  65. m_asset.SetHint(hint);
  66. }
  67. void AttachmentImageAssetCreator::SetName(const AZ::Name& uniqueName, bool isUniqueName)
  68. {
  69. if (uniqueName.IsEmpty())
  70. {
  71. m_asset->m_isUniqueName = false;
  72. AZ_Warning("RPI", false, "Can't set empty string as unique name");
  73. }
  74. else
  75. {
  76. m_asset->m_isUniqueName = isUniqueName;
  77. }
  78. m_asset->m_name = uniqueName;
  79. }
  80. }
  81. }