MeshInstanceGroupKey.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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<Atom/RHI/DrawItem.h>
  10. #include<AtomCore/Instance/InstanceId.h>
  11. namespace AZ
  12. {
  13. namespace Render
  14. {
  15. //! Represents all the data needed to know if a mesh can be instanced
  16. struct MeshInstanceGroupKey
  17. {
  18. Data::InstanceId m_modelId = Data::InstanceId::CreateFromAssetId(Data::AssetId(Uuid::CreateNull(), 0));
  19. uint32_t m_lodIndex = 0;
  20. uint32_t m_meshIndex = 0;
  21. Data::InstanceId m_materialId = Data::InstanceId::CreateFromAssetId(Data::AssetId(Uuid::CreateNull(), 0));
  22. // If anything needs to force instancing off (e.g., if the shader it uses doesn't support instancing),
  23. // it can set a random uuid here to force it to get a unique key
  24. Uuid m_forceInstancingOff = Uuid::CreateNull();
  25. RHI::DrawItemSortKey m_sortKey = 0;
  26. bool operator<(const MeshInstanceGroupKey& rhs) const;
  27. bool operator==(const MeshInstanceGroupKey& rhs) const;
  28. bool operator!=(const MeshInstanceGroupKey& rhs) const;
  29. private:
  30. auto MakeTie() const;
  31. };
  32. } // namespace Render
  33. } // namespace AZ
  34. namespace AZStd
  35. {
  36. // hash specialization
  37. template<>
  38. struct hash<AZ::Render::MeshInstanceGroupKey>
  39. {
  40. using argument_type = AZ::Render::MeshInstanceGroupKey;
  41. using result_type = size_t;
  42. result_type operator()(const argument_type& key) const
  43. {
  44. size_t h = 0;
  45. hash_combine(h, key.m_modelId);
  46. hash_combine(h, key.m_lodIndex);
  47. hash_combine(h, key.m_meshIndex);
  48. hash_combine(h, key.m_materialId);
  49. hash_combine(h, key.m_forceInstancingOff);
  50. hash_combine(h, key.m_sortKey);
  51. return h;
  52. }
  53. };
  54. } // namespace AZStd