RenderingKey.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include <AnKi/Resource/Common.h>
  7. #include <AnKi/Util/Hash.h>
  8. namespace anki {
  9. /// The AnKi passes visible to materials.
  10. enum class RenderingTechnique : U8
  11. {
  12. kGBuffer = 0,
  13. kDepth = 1,
  14. kForward = 2,
  15. kRtShadow = 3,
  16. kRtMaterialFetch = 4,
  17. kCount,
  18. kFirst = 0,
  19. kFirstRt = kRtShadow,
  20. kLastRt = kRtMaterialFetch,
  21. kRtCount = kLastRt - kFirstRt + 1
  22. };
  23. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RenderingTechnique)
  24. enum class RenderingTechniqueBit : U8
  25. {
  26. kNone = 0,
  27. kGBuffer = 1 << 0,
  28. kDepth = 1 << 1,
  29. kForward = 1 << 2,
  30. kRtShadow = 1 << 3,
  31. kRtMaterialFetch = 1 << 4,
  32. kAllRt = kRtShadow | kRtMaterialFetch,
  33. kAllRaster = kGBuffer | kDepth | kForward
  34. };
  35. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RenderingTechniqueBit)
  36. /// A key that consistst of the rendering pass and the level of detail
  37. class RenderingKey
  38. {
  39. public:
  40. RenderingKey(RenderingTechnique technique, U32 lod, Bool skinned, Bool velocity, Bool meshletRendering)
  41. : m_technique(technique)
  42. , m_lod(lod & 0b11)
  43. , m_skinned(skinned)
  44. , m_velocity(velocity)
  45. , m_meshletRendering(meshletRendering)
  46. {
  47. ANKI_ASSERT(lod < kMaxLodCount);
  48. }
  49. RenderingKey()
  50. : RenderingKey(RenderingTechnique::kFirst, 0, false, false, false)
  51. {
  52. }
  53. RenderingKey(const RenderingKey& b)
  54. : RenderingKey(b.m_technique, b.m_lod, b.m_skinned, b.m_velocity, b.m_meshletRendering)
  55. {
  56. }
  57. RenderingKey& operator=(const RenderingKey& b)
  58. {
  59. memcpy(this, &b, sizeof(*this));
  60. return *this;
  61. }
  62. Bool operator==(const RenderingKey& b) const
  63. {
  64. return m_technique == b.m_technique && m_lod == b.m_lod && m_skinned == b.m_skinned && m_velocity == b.m_velocity
  65. && m_meshletRendering == b.m_meshletRendering;
  66. }
  67. RenderingTechnique getRenderingTechnique() const
  68. {
  69. return m_technique;
  70. }
  71. void setRenderingTechnique(RenderingTechnique t)
  72. {
  73. m_technique = t;
  74. }
  75. U32 getLod() const
  76. {
  77. return m_lod;
  78. }
  79. void setLod(U32 lod)
  80. {
  81. ANKI_ASSERT(lod < kMaxLodCount);
  82. m_lod = lod & 0b11;
  83. }
  84. Bool getSkinned() const
  85. {
  86. return m_skinned;
  87. }
  88. void setSkinned(Bool is)
  89. {
  90. m_skinned = is;
  91. }
  92. Bool getVelocity() const
  93. {
  94. return m_velocity;
  95. }
  96. void setVelocity(Bool v)
  97. {
  98. m_velocity = v;
  99. }
  100. void setMeshletRendering(Bool b)
  101. {
  102. m_meshletRendering = b;
  103. }
  104. Bool getMeshletRendering() const
  105. {
  106. return m_meshletRendering;
  107. }
  108. private:
  109. RenderingTechnique m_technique;
  110. U8 m_lod : 2;
  111. Bool m_skinned : 1;
  112. Bool m_velocity : 1;
  113. Bool m_meshletRendering : 1;
  114. static_assert(kMaxLodCount <= 3, "m_lod only reserves 2 bits so make sure all LODs will fit");
  115. };
  116. static_assert(sizeof(RenderingKey) == sizeof(U8) * 2, "RenderingKey needs to be packed because of hashing");
  117. } // end namespace anki