RenderingKey.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. // Copyright (C) 2009-2022, 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. GBUFFER = 0,
  13. GBUFFER_EARLY_Z = 1,
  14. SHADOW = 2,
  15. FORWARD = 3,
  16. RT_SHADOW = 4,
  17. COUNT,
  18. FIRST = 0
  19. };
  20. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RenderingTechnique)
  21. enum class RenderingTechniqueBit : U8
  22. {
  23. NONE = 0,
  24. GBUFFER = 1 << 0,
  25. GBUFFER_EARLY_Z = 1 << 1,
  26. SHADOW = 1 << 2,
  27. FORWARD = 1 << 3,
  28. RT_SHADOW = 1 << 4,
  29. ALL_RT = RT_SHADOW
  30. };
  31. ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(RenderingTechniqueBit)
  32. /// A key that consistst of the rendering pass and the level of detail
  33. class RenderingKey
  34. {
  35. public:
  36. RenderingKey(RenderingTechnique technique, U32 lod, U32 instanceCount, Bool skinned, Bool velocity)
  37. : m_technique(technique)
  38. , m_lod(U8(lod))
  39. , m_instanceCount(U8(instanceCount))
  40. , m_skinned(skinned)
  41. , m_velocity(velocity)
  42. {
  43. ANKI_ASSERT(instanceCount <= MAX_INSTANCE_COUNT && instanceCount != 0);
  44. ANKI_ASSERT(lod <= MAX_LOD_COUNT);
  45. }
  46. RenderingKey()
  47. : RenderingKey(RenderingTechnique::FIRST, 0, 1, false, false)
  48. {
  49. }
  50. RenderingKey(const RenderingKey& b)
  51. : RenderingKey(b.m_technique, b.m_lod, b.m_instanceCount, b.m_skinned, b.m_velocity)
  52. {
  53. }
  54. RenderingKey& operator=(const RenderingKey& b)
  55. {
  56. memcpy(this, &b, sizeof(*this));
  57. return *this;
  58. }
  59. Bool operator==(const RenderingKey& b) const
  60. {
  61. return m_technique == b.m_technique && m_lod == b.m_lod && m_instanceCount == b.m_instanceCount
  62. && m_skinned == b.m_skinned && m_velocity == b.m_velocity;
  63. }
  64. RenderingTechnique getRenderingTechnique() const
  65. {
  66. return m_technique;
  67. }
  68. void setRenderingTechnique(RenderingTechnique t)
  69. {
  70. m_technique = t;
  71. }
  72. U32 getLod() const
  73. {
  74. return m_lod;
  75. }
  76. void setLod(U32 lod)
  77. {
  78. ANKI_ASSERT(lod < MAX_LOD_COUNT);
  79. m_lod = U8(lod);
  80. }
  81. U32 getInstanceCount() const
  82. {
  83. return m_instanceCount;
  84. }
  85. void setInstanceCount(U32 instanceCount)
  86. {
  87. ANKI_ASSERT(instanceCount <= MAX_INSTANCE_COUNT && instanceCount > 0);
  88. m_instanceCount = U8(instanceCount);
  89. }
  90. Bool getSkinned() const
  91. {
  92. return m_skinned;
  93. }
  94. void setSkinned(Bool is)
  95. {
  96. m_skinned = is;
  97. }
  98. Bool getVelocity() const
  99. {
  100. return m_velocity;
  101. }
  102. void setVelocity(Bool v)
  103. {
  104. m_velocity = v;
  105. }
  106. private:
  107. RenderingTechnique m_technique;
  108. U8 m_lod;
  109. U8 m_instanceCount;
  110. Bool m_skinned;
  111. Bool m_velocity;
  112. };
  113. static_assert(sizeof(RenderingKey) == sizeof(U8) * 5, "RenderingKey needs to be packed because of hashing");
  114. } // end namespace anki