ClearValue.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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/RHI.Reflect/ClearValue.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Utils/TypeHash.h>
  11. namespace AZ::RHI
  12. {
  13. void ClearDepthStencil::Reflect(AZ::ReflectContext* context)
  14. {
  15. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  16. {
  17. serializeContext->Class<ClearDepthStencil>()
  18. ->Version(0)
  19. ->Field("Depth", &ClearDepthStencil::m_depth)
  20. ->Field("Stencil", &ClearDepthStencil::m_stencil)
  21. ;
  22. }
  23. }
  24. void ClearValue::Reflect(AZ::ReflectContext* context)
  25. {
  26. ClearDepthStencil::Reflect(context);
  27. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  28. {
  29. serializeContext->Enum<ClearValueType>()
  30. ->Value("Vector4Float", ClearValueType::Vector4Float)
  31. ->Value("Vector4Uint", ClearValueType::Vector4Uint)
  32. ->Value("DepthStencil", ClearValueType::DepthStencil)
  33. ;
  34. serializeContext->Class<ClearValue>()
  35. ->Version(2)
  36. ->Field("Type", &ClearValue::m_type)
  37. ->Field("Value", &ClearValue::m_vector4Float)
  38. ->Field("UintValue", &ClearValue::m_vector4Uint)
  39. ->Field("DepthStencilValue", &ClearValue::m_depthStencil)
  40. ;
  41. }
  42. }
  43. ClearValue::ClearValue()
  44. {
  45. memset(this, 0, sizeof(ClearValue));
  46. m_type = ClearValueType::Vector4Float;
  47. }
  48. HashValue64 ClearValue::GetHash(HashValue64 seed /* = 0 */) const
  49. {
  50. return TypeHash64(*this, seed);
  51. }
  52. ClearValue ClearValue::CreateVector4Float(float x, float y, float z, float w)
  53. {
  54. ClearValue value;
  55. value.m_type = ClearValueType::Vector4Float;
  56. value.m_vector4Float[0] = x;
  57. value.m_vector4Float[1] = y;
  58. value.m_vector4Float[2] = z;
  59. value.m_vector4Float[3] = w;
  60. return value;
  61. }
  62. ClearValue ClearValue::CreateVector4Uint(uint32_t x, uint32_t y, uint32_t z, uint32_t w)
  63. {
  64. ClearValue value;
  65. value.m_type = ClearValueType::Vector4Uint;
  66. value.m_vector4Uint[0] = x;
  67. value.m_vector4Uint[1] = y;
  68. value.m_vector4Uint[2] = z;
  69. value.m_vector4Uint[3] = w;
  70. return value;
  71. }
  72. ClearValue ClearValue::CreateStencil(uint8_t stencil)
  73. {
  74. ClearValue value;
  75. value.m_type = ClearValueType::DepthStencil;
  76. value.m_depthStencil.m_depth = 0.0;
  77. value.m_depthStencil.m_stencil = stencil;
  78. return value;
  79. }
  80. ClearValue ClearValue::CreateDepth(float depth)
  81. {
  82. ClearValue value;
  83. value.m_type = ClearValueType::DepthStencil;
  84. value.m_depthStencil.m_depth = depth;
  85. value.m_depthStencil.m_stencil = 0;
  86. return value;
  87. }
  88. ClearValue ClearValue::CreateDepthStencil(float depth, uint8_t stencil)
  89. {
  90. ClearValue value;
  91. value.m_type = ClearValueType::DepthStencil;
  92. value.m_depthStencil.m_depth = depth;
  93. value.m_depthStencil.m_stencil = stencil;
  94. return value;
  95. }
  96. bool ClearValue::operator==(const ClearValue& other) const
  97. {
  98. return
  99. m_type == other.m_type &&
  100. m_depthStencil == other.m_depthStencil &&
  101. m_vector4Uint == other.m_vector4Uint &&
  102. AZ::IsClose(m_vector4Float[0], other.m_vector4Float[0], std::numeric_limits<float>::epsilon()) &&
  103. AZ::IsClose(m_vector4Float[1], other.m_vector4Float[1], std::numeric_limits<float>::epsilon()) &&
  104. AZ::IsClose(m_vector4Float[2], other.m_vector4Float[2], std::numeric_limits<float>::epsilon()) &&
  105. AZ::IsClose(m_vector4Float[3], other.m_vector4Float[3], std::numeric_limits<float>::epsilon());
  106. }
  107. }