RenderingKey.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // Copyright (C) 2009-2021, 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 Pass : U8
  11. {
  12. GB, ///< GBuffer.
  13. FS, ///< Forward shading.
  14. SM, ///< Shadow mapping.
  15. EZ, ///< Early Z.
  16. COUNT,
  17. FIRST = 0
  18. };
  19. /// A key that consistst of the rendering pass and the level of detail
  20. class RenderingKey
  21. {
  22. public:
  23. RenderingKey(Pass pass, U32 lod, U32 instanceCount, Bool skinned, Bool velocity)
  24. : m_pass(pass)
  25. , m_lod(U8(lod))
  26. , m_instanceCount(U8(instanceCount))
  27. , m_skinned(skinned)
  28. , m_velocity(velocity)
  29. {
  30. ANKI_ASSERT(instanceCount <= MAX_INSTANCE_COUNT && instanceCount != 0);
  31. ANKI_ASSERT(lod <= MAX_LOD_COUNT);
  32. }
  33. RenderingKey()
  34. : RenderingKey(Pass::GB, 0, 1, false, false)
  35. {
  36. }
  37. RenderingKey(const RenderingKey& b)
  38. : RenderingKey(b.m_pass, b.m_lod, b.m_instanceCount, b.m_skinned, b.m_velocity)
  39. {
  40. }
  41. RenderingKey& operator=(const RenderingKey& b)
  42. {
  43. memcpy(this, &b, sizeof(*this));
  44. return *this;
  45. }
  46. Bool operator==(const RenderingKey& b) const
  47. {
  48. return m_pass == b.m_pass && m_lod == b.m_lod && m_instanceCount == b.m_instanceCount
  49. && m_skinned == b.m_skinned && m_velocity == b.m_velocity;
  50. }
  51. Pass getPass() const
  52. {
  53. return m_pass;
  54. }
  55. void setPass(Pass p)
  56. {
  57. m_pass = p;
  58. }
  59. U32 getLod() const
  60. {
  61. return m_lod;
  62. }
  63. void setLod(U32 lod)
  64. {
  65. ANKI_ASSERT(lod < MAX_LOD_COUNT);
  66. m_lod = U8(lod);
  67. }
  68. U32 getInstanceCount() const
  69. {
  70. return m_instanceCount;
  71. }
  72. void setInstanceCount(U32 instanceCount)
  73. {
  74. ANKI_ASSERT(instanceCount <= MAX_INSTANCE_COUNT && instanceCount > 0);
  75. m_instanceCount = U8(instanceCount);
  76. }
  77. Bool isSkinned() const
  78. {
  79. return m_skinned;
  80. }
  81. void setSkinned(Bool is)
  82. {
  83. m_skinned = is;
  84. }
  85. Bool hasVelocity() const
  86. {
  87. return m_velocity;
  88. }
  89. void setVelocity(Bool v)
  90. {
  91. m_velocity = v;
  92. }
  93. private:
  94. Pass m_pass;
  95. U8 m_lod;
  96. U8 m_instanceCount;
  97. Bool m_skinned : 1;
  98. Bool m_velocity : 1;
  99. };
  100. template<>
  101. constexpr Bool isPacked<RenderingKey>()
  102. {
  103. return sizeof(RenderingKey) == 5;
  104. }
  105. } // end namespace anki