TestFeatureProcessors.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. namespace UnitTest
  10. {
  11. // A feature processor which has scene notification enabled
  12. class TestFeatureProcessor1 final
  13. : public AZ::RPI::FeatureProcessor
  14. {
  15. public:
  16. AZ_CLASS_ALLOCATOR(TestFeatureProcessor1, AZ::SystemAllocator)
  17. AZ_RTTI(TestFeatureProcessor1, "{CCC3EB15-D80E-4F5A-93F4-B0F993A5E7F5}", AZ::RPI::FeatureProcessor);
  18. static void Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  21. {
  22. serializeContext->Class<TestFeatureProcessor1, AZ::RPI::FeatureProcessor>()
  23. ->Version(1)
  24. ;
  25. }
  26. }
  27. // Variables
  28. // notification counters
  29. int m_pipelineCount = 0;
  30. int m_viewSetCount = 0;
  31. int m_pipelineChangedCount = 0;
  32. AZ::RPI::RenderPipeline* m_lastPipeline = nullptr;
  33. // FeatureProcessor overrides...
  34. void Activate() override
  35. {
  36. EnableSceneNotification();
  37. }
  38. void Deactivate() override
  39. {
  40. DisableSceneNotification();
  41. }
  42. void Render(const RenderPacket&) override {};
  43. // Overrides for scene notification bus handler
  44. void OnRenderPipelinePersistentViewChanged(AZ::RPI::RenderPipeline* renderPipeline, [[maybe_unused]] AZ::RPI::PipelineViewTag viewTag, [[maybe_unused]] AZ::RPI::ViewPtr newView, [[maybe_unused]] AZ::RPI::ViewPtr previousView) override
  45. {
  46. m_viewSetCount++;
  47. m_lastPipeline = renderPipeline;
  48. }
  49. void OnRenderPipelineChanged(AZ::RPI::RenderPipeline* pipeline, AZ::RPI::SceneNotification::RenderPipelineChangeType changeType) override
  50. {
  51. if (changeType == AZ::RPI::SceneNotification::RenderPipelineChangeType::Added)
  52. {
  53. m_pipelineCount++;
  54. }
  55. else if (changeType == AZ::RPI::SceneNotification::RenderPipelineChangeType::Removed)
  56. {
  57. m_pipelineCount--;
  58. }
  59. else if (changeType == AZ::RPI::SceneNotification::RenderPipelineChangeType::PassChanged)
  60. {
  61. m_pipelineChangedCount++;
  62. }
  63. m_lastPipeline = pipeline;
  64. }
  65. };
  66. class TestFeatureProcessor2 final
  67. : public AZ::RPI::FeatureProcessor
  68. {
  69. public:
  70. AZ_RTTI(TestFeatureProcessor2, "{1DB411E1-0C0D-4FA1-A0AA-9935CFF671D5}", AZ::RPI::FeatureProcessor);
  71. static void Reflect(AZ::ReflectContext* context)
  72. {
  73. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  74. {
  75. serializeContext->Class<TestFeatureProcessor2, AZ::RPI::FeatureProcessor>()
  76. ->Version(1)
  77. ;
  78. }
  79. }
  80. void Render(const RenderPacket&) override {};
  81. };
  82. class TestFeatureProcessorInterface
  83. : public AZ::RPI::FeatureProcessor
  84. {
  85. public:
  86. AZ_RTTI(TestFeatureProcessorInterface, "{F1766CA0-B3A6-40F5-8ADE-5E93EB0DDE9D}", AZ::RPI::FeatureProcessor);
  87. virtual void SetValue(int value) = 0;
  88. virtual int GetValue() const = 0;
  89. };
  90. class TestFeatureProcessorImplementation final
  91. : public TestFeatureProcessorInterface
  92. {
  93. public:
  94. AZ_CLASS_ALLOCATOR(TestFeatureProcessorImplementation, AZ::SystemAllocator)
  95. AZ_RTTI(TestFeatureProcessorImplementation, "{2FEB6299-A03E-4341-9234-47786F5A53C3}", TestFeatureProcessorInterface);
  96. static void Reflect(AZ::ReflectContext* context)
  97. {
  98. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  99. {
  100. serializeContext->Class<TestFeatureProcessorImplementation, TestFeatureProcessorInterface>()
  101. ->Version(1)
  102. ;
  103. }
  104. }
  105. void Render(const RenderPacket&) override {};
  106. void SetValue(int value) override { m_value = value; }
  107. int GetValue() const override { return m_value; };
  108. private:
  109. int m_value = 0;
  110. };
  111. class TestFeatureProcessorImplementation2 final
  112. : public TestFeatureProcessorInterface
  113. {
  114. public:
  115. AZ_CLASS_ALLOCATOR(TestFeatureProcessorImplementation2, AZ::SystemAllocator)
  116. AZ_RTTI(TestFeatureProcessorImplementation2, "{48E98E91-373E-43D4-BFD2-991B9FF8CEE8}", TestFeatureProcessorInterface);
  117. static void Reflect(AZ::ReflectContext* context)
  118. {
  119. if (auto* serializeContext = azrtti_cast<AZ::SerializeContext*>(context))
  120. {
  121. serializeContext->Class<TestFeatureProcessorImplementation2, TestFeatureProcessorInterface>()
  122. ->Version(1)
  123. ;
  124. }
  125. }
  126. void Render(const RenderPacket&) override {};
  127. void SetValue(int value) override { m_value = value; }
  128. int GetValue() const override { return m_value; };
  129. private:
  130. int m_value = 0;
  131. };
  132. } // namespace UnitTest